VTK
dox/IO/EnSight/vtkGenericEnSightReader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkGenericEnSightReader.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00025 #ifndef __vtkGenericEnSightReader_h
00026 #define __vtkGenericEnSightReader_h
00027 
00028 #include "vtkIOEnSightModule.h" // For export macro
00029 #include "vtkMultiBlockDataSetAlgorithm.h"
00030 
00031 class vtkCallbackCommand;
00032 class vtkDataArrayCollection;
00033 class vtkDataArraySelection;
00034 class vtkIdListCollection;
00035 
00036 //BTX
00037 class TranslationTableType;
00038 //ETX
00039 
00040 //BTX
00041 // Cell/Point Ids store mode:
00042 // Sparse Mode is supposed to be for a large number of distributed processes (Unstructured)
00043 // Non Sparse Mode is supposed to be for a small number of distributed processes (Unstructured)
00044 // Implicit Mode is for Structured Data
00045 enum EnsightReaderCellIdMode
00046     {
00047     SINGLE_PROCESS_MODE,
00048     SPARSE_MODE,
00049     NON_SPARSE_MODE,
00050     IMPLICIT_STRUCTURED_MODE
00051     };
00052 //ETX
00053 
00054 class VTKIOENSIGHT_EXPORT vtkGenericEnSightReader : public vtkMultiBlockDataSetAlgorithm
00055 {
00056 public:
00057   static vtkGenericEnSightReader *New();
00058   vtkTypeMacro(vtkGenericEnSightReader, vtkMultiBlockDataSetAlgorithm);
00059   void PrintSelf(ostream& os, vtkIndent indent);
00060 
00062 
00063   void SetCaseFileName(const char* fileName);
00064   vtkGetStringMacro(CaseFileName);
00066 
00068 
00069   vtkSetStringMacro(FilePath);
00070   vtkGetStringMacro(FilePath);
00072 
00074 
00075   vtkGetMacro(EnSightVersion, int);
00077 
00079 
00080   vtkGetMacro(NumberOfVariables, int);
00081   vtkGetMacro(NumberOfComplexVariables, int);
00083 
00085 
00086   int GetNumberOfVariables(int type); // returns -1 if unknown type specified
00087   vtkGetMacro(NumberOfScalarsPerNode, int);
00088   vtkGetMacro(NumberOfVectorsPerNode, int);
00089   vtkGetMacro(NumberOfTensorsSymmPerNode, int);
00090   vtkGetMacro(NumberOfScalarsPerElement, int);
00091   vtkGetMacro(NumberOfVectorsPerElement, int);
00092   vtkGetMacro(NumberOfTensorsSymmPerElement, int);
00093   vtkGetMacro(NumberOfScalarsPerMeasuredNode, int);
00094   vtkGetMacro(NumberOfVectorsPerMeasuredNode, int);
00095   vtkGetMacro(NumberOfComplexScalarsPerNode, int);
00096   vtkGetMacro(NumberOfComplexVectorsPerNode, int);
00097   vtkGetMacro(NumberOfComplexScalarsPerElement, int);
00098   vtkGetMacro(NumberOfComplexVectorsPerElement, int);
00100 
00102   const char* GetDescription(int n);
00103 
00105   const char* GetComplexDescription(int n);
00106 
00115   const char* GetDescription(int n, int type);
00116 
00118 
00119   int GetVariableType(int n);
00120   int GetComplexVariableType(int n);
00122 
00124 
00125   virtual void SetTimeValue(float value);
00126   vtkGetMacro(TimeValue, float);
00128 
00130 
00131   vtkGetMacro(MinimumTimeValue, float);
00132   vtkGetMacro(MaximumTimeValue, float);
00134 
00136 
00137   vtkGetObjectMacro(TimeSets, vtkDataArrayCollection);
00139 
00144   int DetermineEnSightVersion(int quiet=0);
00145 
00147 
00148   vtkBooleanMacro(ReadAllVariables, int);
00149   vtkSetMacro(ReadAllVariables, int);
00150   vtkGetMacro(ReadAllVariables, int);
00152 
00154 
00156   vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
00157   vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
00159 
00161 
00162   int GetNumberOfPointArrays();
00163   int GetNumberOfCellArrays();
00165 
00167 
00169   const char* GetPointArrayName(int index);
00170   const char* GetCellArrayName(int index);
00172 
00174 
00176   int GetPointArrayStatus(const char* name);
00177   int GetCellArrayStatus(const char* name);
00178   void SetPointArrayStatus(const char* name, int status);
00179   void SetCellArrayStatus(const char* name, int status);
00181 
00182   //BTX
00183   enum FileTypes
00184   {
00185     ENSIGHT_6             = 0,
00186     ENSIGHT_6_BINARY      = 1,
00187     ENSIGHT_GOLD          = 2,
00188     ENSIGHT_GOLD_BINARY   = 3,
00189     ENSIGHT_MASTER_SERVER = 4
00190   };
00191   //ETX
00192 
00194 
00197   void SetByteOrderToBigEndian();
00198   void SetByteOrderToLittleEndian();
00199   vtkSetMacro(ByteOrder, int);
00200   vtkGetMacro(ByteOrder, int);
00201   const char *GetByteOrderAsString();
00203 
00204 //BTX
00205   enum
00206   {
00207     FILE_BIG_ENDIAN=0,
00208     FILE_LITTLE_ENDIAN=1,
00209     FILE_UNKNOWN_ENDIAN=2
00210   };
00211 //ETX
00212 
00214 
00216   vtkGetStringMacro(GeometryFileName);
00218 
00220 
00228   vtkSetMacro(ParticleCoordinatesByIndex, int);
00229   vtkGetMacro(ParticleCoordinatesByIndex, int);
00230   vtkBooleanMacro(ParticleCoordinatesByIndex, int);
00232 
00235   static int CanReadFile(const char *casefilename);
00236 
00237 //THIB
00238 vtkGenericEnSightReader* GetReader() { return this->Reader; }
00239 
00240 
00241 protected:
00242   vtkGenericEnSightReader();
00243   ~vtkGenericEnSightReader();
00244 
00245   virtual int FillOutputPortInformation(int port, vtkInformation* info);
00246   virtual int RequestInformation(vtkInformation*,
00247                                  vtkInformationVector**,
00248                                  vtkInformationVector*);
00249   virtual int RequestData(vtkInformation*,
00250                           vtkInformationVector**,
00251                           vtkInformationVector*);
00252 
00255   int ReadLine(char result[256]);
00256 
00259   int ReadBinaryLine(char result[80]);
00260 
00261   // Internal function that skips blank lines and reads the 1st
00262   // non-blank line it finds (up to 256 characters).
00263   // Returns 0 is there was an error.
00264   int ReadNextDataLine(char result[256]);
00265 
00267 
00268   vtkSetStringMacro(GeometryFileName);
00270 
00272 
00273   void AddVariableDescription(const char* description);
00274   void AddComplexVariableDescription(const char* description);
00276 
00278 
00279   void AddVariableType(int variableType);
00280   void AddComplexVariableType(int variableType);
00282 
00284 
00286   int  ReplaceWildcards(char* fileName, int timeSet, int fileSet);
00287   void ReplaceWildcardsHelper(char* fileName, int num);
00289 
00290   // Callback registered with the SelectionObserver.
00291   static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
00292                                         void* clientdata, void* calldata);
00293   void SelectionModified();
00294 
00295   // Utility to create argument for vtkDataArraySelection::SetArrays.
00296   char** CreateStringArray(int numStrings);
00297   void DestroyStringArray(int numStrings, char** strings);
00298 
00299   // Fill the vtkDataArraySelection objects with the current set of
00300   // EnSight variables.
00301   void SetDataArraySelectionSetsFromVariables();
00302 
00303   // Fill the vtkDataArraySelection objects with the current set of
00304   // arrays in the internal EnSight reader.
00305   void SetDataArraySelectionSetsFromReader();
00306 
00307   // Fill the internal EnSight reader's vtkDataArraySelection objects
00308   // from those in this object.
00309   void SetReaderDataArraySelectionSetsFromSelf();
00310 
00311   istream* IS;
00312   FILE *IFile;
00313   vtkGenericEnSightReader *Reader;
00314 
00315   char* CaseFileName;
00316   char* GeometryFileName;
00317   char* FilePath;
00318 
00319   // array of types (one entry per instance of variable type in case file)
00320   int* VariableTypes;
00321   int* ComplexVariableTypes;
00322 
00323   // pointers to lists of descriptions
00324   char** VariableDescriptions;
00325   char** ComplexVariableDescriptions;
00326 
00327   int NumberOfVariables;
00328   int NumberOfComplexVariables;
00329 
00330   // number of file names / descriptions per type
00331   int NumberOfScalarsPerNode;
00332   int NumberOfVectorsPerNode;
00333   int NumberOfTensorsSymmPerNode;
00334   int NumberOfScalarsPerElement;
00335   int NumberOfVectorsPerElement;
00336   int NumberOfTensorsSymmPerElement;
00337   int NumberOfScalarsPerMeasuredNode;
00338   int NumberOfVectorsPerMeasuredNode;
00339   int NumberOfComplexScalarsPerNode;
00340   int NumberOfComplexVectorsPerNode;
00341   int NumberOfComplexScalarsPerElement;
00342   int NumberOfComplexVectorsPerElement;
00343 
00344   float TimeValue;
00345   float MinimumTimeValue;
00346   float MaximumTimeValue;
00347 
00348   // Flag for whether TimeValue has been set.
00349   int TimeValueInitialized;
00350 
00351   vtkDataArrayCollection *TimeSets;
00352   virtual void SetTimeSets(vtkDataArrayCollection*);
00353 
00354   int ReadAllVariables;
00355 
00356   int ByteOrder;
00357   int ParticleCoordinatesByIndex;
00358 
00359   // The EnSight file version being read.  Valid after
00360   // UpdateInformation.  Value is -1 for unknown version.
00361   int EnSightVersion;
00362 
00363   // The array selections.  These map over the variables and complex
00364   // variables to hide the details of EnSight behind VTK terminology.
00365   vtkDataArraySelection* PointDataArraySelection;
00366   vtkDataArraySelection* CellDataArraySelection;
00367 
00368   // The observer to modify this object when the array selections are
00369   // modified.
00370   vtkCallbackCommand* SelectionObserver;
00371 
00372   // Whether the SelectionModified callback should invoke Modified.
00373   // This is used when we are copying to/from the internal reader.
00374   int SelectionModifiedDoNotCallModified;
00375 
00376   // Insert a partId and return the 'realId' that should be used.
00377   int InsertNewPartId(int partId);
00378 
00379   // Wrapper around an stl map
00380   TranslationTableType *TranslationTable;
00381 
00382 private:
00383   vtkGenericEnSightReader(const vtkGenericEnSightReader&);  // Not implemented.
00384   void operator=(const vtkGenericEnSightReader&);  // Not implemented.
00385 };
00386 
00387 #endif