vtkGenericEnSightReader.h 10.3 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkGenericEnSightReader.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     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 19 20 21 22

=========================================================================*/
// .NAME vtkGenericEnSightReader - class to read any type of EnSight files
// .SECTION Description
// The class vtkGenericEnSightReader allows the user to read an EnSight data
// set without a priori knowledge of what type of EnSight data set it is.

#ifndef __vtkGenericEnSightReader_h
#define __vtkGenericEnSightReader_h

23 24
#include "vtkDataSetSource.h"

25
class vtkCallbackCommand;
26
class vtkDataArrayCollection;
27
class vtkDataArraySelection;
28
class vtkIdListCollection;
29 30 31
//BTX
class TranslationTableType;
//ETX
32

33
class VTK_IO_EXPORT vtkGenericEnSightReader : public vtkDataSetSource
34 35 36
{
public:
  static vtkGenericEnSightReader *New();
Brad King's avatar
Brad King committed
37
  vtkTypeRevisionMacro(vtkGenericEnSightReader, vtkDataSetSource);
Amy Squillacote's avatar
Amy Squillacote committed
38
  void PrintSelf(ostream& os, vtkIndent indent);
39 40 41

  // Description:
  // Set/Get the Case file name.
42
  void SetCaseFileName(const char* fileName);
43 44
  vtkGetStringMacro(CaseFileName);

Amy Squillacote's avatar
Amy Squillacote committed
45 46 47 48 49
  // Description:
  // Set/Get the file path.
  vtkSetStringMacro(FilePath);
  vtkGetStringMacro(FilePath);
  
50
  virtual void Update();
51
  virtual void ExecuteInformation();
52
  
53 54
  // Description:
  // Get the number of variables listed in the case file.
Mathieu Malaterre's avatar
ENH:  
Mathieu Malaterre committed
55 56
  vtkGetMacro(NumberOfVariables, int);
  vtkGetMacro(NumberOfComplexVariables, int);
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  // Description:
  // Get the number of variables of a particular type.
  int GetNumberOfVariables(int type); // returns -1 if unknown type specified
  vtkGetMacro(NumberOfScalarsPerNode, int);
  vtkGetMacro(NumberOfVectorsPerNode, int);
  vtkGetMacro(NumberOfTensorsSymmPerNode, int);
  vtkGetMacro(NumberOfScalarsPerElement, int);
  vtkGetMacro(NumberOfVectorsPerElement, int);
  vtkGetMacro(NumberOfTensorsSymmPerElement, int);
  vtkGetMacro(NumberOfScalarsPerMeasuredNode, int);
  vtkGetMacro(NumberOfVectorsPerMeasuredNode, int);
  vtkGetMacro(NumberOfComplexScalarsPerNode, int);
  vtkGetMacro(NumberOfComplexVectorsPerNode, int);
  vtkGetMacro(NumberOfComplexScalarsPerElement, int);
  vtkGetMacro(NumberOfComplexVectorsPerElement, int);

  // Description:
  // Get the nth description for a non-complex variable.
Mathieu Malaterre's avatar
ENH:  
Mathieu Malaterre committed
76
  const char* GetDescription(int n);
77 78 79
  
  // Description:
  // Get the nth description for a complex variable.
Mathieu Malaterre's avatar
ENH:  
Mathieu Malaterre committed
80
  const char* GetComplexDescription(int n);
81 82 83 84
  
  // Description:
  // Get the nth description of a particular variable type.  Returns NULL if no
  // variable of this type exists in this data set.
85 86 87 88 89 90
  // SCALAR_PER_NODE = 0; VECTOR_PER_NODE = 1;
  // TENSOR_SYMM_PER_NODE = 2; SCALAR_PER_ELEMENT = 3;
  // VECTOR_PER_ELEMENT = 4; TENSOR_SYMM_PER_ELEMENT = 5;
  // SCALAR_PER_MEASURED_NODE = 6; VECTOR_PER_MEASURED_NODE = 7;
  // COMPLEX_SCALAR_PER_NODE = 8; COMPLEX_VECTOR_PER_NODE 9;
  // COMPLEX_SCALAR_PER_ELEMENT  = 10; COMPLEX_VECTOR_PER_ELEMENT = 11
Mathieu Malaterre's avatar
ENH:  
Mathieu Malaterre committed
91
  const char* GetDescription(int n, int type);
92 93 94 95 96 97
  
  // Description:
  // Get the variable type of variable n.
  int GetVariableType(int n);
  int GetComplexVariableType(int n);
  
98 99
  // Description:
  // Set/Get the time value at which to get the value.
100
  virtual void SetTimeValue(float value);
101 102
  vtkGetMacro(TimeValue, float);

103 104 105 106 107
  // Description:
  // Get the minimum or maximum time value for this data set.
  vtkGetMacro(MinimumTimeValue, float);
  vtkGetMacro(MaximumTimeValue, float);
  
108 109
  // Description:
  // Get the time values per time set
110
  vtkGetObjectMacro(TimeSets, vtkDataArrayCollection);
111 112 113 114 115 116 117

  // Description:
  // Reads the FORMAT part of the case file to determine whether this is an
  // EnSight6 or EnSightGold data set.  Returns 0 if the format is EnSight6,
  // 1 if it is EnSightGold, and -1 otherwise (meaning an error occurred).
  int DetermineEnSightVersion();

118 119 120 121 122 123 124
  // Description:
  // Set/get the flag for whether to read all the variables
  vtkBooleanMacro(ReadAllVariables, int);
  vtkSetMacro(ReadAllVariables, int);
  vtkGetMacro(ReadAllVariables, int);
  
  // Description:
125 126 127 128
  // Get the data array selection tables used to configure which data
  // arrays are loaded by the reader.
  vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
  vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
129
  
130 131 132 133
  // Description:  
  // Get the number of point or cell arrays available in the input.
  int GetNumberOfPointArrays();
  int GetNumberOfCellArrays();
134 135
  
  // Description:
136 137 138 139
  // Get the name of the point or cell array with the given index in
  // the input.
  const char* GetPointArrayName(int index);
  const char* GetCellArrayName(int index);
140 141
  
  // Description:
142 143 144 145 146 147
  // Get/Set whether the point or cell array with the given name is to
  // be read.
  int GetPointArrayStatus(const char* name);
  int GetCellArrayStatus(const char* name);
  void SetPointArrayStatus(const char* name, int status);  
  void SetCellArrayStatus(const char* name, int status);  
148
  
149 150 151
  //BTX
  enum FileTypes
  {
152 153 154 155 156
    ENSIGHT_6             = 0,
    ENSIGHT_6_BINARY      = 1,
    ENSIGHT_GOLD          = 2,
    ENSIGHT_GOLD_BINARY   = 3,
    ENSIGHT_MASTER_SERVER = 4
157 158 159
  };
  //ETX

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  // Description:
  // Set the byte order of the file (remember, more Unix workstations
  // write big endian whereas PCs write little endian). Default is
  // big endian (since most older PLOT3D files were written by
  // workstations).
  void SetByteOrderToBigEndian();
  void SetByteOrderToLittleEndian();
  vtkSetMacro(ByteOrder, int);
  vtkGetMacro(ByteOrder, int);
  const char *GetByteOrderAsString();

//BTX
  enum 
  {
    FILE_BIG_ENDIAN=0,
Amy Squillacote's avatar
Amy Squillacote committed
175 176
    FILE_LITTLE_ENDIAN=1,
    FILE_UNKNOWN_ENDIAN=2
177 178 179
  };
//ETX

180 181 182 183 184 185
protected:
  vtkGenericEnSightReader();
  ~vtkGenericEnSightReader();

  void Execute();
  
186 187 188 189 190
  // Description:
  // Internal function to read in a line up to 256 characters.
  // Returns zero if there was an error.
  int ReadLine(char result[256]);

191 192 193 194 195
  // Description:
  // Internal function to read up to 80 characters from a binary file.
  // Returns zero if there was an error.
  int ReadBinaryLine(char result[80]);
  
196 197 198 199 200
  // Internal function that skips blank lines and reads the 1st
  // non-blank line it finds (up to 256 characters).
  // Returns 0 is there was an error.
  int ReadNextDataLine(char result[256]);

201 202 203 204 205
  // Description:
  // Set/Get the geometry file name.
  vtkSetStringMacro(GeometryFileName);
  vtkGetStringMacro(GeometryFileName);
  
206 207
  // Description:
  // Add a variable description to the appropriate array.
Mathieu Malaterre's avatar
ENH:  
Mathieu Malaterre committed
208 209
  void AddVariableDescription(const char* description);
  void AddComplexVariableDescription(const char* description);
210 211 212 213 214 215

  // Description:
  // Add a variable type to the appropriate array.
  void AddVariableType(int variableType);
  void AddComplexVariableType(int variableType);

216 217 218 219 220 221
  // Description:
  // Replace the wildcards in the geometry file name with appropriate filename
  // numbers as specified in the time set or file set.
  void ReplaceWildcards(char* fileName, int timeSet, int fileSet);
  void ReplaceWildcardsHelper(char* fileName, int num);
  
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
  // Callback registered with the SelectionObserver.
  static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
                                        void* clientdata, void* calldata);
  void SelectionModified();
  
  // Utility to create argument for vtkDataArraySelection::SetArrays.
  char** CreateStringArray(int numStrings);
  void DestroyStringArray(int numStrings, char** strings);

  // Fill the vtkDataArraySelection objects with the current set of
  // EnSight variables.
  void SetDataArraySelectionSetsFromVariables();
  
  // Fill the vtkDataArraySelection objects with the current set of
  // arrays in the internal EnSight reader.
  void SetDataArraySelectionSetsFromReader();
  
  // Fill the internal EnSight reader's vtkDataArraySelection objects
  // from those in this object.
  void SetReaderDataArraySelectionSetsFromSelf();
  
243
  istream* IS;
244
  FILE *IFile;
245
  vtkGenericEnSightReader *Reader;
246 247
  
  char* CaseFileName;
248
  char* GeometryFileName;
249 250
  char* FilePath;

251
  // array of types (one entry per instance of variable type in case file)
252 253 254
  int* VariableTypes;
  int* ComplexVariableTypes;
  
255
  // pointers to lists of descriptions
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
  char** VariableDescriptions;
  char** ComplexVariableDescriptions;
  
  int NumberOfVariables;
  int NumberOfComplexVariables;
  
  // number of file names / descriptions per type
  int NumberOfScalarsPerNode;
  int NumberOfVectorsPerNode;
  int NumberOfTensorsSymmPerNode;
  int NumberOfScalarsPerElement;
  int NumberOfVectorsPerElement;
  int NumberOfTensorsSymmPerElement;
  int NumberOfScalarsPerMeasuredNode;
  int NumberOfVectorsPerMeasuredNode;
  int NumberOfComplexScalarsPerNode;
  int NumberOfComplexVectorsPerNode;  
  int NumberOfComplexScalarsPerElement;
  int NumberOfComplexVectorsPerElement;
275 276
  
  float TimeValue;
277 278
  float MinimumTimeValue;
  float MaximumTimeValue;
279
  
280 281 282
  // Flag for whether TimeValue has been set.
  int TimeValueInitialized;
  
283 284
  vtkDataArrayCollection *TimeSets;
  virtual void SetTimeSets(vtkDataArrayCollection*);
285 286

  int ReadAllVariables;
287 288

  int ByteOrder;
289
  
290 291 292 293
  // The EnSight file version being read.  Valid after
  // UpdateInformation.  Value is -1 for unknown version.
  int EnSightVersion;
  
294 295 296 297 298 299 300 301 302 303 304 305
  // The array selections.  These map over the variables and complex
  // variables to hide the details of EnSight behind VTK terminology.
  vtkDataArraySelection* PointDataArraySelection;
  vtkDataArraySelection* CellDataArraySelection;
  
  // The observer to modify this object when the array selections are
  // modified.
  vtkCallbackCommand* SelectionObserver;
  
  // Whether the SelectionModified callback should invoke Modified.
  // This is used when we are copying to/from the internal reader.
  int SelectionModifiedDoNotCallModified;
306 307 308 309 310 311 312 313 314

  // Insert a partId and return the 'realId' that should be used.
  int InsertNewPartId(int partId);

//BTX
  // Wrapper around an stl map
  TranslationTableType *TranslationTable;
//ETX

315 316 317
private:
  vtkGenericEnSightReader(const vtkGenericEnSightReader&);  // Not implemented.
  void operator=(const vtkGenericEnSightReader&);  // Not implemented.
318 319 320
};

#endif