VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkXdmfReaderInternal.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 =========================================================================*/ 00021 #ifndef __vtkXdmfReaderInternal_h 00022 #define __vtkXdmfReaderInternal_h 00023 00024 // NAMING CONVENTION ********************************************************* 00025 // * all member variables of the type XdmfXml* begin with XML eg. XMLNode 00026 // * all non-member variables of the type XdmfXml* begin with xml eg. xmlNode 00027 // * all member variables of the type XdmfElement (and subclasses) begin with 00028 // XMF eg. XMFGrid 00029 // * all non-member variables of the type XdmfElement (and subclasses) begin 00030 // with xmf eg. xmfGrid 00031 // *************************************************************************** 00032 00033 #include "vtkMutableDirectedGraph.h" 00034 #include "vtkSILBuilder.h" 00035 00036 #include "XdmfArray.h" 00037 #include "XdmfAttribute.h" 00038 #include "XdmfDOM.h" 00039 #include "XdmfDataDesc.h" 00040 #include "XdmfDataItem.h" 00041 #include "XdmfGrid.h" 00042 #include "XdmfTopology.h" 00043 #include "XdmfGeometry.h" 00044 #include "XdmfTime.h" 00045 #include "XdmfSet.h" 00046 00047 #include <string> 00048 #include <vector> 00049 #include <set> 00050 #include <map> 00051 #include <vtksys/SystemTools.hxx> 00052 #include <assert.h> 00053 #include <functional> 00054 #include <algorithm> 00055 #include <vtksys/ios/sstream> 00056 00057 class vtkXdmfDomain; 00058 class VTKIOXDMF2_EXPORT vtkXdmfDocument 00059 { 00060 public: 00061 //--------------------------------------------------------------------------- 00063 00066 bool Parse(const char*xmffilename); 00067 bool ParseString(const char* xmfdata, size_t length); 00069 00070 //--------------------------------------------------------------------------- 00072 00073 const std::vector<std::string>& GetDomains() 00074 { return this->Domains; } 00076 00077 //--------------------------------------------------------------------------- 00079 00081 bool SetActiveDomain(const char* domainname); 00082 bool SetActiveDomain(int index); 00084 00085 //--------------------------------------------------------------------------- 00087 00088 vtkXdmfDomain* GetActiveDomain() 00089 { return this->ActiveDomain; } 00091 00092 //--------------------------------------------------------------------------- 00094 00095 vtkXdmfDocument(); 00096 ~vtkXdmfDocument(); 00098 00099 private: 00100 // Populates the list of domains. 00101 void UpdateDomains(); 00102 00103 private: 00104 int ActiveDomainIndex; 00105 XdmfDOM XMLDOM; 00106 vtkXdmfDomain* ActiveDomain; 00107 std::vector<std::string> Domains; 00108 00109 char* LastReadContents; 00110 size_t LastReadContentsLength; 00111 std::string LastReadFilename; 00112 }; 00113 00114 // I don't use vtkDataArraySelection since it's very slow when it comes to large 00115 // number of arrays. 00116 class vtkXdmfArraySelection : public std::map<std::string, bool> 00117 { 00118 public: 00119 void Merge(const vtkXdmfArraySelection& other) 00120 { 00121 vtkXdmfArraySelection::const_iterator iter = other.begin(); 00122 for (; iter != other.end(); ++iter) 00123 { 00124 (*this)[iter->first] = iter->second; 00125 } 00126 } 00127 00128 void AddArray(const char* name, bool status=true) 00129 { 00130 (*this)[name] = status; 00131 } 00132 00133 bool ArrayIsEnabled(const char* name) 00134 { 00135 vtkXdmfArraySelection::iterator iter = this->find(name); 00136 if (iter != this->end()) 00137 { 00138 return iter->second; 00139 } 00140 00141 // don't know anything about this array, enable it by default. 00142 return true; 00143 } 00144 00145 bool HasArray(const char* name) 00146 { 00147 vtkXdmfArraySelection::iterator iter = this->find(name); 00148 return (iter != this->end()); 00149 } 00150 00151 int GetArraySetting(const char* name) 00152 { 00153 return this->ArrayIsEnabled(name)? 1 : 0; 00154 } 00155 00156 void SetArrayStatus(const char* name, bool status) 00157 { 00158 this->AddArray(name, status); 00159 } 00160 00161 const char* GetArrayName(int index) 00162 { 00163 int cc=0; 00164 for (vtkXdmfArraySelection::iterator iter = this->begin(); 00165 iter != this->end(); ++iter) 00166 { 00167 00168 if (cc==index) 00169 { 00170 return iter->first.c_str(); 00171 } 00172 cc++; 00173 } 00174 return NULL; 00175 } 00176 00177 int GetNumberOfArrays() 00178 { 00179 return static_cast<int>(this->size()); 00180 } 00181 }; 00182 00183 //*************************************************************************** 00184 class VTKIOXDMF2_EXPORT vtkXdmfDomain 00185 { 00186 private: 00187 XdmfInt64 NumberOfGrids; 00188 XdmfGrid* XMFGrids; 00189 00190 XdmfXmlNode XMLDomain; 00191 XdmfDOM* XMLDOM; 00192 00193 unsigned int GridsOverflowCounter; 00194 // these are node indices used when building the SIL. 00195 vtkIdType SILBlocksRoot; 00196 std::map<std::string, vtkIdType> GridCenteredAttrbuteRoots; 00197 std::map<vtkIdType, 00198 std::map<XdmfInt64, vtkIdType> > GridCenteredAttrbuteValues; 00199 00200 vtkSILBuilder* SILBuilder; 00201 vtkMutableDirectedGraph* SIL; 00202 vtkXdmfArraySelection* PointArrays; 00203 vtkXdmfArraySelection* CellArrays; 00204 vtkXdmfArraySelection* Grids; 00205 vtkXdmfArraySelection* Sets; 00206 std::set<XdmfFloat64> TimeSteps; //< Only discrete timesteps are currently 00207 // supported. 00208 00209 public: 00210 //--------------------------------------------------------------------------- 00211 // does not take ownership of the DOM, however the xmlDom must exist as long 00212 // as the instance is in use. 00213 vtkXdmfDomain(XdmfDOM* xmlDom, int domain_index); 00214 00215 //--------------------------------------------------------------------------- 00217 00219 bool IsValid() 00220 { return (this->XMLDomain != 0); } 00222 00223 //--------------------------------------------------------------------------- 00224 vtkGraph* GetSIL() 00225 { return this->SIL; } 00226 00227 //--------------------------------------------------------------------------- 00229 XdmfInt64 GetNumberOfGrids() { return this->NumberOfGrids; } 00230 00231 //--------------------------------------------------------------------------- 00233 XdmfGrid* GetGrid(XdmfInt64 cc); 00234 00235 //--------------------------------------------------------------------------- 00239 int GetVTKDataType(); 00240 00241 //--------------------------------------------------------------------------- 00243 00244 const std::set<XdmfFloat64>& GetTimeSteps() 00245 { return this->TimeSteps; } 00247 00248 //--------------------------------------------------------------------------- 00250 int GetIndexForTime(double time); 00251 00252 //--------------------------------------------------------------------------- 00254 00255 XdmfFloat64 GetTimeForIndex(int index) 00256 { 00257 std::set<XdmfFloat64>::iterator iter; 00258 int cc=0; 00259 for (iter = this->TimeSteps.begin(); iter != this->TimeSteps.end(); 00260 iter++, cc++) 00261 { 00262 if (cc == index) 00263 { 00264 return *iter; 00265 } 00266 } 00267 // invalid index. 00268 return 0.0; 00269 } 00271 00272 //--------------------------------------------------------------------------- 00275 XdmfGrid* GetGrid(XdmfGrid* xmfGrid, double time); 00276 00277 //--------------------------------------------------------------------------- 00279 bool IsStructured(XdmfGrid*); 00280 00281 //--------------------------------------------------------------------------- 00286 bool GetWholeExtent(XdmfGrid*, int extents[6]); 00287 00288 //--------------------------------------------------------------------------- 00292 bool GetOriginAndSpacing(XdmfGrid*, double origin[3], double spacing[3]); 00293 00294 //--------------------------------------------------------------------------- 00295 ~vtkXdmfDomain(); 00296 00297 // Returns VTK data type based on grid type and topology. 00298 // Returns -1 on error. 00299 int GetVTKDataType(XdmfGrid* xmfGrid); 00300 00301 // Returns the dimensionality (or rank) of the topology for the given grid. 00302 // Returns -1 is the xmfGrid is not a uniform i.e. is a collection or a tree. 00303 static int GetDataDimensionality(XdmfGrid* xmfGrid); 00304 00305 vtkXdmfArraySelection* GetPointArraySelection() 00306 { return this->PointArrays; } 00307 vtkXdmfArraySelection* GetCellArraySelection() 00308 { return this->CellArrays; } 00309 vtkXdmfArraySelection* GetGridSelection() 00310 { return this->Grids; } 00311 vtkXdmfArraySelection* GetSetsSelection() 00312 { return this->Sets; } 00313 00314 private: 00323 void CollectMetaData(); 00324 00325 // Used by CollectMetaData(). 00326 void CollectMetaData(XdmfGrid* xmfGrid, vtkIdType silParent); 00327 00328 // Used by CollectMetaData(). 00329 void CollectNonLeafMetaData(XdmfGrid* xmfGrid, vtkIdType silParent); 00330 00331 // Used by CollectMetaData(). 00332 void CollectLeafMetaData(XdmfGrid* xmfGrid, vtkIdType silParent); 00333 00335 00338 bool UpdateGridAttributeInSIL( 00339 XdmfAttribute* xmfAttribute, vtkIdType gridSILId); 00340 }; 00342 00343 #endif