1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkAVSucdReader.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 // .NAME vtkAVSucdReader - reads a dataset in AVS "UCD" format 16 // .SECTION Description 17 // vtkAVSucdReader creates an unstructured grid dataset. It reads binary or 18 // ASCII files stored in UCD format, with optional data stored at the nodes 19 // or at the cells of the model. A cell-based fielddata stores the material 20 // id. The class can automatically detect the endian-ness of the binary files. 21 22 // .SECTION Thanks 23 // Thanks to Guenole Harel and Emmanuel Colin (Supelec engineering school, 24 // France) and Jean M. Favre (CSCS, Switzerland) who co-developed this class. 25 // Thanks to Isabelle Surin (isabelle.surin at cea.fr, CEA-DAM, France) who 26 // supervised the internship of the first two authors. Thanks to Daniel 27 // Aguilera (daniel.aguilera at cea.fr, CEA-DAM, France) who contributed code 28 // and advice. Please address all comments to Jean Favre (jfavre at cscs.ch) 29 30 // .SECTION See Also 31 // vtkGAMBITReader 32 33 #ifndef vtkAVSucdReader_h 34 #define vtkAVSucdReader_h 35 36 #include "vtkIOGeometryModule.h" // For export macro 37 #include "vtkUnstructuredGridAlgorithm.h" 38 39 class vtkIntArray; 40 class vtkFloatArray; 41 class vtkIdTypeArray; 42 class vtkDataArraySelection; 43 44 class VTKIOGEOMETRY_EXPORT vtkAVSucdReader : public vtkUnstructuredGridAlgorithm 45 { 46 public: 47 static vtkAVSucdReader *New(); 48 vtkTypeMacro(vtkAVSucdReader,vtkUnstructuredGridAlgorithm); 49 void PrintSelf(ostream& os, vtkIndent indent); 50 51 // Description: 52 // Specify file name of AVS UCD datafile to read 53 vtkSetStringMacro(FileName); 54 vtkGetStringMacro(FileName); 55 56 // Description: 57 // Is the file to be read written in binary format (as opposed to ascii). 58 vtkSetMacro(BinaryFile, int); 59 vtkGetMacro(BinaryFile, int); 60 vtkBooleanMacro(BinaryFile, int); 61 62 // Description: 63 // Get the total number of cells. 64 vtkGetMacro(NumberOfCells,int); 65 66 // Description: 67 // Get the total number of nodes. 68 vtkGetMacro(NumberOfNodes,int); 69 70 // Description: 71 // Get the number of data fields at the nodes. 72 vtkGetMacro(NumberOfNodeFields,int); 73 74 // Description: 75 // Get the number of data fields at the cell centers. 76 vtkGetMacro(NumberOfCellFields,int); 77 78 // Description: 79 // Get the number of data fields for the model. Unused because VTK 80 // has no methods for it. 81 vtkGetMacro(NumberOfFields,int); 82 83 // Description: 84 // Get the number of data components at the nodes and cells. 85 vtkGetMacro(NumberOfNodeComponents,int); 86 vtkGetMacro(NumberOfCellComponents,int); 87 88 // Description: 89 // Set/Get the endian-ness of the binary file. 90 void SetByteOrderToBigEndian(); 91 void SetByteOrderToLittleEndian(); 92 const char *GetByteOrderAsString(); 93 94 vtkSetMacro(ByteOrder, int); 95 vtkGetMacro(ByteOrder, int); 96 97 // Description: 98 // The following methods allow selective reading of solutions fields. by 99 // default, ALL data fields are the nodes and cells are read, but this can 100 // be modified. 101 int GetNumberOfPointArrays(); 102 int GetNumberOfCellArrays(); 103 const char* GetPointArrayName(int index); 104 const char* GetCellArrayName(int index); 105 int GetPointArrayStatus(const char* name); 106 int GetCellArrayStatus(const char* name); 107 void SetPointArrayStatus(const char* name, int status); 108 void SetCellArrayStatus(const char* name, int status); 109 110 void DisableAllCellArrays(); 111 void EnableAllCellArrays(); 112 void DisableAllPointArrays(); 113 void EnableAllPointArrays(); 114 115 // get min and max value for the index-th value of a cell component 116 // index varies from 0 to (veclen - 1) 117 void GetCellDataRange(int cellComp, int index, float *min, float *max); 118 119 // get min and max value for the index-th value of a node component 120 // index varies from 0 to (veclen - 1) 121 void GetNodeDataRange(int nodeComp, int index, float *min, float *max); 122 123 protected: 124 vtkAVSucdReader(); 125 ~vtkAVSucdReader(); 126 int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *); 127 int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); 128 129 char *FileName; 130 int BinaryFile; 131 132 int NumberOfNodes; 133 int NumberOfCells; 134 int NumberOfNodeFields; 135 int NumberOfNodeComponents; 136 int NumberOfCellComponents; 137 int NumberOfCellFields; 138 int NumberOfFields; 139 int NlistNodes; 140 141 ifstream *FileStream; 142 143 vtkDataArraySelection* PointDataArraySelection; 144 vtkDataArraySelection* CellDataArraySelection; 145 146 int DecrementNodeIds; 147 int ByteOrder; 148 int GetLabel(char *string, int number, char *label); 149 //BTX 150 enum 151 { 152 FILE_BIG_ENDIAN=0, 153 FILE_LITTLE_ENDIAN=1 154 }; 155 enum UCDCell_type 156 { 157 PT = 0, 158 LINE = 1, 159 TRI = 2, 160 QUAD = 3, 161 TET = 4, 162 PYR = 5, 163 PRISM = 6, 164 HEX = 7 165 }; 166 167 struct DataInfo { 168 long foffset; // offset in binary file 169 int veclen; // number of components in the node or cell variable 170 float min[3]; // pre-calculated data minima (max size 3 for vectors) 171 float max[3]; // pre-calculated data maxima (max size 3 for vectors) 172 }; 173 //ETX 174 175 DataInfo *NodeDataInfo; 176 DataInfo *CellDataInfo; 177 178 private: 179 void ReadFile(vtkUnstructuredGrid *output); 180 void ReadGeometry(vtkUnstructuredGrid *output); 181 void ReadNodeData(vtkUnstructuredGrid *output); 182 void ReadCellData(vtkUnstructuredGrid *output); 183 184 int ReadFloatBlock(int n, float *block); 185 int ReadIntBlock(int n, int *block); 186 void ReadXYZCoords(vtkFloatArray *coords); 187 void ReadBinaryCellTopology(vtkIntArray *material, int *types, 188 vtkIdTypeArray *listcells); 189 void ReadASCIICellTopology(vtkIntArray *material, vtkUnstructuredGrid *output); 190 191 vtkAVSucdReader(const vtkAVSucdReader&); // Not implemented. 192 void operator=(const vtkAVSucdReader&); // Not implemented. 193 }; 194 195 #endif 196