1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkCPExodusIIInSituReader.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  * @class   vtkCPExodusIIInSituReader
18  * @brief   Read an Exodus II file into data structures
19  * that map the raw arrays returned by the Exodus II library into a multi-block
20  * data set containing vtkUnstructuredGridBase subclasses.
21  *
22  *
23  * This class can be used to import Exodus II files into VTK without repacking
24  * the data into the standard VTK memory layout, avoiding the cost of a deep
25  * copy.
26  */
27 
28 #ifndef vtkCPExodusIIInSituReader_h
29 #define vtkCPExodusIIInSituReader_h
30 
31 #include "vtkIOExodusModule.h" // For export macro
32 #include "vtkMultiBlockDataSetAlgorithm.h"
33 #include "vtkNew.h" // For vtkNew
34 #include <string>   // For std::string
35 #include <vector>   // For std::vector
36 
37 class vtkDataArrayCollection;
38 class vtkPointData;
39 class vtkPoints;
40 
41 class VTKIOEXODUS_EXPORT vtkCPExodusIIInSituReader : public vtkMultiBlockDataSetAlgorithm
42 {
43 public:
44   static vtkCPExodusIIInSituReader* New();
45   vtkTypeMacro(vtkCPExodusIIInSituReader, vtkMultiBlockDataSetAlgorithm);
46   void PrintSelf(ostream& os, vtkIndent indent) override;
47 
48   ///@{
49   /**
50    * Get/Set the name of the Exodus file to read.
51    */
52   vtkSetFilePathMacro(FileName);
53   vtkGetFilePathMacro(FileName);
54   ///@}
55 
56   ///@{
57   /**
58    * Get/Set the current timestep to read as a zero-based index.
59    */
60   vtkGetMacro(CurrentTimeStep, int);
61   vtkSetMacro(CurrentTimeStep, int);
62   ///@}
63 
64   ///@{
65   /**
66    * Get the range of timesteps, represented as [0, numTimeSteps - 1]. Call
67    * UpdateInformation first to set this without reading any timestep data.
68    */
69   vtkGetVector2Macro(TimeStepRange, int);
70   ///@}
71 
72   /**
73    * Get the floating point tag associated with the timestep at 'step'.
74    */
GetTimeStepValue(int step)75   double GetTimeStepValue(int step) { return TimeSteps.at(step); }
76 
77 protected:
78   vtkCPExodusIIInSituReader();
79   ~vtkCPExodusIIInSituReader() override;
80 
81   vtkTypeBool ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
82     vtkInformationVector* outputVector) override;
83   int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
84   int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
85 
86 private:
87   vtkCPExodusIIInSituReader(const vtkCPExodusIIInSituReader&) = delete;
88   void operator=(const vtkCPExodusIIInSituReader&) = delete;
89 
90   bool ExOpen();
91   char* FileName;
92   int FileId;
93 
94   bool ExGetMetaData();
95   int NumberOfDimensions;
96   int NumberOfNodes;
97   int NumberOfElementBlocks;
98   std::vector<std::string> NodalVariableNames;
99   std::vector<std::string> ElementVariableNames;
100   std::vector<int> ElementBlockIds;
101   std::vector<double> TimeSteps;
102   int TimeStepRange[2];
103 
104   bool ExGetCoords();
105   vtkNew<vtkPoints> Points;
106 
107   bool ExGetNodalVars();
108   vtkNew<vtkPointData> PointData;
109 
110   bool ExGetElemBlocks();
111   vtkNew<vtkMultiBlockDataSet> ElementBlocks;
112 
113   void ExClose();
114 
115   int CurrentTimeStep;
116 };
117 
118 #endif // vtkCPExodusIIInSituReader_h
119