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 //?
40 #include "XdmfDataDesc.h"
41 //?
42 #include "XdmfDataItem.h"
43 #include "XdmfGrid.h"
44 //?
45 #include "XdmfTopology.h"
46 //?
47 #include "XdmfGeometry.h"
48 //?
49 #include "XdmfTime.h"
50 //?
51 #include "XdmfSet.h"
52 
53 #include <string>
54 #include <vector>
55 #include <set>
56 #include <map>
57 #include <vtksys/SystemTools.hxx>
58 #include <cassert>
59 #include <functional>
60 #include <algorithm>
61 #include <vtksys/ios/sstream>
62 
63 class vtkXdmfDomain;
65 {
66 public:
67  //---------------------------------------------------------------------------
69 
72  bool Parse(const char*xmffilename);
73  bool ParseString(const char* xmfdata, size_t length);
75 
76  //---------------------------------------------------------------------------
78 
79  const std::vector<std::string>& GetDomains()
80  { return this->Domains; }
82 
83  //---------------------------------------------------------------------------
85 
87  bool SetActiveDomain(const char* domainname);
88  bool SetActiveDomain(int index);
90 
91  //---------------------------------------------------------------------------
93 
95  { return this->ActiveDomain; }
97 
98  //---------------------------------------------------------------------------
100 
101  vtkXdmfDocument();
102  ~vtkXdmfDocument();
104 
105 private:
106  // Populates the list of domains.
107  void UpdateDomains();
108 
109 private:
110  int ActiveDomainIndex;
111  xdmf2::XdmfDOM XMLDOM;
112  vtkXdmfDomain* ActiveDomain;
113  std::vector<std::string> Domains;
114 
115  char* LastReadContents;
116  size_t LastReadContentsLength;
117  std::string LastReadFilename;
118 };
119 
120 // I don't use vtkDataArraySelection since it's very slow when it comes to large
121 // number of arrays.
122 class vtkXdmfArraySelection : public std::map<std::string, bool>
123 {
124 public:
125  void Merge(const vtkXdmfArraySelection& other)
126  {
127  vtkXdmfArraySelection::const_iterator iter = other.begin();
128  for (; iter != other.end(); ++iter)
129  {
130  (*this)[iter->first] = iter->second;
131  }
132  }
133 
134  void AddArray(const char* name, bool status=true)
135  {
136  (*this)[name] = status;
137  }
138 
139  bool ArrayIsEnabled(const char* name)
140  {
141  vtkXdmfArraySelection::iterator iter = this->find(name);
142  if (iter != this->end())
143  {
144  return iter->second;
145  }
146 
147  // don't know anything about this array, enable it by default.
148  return true;
149  }
150 
151  bool HasArray(const char* name)
152  {
153  vtkXdmfArraySelection::iterator iter = this->find(name);
154  return (iter != this->end());
155  }
156 
157  int GetArraySetting(const char* name)
158  {
159  return this->ArrayIsEnabled(name)? 1 : 0;
160  }
161 
162  void SetArrayStatus(const char* name, bool status)
163  {
164  this->AddArray(name, status);
165  }
166 
167  const char* GetArrayName(int index)
168  {
169  int cc=0;
170  for (vtkXdmfArraySelection::iterator iter = this->begin();
171  iter != this->end(); ++iter)
172  {
173 
174  if (cc==index)
175  {
176  return iter->first.c_str();
177  }
178  cc++;
179  }
180  return NULL;
181  }
182 
184  {
185  return static_cast<int>(this->size());
186  }
187 };
188 
189 //***************************************************************************
191 {
192 private:
193  XdmfInt64 NumberOfGrids;
194  xdmf2::XdmfGrid* XMFGrids;
195 
196  XdmfXmlNode XMLDomain;
197  xdmf2::XdmfDOM* XMLDOM;
198 
199  unsigned int GridsOverflowCounter;
200  // these are node indices used when building the SIL.
201  vtkIdType SILBlocksRoot;
202  std::map<std::string, vtkIdType> GridCenteredAttrbuteRoots;
203  std::map<vtkIdType,
204  std::map<XdmfInt64, vtkIdType> > GridCenteredAttrbuteValues;
205 
206  vtkSILBuilder* SILBuilder;
208  vtkXdmfArraySelection* PointArrays;
209  vtkXdmfArraySelection* CellArrays;
210  vtkXdmfArraySelection* Grids;
211  vtkXdmfArraySelection* Sets;
212  std::set<XdmfFloat64> TimeSteps; //< Only discrete timesteps are currently
213  // supported.
214 
215 public:
216  //---------------------------------------------------------------------------
217  // does not take ownership of the DOM, however the xmlDom must exist as long
218  // as the instance is in use.
219  vtkXdmfDomain(xdmf2::XdmfDOM* xmlDom, int domain_index);
220 
221  //---------------------------------------------------------------------------
223 
225  bool IsValid()
226  { return (this->XMLDomain != 0); }
228 
229  //---------------------------------------------------------------------------
231  { return this->SIL; }
232 
233  //---------------------------------------------------------------------------
235  XdmfInt64 GetNumberOfGrids() { return this->NumberOfGrids; }
236 
237  //---------------------------------------------------------------------------
239  xdmf2::XdmfGrid* GetGrid(XdmfInt64 cc);
240 
241  //---------------------------------------------------------------------------
245  int GetVTKDataType();
246 
247  //---------------------------------------------------------------------------
249 
250  const std::set<XdmfFloat64>& GetTimeSteps()
251  { return this->TimeSteps; }
253 
254  //---------------------------------------------------------------------------
256  int GetIndexForTime(double time);
257 
258  //---------------------------------------------------------------------------
260 
261  XdmfFloat64 GetTimeForIndex(int index)
262  {
263  std::set<XdmfFloat64>::iterator iter;
264  int cc=0;
265  for (iter = this->TimeSteps.begin(); iter != this->TimeSteps.end();
266  iter++, cc++)
267  {
268  if (cc == index)
269  {
270  return *iter;
271  }
272  }
273  // invalid index.
274  return 0.0;
275  }
277 
278  //---------------------------------------------------------------------------
281  xdmf2::XdmfGrid* GetGrid(xdmf2::XdmfGrid* xmfGrid, double time);
282 
283  //---------------------------------------------------------------------------
285  bool IsStructured(xdmf2::XdmfGrid*);
286 
287  //---------------------------------------------------------------------------
292  bool GetWholeExtent(xdmf2::XdmfGrid*, int extents[6]);
293 
294  //---------------------------------------------------------------------------
298  bool GetOriginAndSpacing(xdmf2::XdmfGrid*, double origin[3], double spacing[3]);
299 
300  //---------------------------------------------------------------------------
301  ~vtkXdmfDomain();
302 
303  // Returns VTK data type based on grid type and topology.
304  // Returns -1 on error.
305  int GetVTKDataType(xdmf2::XdmfGrid* xmfGrid);
306 
307  // Returns the dimensionality (or rank) of the topology for the given grid.
308  // Returns -1 is the xmfGrid is not a uniform i.e. is a collection or a tree.
309  static int GetDataDimensionality(xdmf2::XdmfGrid* xmfGrid);
310 
312  { return this->PointArrays; }
314  { return this->CellArrays; }
316  { return this->Grids; }
318  { return this->Sets; }
319 
320 private:
329  void CollectMetaData();
330 
331  // Used by CollectMetaData().
332  void CollectMetaData(xdmf2::XdmfGrid* xmfGrid, vtkIdType silParent);
333 
334  // Used by CollectMetaData().
335  void CollectNonLeafMetaData(xdmf2::XdmfGrid* xmfGrid, vtkIdType silParent);
336 
337  // Used by CollectMetaData().
338  void CollectLeafMetaData(xdmf2::XdmfGrid* xmfGrid, vtkIdType silParent);
339 
341 
344  bool UpdateGridAttributeInSIL(
345  xdmf2::XdmfAttribute* xmfAttribute, vtkIdType gridSILId);
346 };
348 
349 #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:281
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)