1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkTecplotReader.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 16 /***************************************************************************** 17 * 18 * Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC 19 * Produced at the Lawrence Livermore National Laboratory 20 * LLNL-CODE-400124 21 * All rights reserved. 22 * 23 * This file was adapted from the ASCII Tecplot reader of VisIt. For details, 24 * see https://visit.llnl.gov/. The full copyright notice is contained in the 25 * file COPYRIGHT located at the root of the VisIt distribution or at 26 * http://www.llnl.gov/visit/copyright.html. 27 * 28 *****************************************************************************/ 29 30 // .NAME vtkTecplotReader - A concrete class to read an ASCII Tecplot file. 31 // 32 // .SECTION Description 33 // vtkTecplotReader parses an ASCII Tecplot file to get a vtkMultiBlockDataSet 34 // object made up of several vtkDataSet objects, of which each is of type 35 // either vtkStructuredGrid or vtkUnstructuredGrid. Each vtkDataSet object 36 // maintains the geometry, topology, and some associated attributes describing 37 // physical properties. 38 // 39 // Tecplot treats 3D coordinates (only one or two coordinates might be 40 // explicitly specified in a file) as varaibles too, whose names (e.g., 41 // 'X' / 'x' / 'I', 'Y' / 'y' / 'J', 'Z' / 'z' / 'K') are provided in the 42 // variables list (the 'VARIABLES' section). These names are then followed 43 // in the list by those of other traditional variables or attributes (node- 44 // based and / or cell-based data with the mode specified via token 'VAR 45 // LOCATION', to be extracted to create vtkPointData and / or vtkCellData). 46 // Each zone described afterwards (in the 'ZONE's section) provides the 47 // specific values of the aforementioned variables (including 3D coordinates), 48 // in the same order as indicated by the variable-names list, through either 49 // POINT-packing (i.e., tuple-based storage) or BLOCK-packing (component-based 50 // storage). In particular, the first / description line of each zone tells 51 // the type of all the constituent cells as the connectivity / topology 52 // information. In other words, the entire dataset is made up of multiple zones 53 // (blocks), of which each maintains a set of cells of the same type ('BRICK', 54 // 'TRIANGLE', 'QUADRILATERAL', 'TETRAHEDRON', and 'POINT' in Tecplot terms). 55 // In addition, the description line of each zone specifies the zone name, 56 // dimensionality information (size of each dimension for a structured zone), 57 // number of nodes, and number of cells. Information about the file format is 58 // available at http://download.tecplot.com/360/dataformat.pdf. 59 // 60 // .SECTION Caveats 61 // vtkTecplotReader is currently a simplified ASCII Tecplot reader and some 62 // functionalities (e.g., extraction of sections 'GEOMETRY', 'TEXT', and 'DATA 63 // SETAUXDATA', access to multiple time steps, in addition to the construction 64 // of vtkRectilinearGrid and vtkImageData objects) are not supported. 65 // 66 // .SECTION Thanks 67 // This class is a VTK implementation of VisIt's ASCII Tecplot reader. 68 // 69 // .SECTION See Also 70 // vtkPoints vtkStructuredGrid vtkUnstructuredGrid vtkPointData vtkCellData 71 // vtkDataSet vtkMultiBlockDataSet 72 73 #ifndef vtkTecplotReader_h 74 #define vtkTecplotReader_h 75 76 #include "vtkIOGeometryModule.h" // For export macro 77 #include "vtkMultiBlockDataSetAlgorithm.h" 78 79 //BTX 80 #include <vector> // STL Header; Required for vector 81 #include <string> // STL Header; Required for string 82 //ETX 83 84 class vtkPoints; 85 class vtkCellData; 86 class vtkPointData; 87 class vtkCallbackCommand; 88 class vtkUnstructuredGrid; 89 class vtkMultiBlockDataSet; 90 class vtkDataArraySelection; 91 class vtkTecplotReaderInternal; 92 93 class VTKIOGEOMETRY_EXPORT vtkTecplotReader : public vtkMultiBlockDataSetAlgorithm 94 { 95 public: 96 static vtkTecplotReader * New(); 97 vtkTypeMacro( vtkTecplotReader, vtkMultiBlockDataSetAlgorithm ); 98 void PrintSelf( ostream & os, vtkIndent indent ); 99 100 // Description: 101 // Get the number of all variables (including 3D coordinates). 102 vtkGetMacro( NumberOfVariables, int ); 103 104 // Description: 105 // Specify a Tecplot ASCII file for data loading. 106 void SetFileName( const char * fileName ); 107 108 // Description: 109 // Get the Tecplot data title. 110 const char * GetDataTitle(); 111 112 // Description: 113 // Get the number of blocks (i.e., zones in Tecplot terms). 114 int GetNumberOfBlocks(); 115 116 // Description: 117 // Get the name of a block specified by a zero-based index. NULL is returned 118 // for an invalid block index. 119 const char * GetBlockName( int blockIdx ); 120 121 // Description: 122 // Get the number of standard data attributes (node-based and cell-based), 123 // excluding 3D coordinates. 124 int GetNumberOfDataAttributes(); 125 126 // Description: 127 // Get the name of a zero-based data attribute (not 3D coordinates). NULL is 128 // returned for an invalid attribute index. 129 const char * GetDataAttributeName( int attrIndx ); 130 131 // Description: 132 // Get the type (0 for node-based and 1 for cell-based) of a specified data 133 // attribute (not 3D coordinates). -1 is returned for an invalid attribute 134 // name. 135 int IsDataAttributeCellBased( const char * attrName ); 136 137 // Description: 138 // Get the type (0 for node-based and 1 for cell-based) of a specified data 139 // attribute (not 3D coordinates). -1 is returned for an invalid attribute 140 // index. 141 int IsDataAttributeCellBased( int attrIndx ); 142 143 // Description: 144 // Get the number of all data attributes (point data and cell data). 145 int GetNumberOfDataArrays(); 146 147 // Description: 148 // Get the name of a data array specified by the zero-based index (arrayIdx). 149 const char * GetDataArrayName( int arrayIdx ); 150 151 // Description: 152 // Get the status of a specific data array (0: un-selected; 1: selected). 153 int GetDataArrayStatus( const char * arayName ); 154 155 // Description: 156 // Set the status of a specific data array (0: de-select; 1: select) specified 157 // by the name. 158 void SetDataArrayStatus( const char * arayName, int bChecked ); 159 160 protected: 161 vtkTecplotReader(); 162 ~vtkTecplotReader(); 163 164 virtual int FillOutputPortInformation( int port, vtkInformation * info ); 165 virtual int RequestInformation( vtkInformation * request, 166 vtkInformationVector ** inputVector, 167 vtkInformationVector * outputVector ); 168 virtual int RequestData 169 ( vtkInformation *, vtkInformationVector **, vtkInformationVector * ); 170 171 // Description: 172 // A callback function registered with the selection observer. 173 static void SelectionModifiedCallback 174 ( vtkObject *, unsigned long, void * tpReader, void * ); 175 176 // Description: 177 // This function initializes the context. Note that the Tecplot file name 178 // must NOT be addressed (either specified or inited) in this function. It 179 // is addressed in constructor, destructor, and SetTecplotFile() only. 180 void Init(); 181 182 // Description: 183 // Get the data arrays list from the tecplot file header. 184 void GetDataArraysList(); 185 186 // Description: 187 // This function, the data loading engine, parses the Tecplot file to fill 188 // a vtkMultiBlockDataSet object. 189 void ReadFile( vtkMultiBlockDataSet * multZone); 190 191 // Description: 192 // This function extracts each variable array from a block-packing (component- 193 // based) zone and collects the 3D point coordinates in addition to data 194 // attributes (node-based and / or cell-based). Note that Tecplot treats 3D 195 // coordinates as variables too, though three special ones. 196 void GetArraysFromBlockPackingZone( int numNodes, int numCells, 197 vtkPoints * theNodes, vtkPointData * nodeData, vtkCellData * cellData ); 198 199 // Description: 200 // This function extracts each variable array from a point-packing (tuple- 201 // based) zone and collects the 3D point coordbinates in addition to data 202 // attributes (node-based and / or cell-based). Note that Tecplot treats 3D 203 // coordinates as variables too, though three special ones. A point-packing 204 // zone does not contain any cell data at all, instead it is supposed to 205 // contain point data only, if any. 206 void GetArraysFromPointPackingZone 207 ( int numNodes, vtkPoints * theNodes, vtkPointData * nodeData ); 208 209 // Description: 210 // This function creates a vtkStructuredGrid object made up of a set of 211 // points and the associated attributes (node-based and / or cell-based) 212 // extracted from a block-packing (i.e., component-based) zone. This 213 // vtkStructuredGrid is then inserted, with a specified zone name, to a 214 // vtkMultiBlockDataSet object. 215 void GetStructuredGridFromBlockPackingZone( int iDimSize, int jDimSize, 216 int kDimSize, int zoneIndx, const char * zoneName, 217 vtkMultiBlockDataSet * multZone ); 218 219 // Description: 220 // This function creates a vtkStructuredGrid object made up of a set of 221 // points and the associated attributes (node-based and / or cell-based) 222 // extracted from a point-packing (i.e., tuple-based) zone. This 223 // vtkStructuredGrid is then inserted, with a specified zone name, to a 224 // vtkMultiBlockDataSet object. 225 void GetStructuredGridFromPointPackingZone( int iDimSize, int jDimSize, 226 int kDimSize, int zoneIndx, const char * zoneName, 227 vtkMultiBlockDataSet * multZone ); 228 229 // Description: 230 // This function creates a vtkUnstructuredGrid object made up of a set of 231 // points and the associated attributes (node-based and / or cell-based) 232 // extracted from a block-packing (i.e., component-based) zone. This 233 // vtkUnstructuredGrid is then inserted, with a specified zone name, to a 234 // vtkMultiBlockDataSet object. 235 void GetUnstructuredGridFromBlockPackingZone( int numNodes, int numCells, 236 const char * cellType, int zoneIndx, const char * zoneName, 237 vtkMultiBlockDataSet * multZone ); 238 239 // Description: 240 // This function creates a vtkUnstructuredGrid object made up of a set of 241 // points and the associated attributes (node-based and / or cell-based) 242 // extracted from a point-packing (i.e., tuple-based) zone. This 243 // vtkUnstructuredGrid is then inserted, with a specified zone name, to a 244 // vtkMultiBlockDataSet object. 245 void GetUnstructuredGridFromPointPackingZone( int numNodes, int numCells, 246 const char * cellType,int zoneIndx, const char * zoneName, 247 vtkMultiBlockDataSet * multZone ); 248 249 // Description: 250 // This function fills an allocated vtkUnstructuredGrid object with numberCells 251 // cells of type cellTypeStr to define the grid topology. 252 void GetUnstructuredGridCells( int numberCells, const char * cellTypeStr, 253 vtkUnstructuredGrid * unstrctGrid ); 254 255 int NumberOfVariables; 256 char * FileName; 257 vtkCallbackCommand * SelectionObserver; 258 vtkDataArraySelection * DataArraySelection; 259 vtkTecplotReaderInternal * Internal; 260 261 //BTX 262 std::string DataTitle; 263 std::vector< int > CellBased; 264 std::vector< std::string > ZoneNames; 265 std::vector< std::string > Variables; 266 //ETX 267 268 private: 269 270 vtkTecplotReader( const vtkTecplotReader & ); // Not implemented. 271 void operator = ( const vtkTecplotReader & ); // Not implemented. 272 }; 273 274 #endif 275