VTK  9.1.0
vtkXdmfReaderInternal.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXdmfReaderInternal.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=========================================================================*/
20#ifndef vtkXdmfReaderInternal_h
21#define vtkXdmfReaderInternal_h
22#ifndef __VTK_WRAP__
23#ifndef VTK_WRAPPING_CXX
24
25// NAMING CONVENTION *********************************************************
26// * all member variables of the type XdmfXml* begin with XML eg. XMLNode
27// * all non-member variables of the type XdmfXml* begin with xml eg. xmlNode
28// * all member variables of the type XdmfElement (and subclasses) begin with
29// XMF eg. XMFGrid
30// * all non-member variables of the type XdmfElement (and subclasses) begin
31// with xmf eg. xmfGrid
32// ***************************************************************************
33
35#include "vtkSILBuilder.h"
36
37#include "vtk_xdmf2.h"
38#include VTKXDMF2_HEADER(XdmfArray.h)
39#include VTKXDMF2_HEADER(XdmfAttribute.h)
40#include VTKXDMF2_HEADER(XdmfDOM.h)
41//?
42#include VTKXDMF2_HEADER(XdmfDataDesc.h)
43//?
44#include VTKXDMF2_HEADER(XdmfDataItem.h)
45#include VTKXDMF2_HEADER(XdmfGrid.h)
46//?
47#include VTKXDMF2_HEADER(XdmfTopology.h)
48//?
49#include VTKXDMF2_HEADER(XdmfGeometry.h)
50//?
51#include VTKXDMF2_HEADER(XdmfTime.h)
52//?
53#include VTKXDMF2_HEADER(XdmfSet.h)
54
55#include <algorithm>
56#include <cassert>
57#include <functional>
58#include <map>
59#include <set>
60#include <sstream>
61#include <string>
62#include <vector>
63#include <vtksys/SystemTools.hxx>
64
65class vtkXdmfDomain;
66class VTKIOXDMF2_EXPORT vtkXdmfDocument
67{
68public:
69 //---------------------------------------------------------------------------
71
76 bool Parse(const char* xmffilename);
77 bool ParseString(const char* xmfdata, size_t length);
79
80 //---------------------------------------------------------------------------
84 const std::vector<std::string>& GetDomains() { return this->Domains; }
85
86 //---------------------------------------------------------------------------
88
92 bool SetActiveDomain(const char* domainname);
93 bool SetActiveDomain(int index);
95
96 //---------------------------------------------------------------------------
100 vtkXdmfDomain* GetActiveDomain() { return this->ActiveDomain; }
101
102 //---------------------------------------------------------------------------
104
110
111private:
112 // Populates the list of domains.
113 void UpdateDomains();
114
115private:
116 int ActiveDomainIndex;
117 xdmf2::XdmfDOM XMLDOM;
118 vtkXdmfDomain* ActiveDomain;
119 std::vector<std::string> Domains;
120
121 char* LastReadContents;
122 size_t LastReadContentsLength;
123 std::string LastReadFilename;
124};
125
126// I don't use vtkDataArraySelection since it's very slow when it comes to large
127// number of arrays.
128class vtkXdmfArraySelection : public std::map<std::string, bool>
129{
130public:
131 void Merge(const vtkXdmfArraySelection& other)
132 {
133 vtkXdmfArraySelection::const_iterator iter = other.begin();
134 for (; iter != other.end(); ++iter)
135 {
136 (*this)[iter->first] = iter->second;
137 }
138 }
139
140 void AddArray(const char* name, bool status = true) { (*this)[name] = status; }
141
142 bool ArrayIsEnabled(const char* name)
143 {
144 vtkXdmfArraySelection::iterator iter = this->find(name);
145 if (iter != this->end())
146 {
147 return iter->second;
148 }
149
150 // don't know anything about this array, enable it by default.
151 return true;
152 }
153
154 bool HasArray(const char* name)
155 {
156 vtkXdmfArraySelection::iterator iter = this->find(name);
157 return (iter != this->end());
158 }
159
160 int GetArraySetting(const char* name) { return this->ArrayIsEnabled(name) ? 1 : 0; }
161
162 void SetArrayStatus(const char* name, bool status) { this->AddArray(name, status); }
163
164 const char* GetArrayName(int index)
165 {
166 int cc = 0;
167 for (vtkXdmfArraySelection::iterator iter = this->begin(); iter != this->end(); ++iter)
168 {
169
170 if (cc == index)
171 {
172 return iter->first.c_str();
173 }
174 cc++;
175 }
176 return nullptr;
177 }
178
179 int GetNumberOfArrays() { return static_cast<int>(this->size()); }
180};
181
182//***************************************************************************
183class VTKIOXDMF2_EXPORT vtkXdmfDomain
184{
185private:
186 XdmfInt64 NumberOfGrids;
187 xdmf2::XdmfGrid* XMFGrids;
188
189 XdmfXmlNode XMLDomain;
190 xdmf2::XdmfDOM* XMLDOM;
191
192 unsigned int GridsOverflowCounter;
193 // these are node indices used when building the SIL.
194 vtkIdType SILBlocksRoot;
195 std::map<std::string, vtkIdType> GridCenteredAttrbuteRoots;
196 std::map<vtkIdType, std::map<XdmfInt64, vtkIdType>> GridCenteredAttrbuteValues;
197
198 vtkSILBuilder* SILBuilder;
200 vtkXdmfArraySelection* PointArrays;
201 vtkXdmfArraySelection* CellArrays;
204 std::map<XdmfFloat64, int> TimeSteps; //< Only discrete timesteps are currently
205 // supported.
206 std::map<int, XdmfFloat64> TimeStepsRev;
207
208public:
209 //---------------------------------------------------------------------------
210 // does not take ownership of the DOM, however the xmlDom must exist as long
211 // as the instance is in use.
212 vtkXdmfDomain(xdmf2::XdmfDOM* xmlDom, int domain_index);
213
214 //---------------------------------------------------------------------------
219 bool IsValid() { return (this->XMLDomain != 0); }
220
221 //---------------------------------------------------------------------------
222 vtkGraph* GetSIL() { return this->SIL; }
223
224 //---------------------------------------------------------------------------
228 XdmfInt64 GetNumberOfGrids() { return this->NumberOfGrids; }
229
230 //---------------------------------------------------------------------------
234 xdmf2::XdmfGrid* GetGrid(XdmfInt64 cc);
235
236 //---------------------------------------------------------------------------
244
245 //---------------------------------------------------------------------------
249 const std::map<XdmfFloat64, int>& GetTimeSteps() { return this->TimeSteps; }
250 const std::map<int, XdmfFloat64>& GetTimeStepsRev() { return this->TimeStepsRev; }
251
252 //---------------------------------------------------------------------------
256 int GetIndexForTime(double time);
257
258 //---------------------------------------------------------------------------
260
263 XdmfFloat64 GetTimeForIndex(int index)
264 {
265 std::map<int, XdmfFloat64>::iterator iter = this->TimeStepsRev.find(index);
266 return (iter != this->TimeStepsRev.end()) ? iter->second : 0.0;
267 }
269
270 //---------------------------------------------------------------------------
275 xdmf2::XdmfGrid* GetGrid(xdmf2::XdmfGrid* xmfGrid, double time);
276
277 //---------------------------------------------------------------------------
281 bool IsStructured(xdmf2::XdmfGrid*);
282
283 //---------------------------------------------------------------------------
289 bool GetWholeExtent(xdmf2::XdmfGrid*, int extents[6]);
290
291 //---------------------------------------------------------------------------
297 bool GetOriginAndSpacing(xdmf2::XdmfGrid*, double origin[3], double spacing[3]);
298
299 //---------------------------------------------------------------------------
301
302 // Returns VTK data type based on grid type and topology.
303 // Returns -1 on error.
304 int GetVTKDataType(xdmf2::XdmfGrid* xmfGrid);
305
306 // Returns the dimensionality (or rank) of the topology for the given grid.
307 // Returns -1 is the xmfGrid is not a uniform i.e. is a collection or a tree.
308 static int GetDataDimensionality(xdmf2::XdmfGrid* xmfGrid);
309
310 vtkXdmfArraySelection* GetPointArraySelection() { return this->PointArrays; }
311 vtkXdmfArraySelection* GetCellArraySelection() { return this->CellArrays; }
312 vtkXdmfArraySelection* GetGridSelection() { return this->Grids; }
313 vtkXdmfArraySelection* GetSetsSelection() { return this->Sets; }
314
315private:
326 void CollectMetaData();
327
328 // Used by CollectMetaData().
329 void CollectMetaData(xdmf2::XdmfGrid* xmfGrid, vtkIdType silParent);
330
331 // Used by CollectMetaData().
332 void CollectNonLeafMetaData(xdmf2::XdmfGrid* xmfGrid, vtkIdType silParent);
333
334 // Used by CollectMetaData().
335 void CollectLeafMetaData(xdmf2::XdmfGrid* xmfGrid, vtkIdType silParent);
336
338
342 bool UpdateGridAttributeInSIL(xdmf2::XdmfAttribute* xmfAttribute, vtkIdType gridSILId);
344};
345
346#endif
347#endif
348#endif
349// VTK-HeaderTest-Exclude: vtkXdmfReaderInternal.h
Base class for graph data types.
Definition: vtkGraph.h:339
An editable directed graph.
helper class to build a SIL i.e.
Definition: vtkSILBuilder.h:38
void SetArrayStatus(const char *name, bool status)
void AddArray(const char *name, bool status=true)
bool ArrayIsEnabled(const char *name)
bool HasArray(const char *name)
int GetArraySetting(const char *name)
void Merge(const vtkXdmfArraySelection &other)
const char * GetArrayName(int index)
bool Parse(const char *xmffilename)
Parse an xmf file (or string).
bool SetActiveDomain(int index)
Set the active domain.
bool ParseString(const char *xmfdata, size_t length)
Parse an xmf file (or string).
vtkXdmfDocument()
Constructor/Destructor.
const std::vector< std::string > & GetDomains()
Returns the names for available domains.
~vtkXdmfDocument()
Constructor/Destructor.
vtkXdmfDomain * GetActiveDomain()
Returns the active domain.
bool SetActiveDomain(const char *domainname)
Set the active domain.
bool IsValid()
After instantiating, check that the domain is valid.
vtkXdmfDomain(xdmf2::XdmfDOM *xmlDom, int domain_index)
int GetIndexForTime(double time)
Given a time value, returns the index.
XdmfInt64 GetNumberOfGrids()
Returns the number of top-level grids present in this domain.
xdmf2::XdmfGrid * GetGrid(XdmfInt64 cc)
Provides access to a top-level grid from this domain.
int GetVTKDataType()
Returns the VTK data type need for this domain.
int GetVTKDataType(xdmf2::XdmfGrid *xmfGrid)
const std::map< int, XdmfFloat64 > & GetTimeStepsRev()
vtkXdmfArraySelection * GetSetsSelection()
bool IsStructured(xdmf2::XdmfGrid *)
Returns true if the grids is a structured dataset.
bool GetOriginAndSpacing(xdmf2::XdmfGrid *, double origin[3], double spacing[3])
Returns the spacing and origin for the grid if the grid topology == XDMF_2DCORECTMESH or XDMF_3DCOREC...
xdmf2::XdmfGrid * GetGrid(xdmf2::XdmfGrid *xmfGrid, double time)
If xmfGrid is a temporal collection, returns the child-grid matching the requested time.
vtkXdmfArraySelection * GetPointArraySelection()
bool GetWholeExtent(xdmf2::XdmfGrid *, int extents[6])
Returns the whole extents for the dataset if the grid if IsStructured() returns true for the given gr...
static int GetDataDimensionality(xdmf2::XdmfGrid *xmfGrid)
vtkXdmfArraySelection * GetGridSelection()
vtkXdmfArraySelection * GetCellArraySelection()
XdmfFloat64 GetTimeForIndex(int index)
Returns the time value at the given index.
const std::map< XdmfFloat64, int > & GetTimeSteps()
Returns the timesteps.
int vtkIdType
Definition: vtkType.h:332