VTK
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 =========================================================================*/
21 #ifndef __vtkXdmfReaderInternal_h
22 #define __vtkXdmfReaderInternal_h
23 
24 // NAMING CONVENTION *********************************************************
25 // * all member variables of the type XdmfXml* begin with XML eg. XMLNode
26 // * all non-member variables of the type XdmfXml* begin with xml eg. xmlNode
27 // * all member variables of the type XdmfElement (and subclasses) begin with
28 // XMF eg. XMFGrid
29 // * all non-member variables of the type XdmfElement (and subclasses) begin
30 // with xmf eg. xmfGrid
31 // ***************************************************************************
32 
34 #include "vtkSILBuilder.h"
35 
36 #include "XdmfArray.h"
37 #include "XdmfAttribute.h"
38 #include "XdmfDOM.h"
39 #include "XdmfDataDesc.h"
40 #include "XdmfDataItem.h"
41 #include "XdmfGrid.h"
42 #include "XdmfTopology.h"
43 #include "XdmfGeometry.h"
44 #include "XdmfTime.h"
45 #include "XdmfSet.h"
46 
47 #include <string>
48 #include <vector>
49 #include <set>
50 #include <map>
51 #include <vtksys/SystemTools.hxx>
52 #include <cassert>
53 #include <functional>
54 #include <algorithm>
55 #include <vtksys/ios/sstream>
56 
57 class vtkXdmfDomain;
59 {
60 public:
61  //---------------------------------------------------------------------------
63 
66  bool Parse(const char*xmffilename);
67  bool ParseString(const char* xmfdata, size_t length);
69 
70  //---------------------------------------------------------------------------
72 
73  const std::vector<std::string>& GetDomains()
74  { return this->Domains; }
76 
77  //---------------------------------------------------------------------------
79 
81  bool SetActiveDomain(const char* domainname);
82  bool SetActiveDomain(int index);
84 
85  //---------------------------------------------------------------------------
87 
89  { return this->ActiveDomain; }
91 
92  //---------------------------------------------------------------------------
94 
96  ~vtkXdmfDocument();
98 
99 private:
100  // Populates the list of domains.
101  void UpdateDomains();
102 
103 private:
104  int ActiveDomainIndex;
105  XdmfDOM XMLDOM;
106  vtkXdmfDomain* ActiveDomain;
107  std::vector<std::string> Domains;
108 
109  char* LastReadContents;
110  size_t LastReadContentsLength;
111  std::string LastReadFilename;
112 };
113 
114 // I don't use vtkDataArraySelection since it's very slow when it comes to large
115 // number of arrays.
116 class vtkXdmfArraySelection : public std::map<std::string, bool>
117 {
118 public:
119  void Merge(const vtkXdmfArraySelection& other)
120  {
121  vtkXdmfArraySelection::const_iterator iter = other.begin();
122  for (; iter != other.end(); ++iter)
123  {
124  (*this)[iter->first] = iter->second;
125  }
126  }
127 
128  void AddArray(const char* name, bool status=true)
129  {
130  (*this)[name] = status;
131  }
132 
133  bool ArrayIsEnabled(const char* name)
134  {
135  vtkXdmfArraySelection::iterator iter = this->find(name);
136  if (iter != this->end())
137  {
138  return iter->second;
139  }
140 
141  // don't know anything about this array, enable it by default.
142  return true;
143  }
144 
145  bool HasArray(const char* name)
146  {
147  vtkXdmfArraySelection::iterator iter = this->find(name);
148  return (iter != this->end());
149  }
150 
151  int GetArraySetting(const char* name)
152  {
153  return this->ArrayIsEnabled(name)? 1 : 0;
154  }
155 
156  void SetArrayStatus(const char* name, bool status)
157  {
158  this->AddArray(name, status);
159  }
160 
161  const char* GetArrayName(int index)
162  {
163  int cc=0;
164  for (vtkXdmfArraySelection::iterator iter = this->begin();
165  iter != this->end(); ++iter)
166  {
167 
168  if (cc==index)
169  {
170  return iter->first.c_str();
171  }
172  cc++;
173  }
174  return NULL;
175  }
176 
178  {
179  return static_cast<int>(this->size());
180  }
181 };
182 
183 //***************************************************************************
185 {
186 private:
187  XdmfInt64 NumberOfGrids;
188  XdmfGrid* XMFGrids;
189 
190  XdmfXmlNode XMLDomain;
191  XdmfDOM* XMLDOM;
192 
193  unsigned int GridsOverflowCounter;
194  // these are node indices used when building the SIL.
195  vtkIdType SILBlocksRoot;
196  std::map<std::string, vtkIdType> GridCenteredAttrbuteRoots;
197  std::map<vtkIdType,
198  std::map<XdmfInt64, vtkIdType> > GridCenteredAttrbuteValues;
199 
200  vtkSILBuilder* SILBuilder;
202  vtkXdmfArraySelection* PointArrays;
203  vtkXdmfArraySelection* CellArrays;
204  vtkXdmfArraySelection* Grids;
205  vtkXdmfArraySelection* Sets;
206  std::set<XdmfFloat64> TimeSteps; //< Only discrete timesteps are currently
207  // supported.
208 
209 public:
210  //---------------------------------------------------------------------------
211  // does not take ownership of the DOM, however the xmlDom must exist as long
212  // as the instance is in use.
213  vtkXdmfDomain(XdmfDOM* xmlDom, int domain_index);
214 
215  //---------------------------------------------------------------------------
217 
219  bool IsValid()
220  { return (this->XMLDomain != 0); }
222 
223  //---------------------------------------------------------------------------
225  { return this->SIL; }
226 
227  //---------------------------------------------------------------------------
229  XdmfInt64 GetNumberOfGrids() { return this->NumberOfGrids; }
230 
231  //---------------------------------------------------------------------------
233  XdmfGrid* GetGrid(XdmfInt64 cc);
234 
235  //---------------------------------------------------------------------------
239  int GetVTKDataType();
240 
241  //---------------------------------------------------------------------------
243 
244  const std::set<XdmfFloat64>& GetTimeSteps()
245  { return this->TimeSteps; }
247 
248  //---------------------------------------------------------------------------
250  int GetIndexForTime(double time);
251 
252  //---------------------------------------------------------------------------
254 
255  XdmfFloat64 GetTimeForIndex(int index)
256  {
257  std::set<XdmfFloat64>::iterator iter;
258  int cc=0;
259  for (iter = this->TimeSteps.begin(); iter != this->TimeSteps.end();
260  iter++, cc++)
261  {
262  if (cc == index)
263  {
264  return *iter;
265  }
266  }
267  // invalid index.
268  return 0.0;
269  }
271 
272  //---------------------------------------------------------------------------
275  XdmfGrid* GetGrid(XdmfGrid* xmfGrid, double time);
276 
277  //---------------------------------------------------------------------------
279  bool IsStructured(XdmfGrid*);
280 
281  //---------------------------------------------------------------------------
286  bool GetWholeExtent(XdmfGrid*, int extents[6]);
287 
288  //---------------------------------------------------------------------------
292  bool GetOriginAndSpacing(XdmfGrid*, double origin[3], double spacing[3]);
293 
294  //---------------------------------------------------------------------------
295  ~vtkXdmfDomain();
296 
297  // Returns VTK data type based on grid type and topology.
298  // Returns -1 on error.
299  int GetVTKDataType(XdmfGrid* xmfGrid);
300 
301  // Returns the dimensionality (or rank) of the topology for the given grid.
302  // Returns -1 is the xmfGrid is not a uniform i.e. is a collection or a tree.
303  static int GetDataDimensionality(XdmfGrid* xmfGrid);
304 
306  { return this->PointArrays; }
308  { return this->CellArrays; }
310  { return this->Grids; }
312  { return this->Sets; }
313 
314 private:
323  void CollectMetaData();
324 
325  // Used by CollectMetaData().
326  void CollectMetaData(XdmfGrid* xmfGrid, vtkIdType silParent);
327 
328  // Used by CollectMetaData().
329  void CollectNonLeafMetaData(XdmfGrid* xmfGrid, vtkIdType silParent);
330 
331  // Used by CollectMetaData().
332  void CollectLeafMetaData(XdmfGrid* xmfGrid, vtkIdType silParent);
333 
335 
338  bool UpdateGridAttributeInSIL(
339  XdmfAttribute* xmfAttribute, vtkIdType gridSILId);
340 };
342 
343 #endif
GLsizeiptr size
Definition: vtkgl.h:11843
void AddArray(const char *name, bool status=true)
bool ArrayIsEnabled(const char *name)
vtkXdmfArraySelection * GetPointArraySelection()
GLuint index
Definition: vtkgl.h:11983
void SetArrayStatus(const char *name, bool status)
vtkXdmfArraySelection * GetSetsSelection()
GLuint GLsizei GLsizei * length
Definition: vtkgl.h:11992
#define VTKIOXDMF2_EXPORT
int vtkIdType
Definition: vtkType.h:268
bool HasArray(const char *name)
vtkXdmfDomain * GetActiveDomain()
Base class for graph data types.
Definition: vtkGraph.h:288
vtkXdmfArraySelection * GetCellArraySelection()
GLuint const GLchar * name
Definition: vtkgl.h:11983
const std::vector< std::string > & GetDomains()
void Merge(const vtkXdmfArraySelection &other)
An editable directed graph.
vtkXdmfArraySelection * GetGridSelection()
GLuint GLuint end
Definition: vtkgl.h:11315
XdmfFloat64 GetTimeForIndex(int index)
XdmfInt64 GetNumberOfGrids()
const std::set< XdmfFloat64 > & GetTimeSteps()
const char * GetArrayName(int index)
helper class to build a SIL i.e. a directed graph used by reader producing composite datasets to desc...
Definition: vtkSILBuilder.h:36
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
int GetArraySetting(const char *name)