VTK
dox/IO/Exodus/vtkExodusIIReaderParser.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   ParaView
00004   Module:    vtkExodusIIReaderParser.h
00005 
00006   Copyright (c) Kitware, Inc.
00007   All rights reserved.
00008   See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 =========================================================================*/
00022 #ifndef __vtkExodusIIReaderParser_h
00023 #define __vtkExodusIIReaderParser_h
00024 
00025 #include "vtkIOExodusModule.h" // For export macro
00026 #include "vtkXMLParser.h"
00027 #include "vtkSmartPointer.h"
00028 
00029 #include <vtksys/ios/sstream>
00030 #include <map>
00031 #include <vector>
00032 #include <set>
00033 #include <string>
00034 
00035 class vtkMutableDirectedGraph;
00036 class vtkStringArray;
00037 class vtkUnsignedCharArray;
00038 
00039 class VTKIOEXODUS_EXPORT vtkExodusIIReaderParser : public vtkXMLParser
00040 {
00041 public:
00042   static vtkExodusIIReaderParser* New();
00043   vtkTypeMacro(vtkExodusIIReaderParser, vtkXMLParser);
00044   void PrintSelf(ostream& os, vtkIndent indent);
00045 
00047 
00048   vtkGetObjectMacro(SIL, vtkMutableDirectedGraph);
00050 
00052   void Go(const char* filename);
00053 
00054   // Returns if the parser has some information about the block with given "id".
00055   // This is valid only after Go().
00056   bool HasInformationAboutBlock(int id)
00057     {
00058     return (this->BlockID_To_VertexID.find(id) != this->BlockID_To_VertexID.end());
00059     }
00060 
00063   std::string GetBlockName(int id);
00064 
00066 
00068   void GetBlockIds(std::set<int>& blockIdsSet)
00069     {
00070     std::map<int, vtkIdType>::iterator iter;
00071     for (iter = this->BlockID_To_VertexID.begin();
00072       iter != this->BlockID_To_VertexID.end();
00073       ++iter)
00074       {
00075       blockIdsSet.insert(iter->first);
00076       }
00077     }
00078 //BTX
00079 protected:
00080   vtkExodusIIReaderParser();
00081   ~vtkExodusIIReaderParser();
00083 
00084   virtual void StartElement( const char* tagName, const char** attrs);
00085   virtual void EndElement(const char* tagName);
00086   void FinishedParsing();
00087 
00088   const char* GetValue(const char* attr,const char** attrs)
00089     {
00090     int i;
00091     for (i=0;attrs[i];i+=2)
00092       {
00093       const char* name=strrchr(attrs[i],':');
00094       if (!name)
00095         {
00096         name=attrs[i];
00097         }
00098       else
00099         {
00100         name++;
00101         }
00102       if (strcmp(attr,name)==0)
00103         {
00104         return attrs[i+1];
00105         }
00106       }
00107     return NULL;
00108     }
00109 
00110   // Convenience methods to add vertices/edges to the SIL.
00111   vtkIdType AddVertexToSIL(const char* name);
00112   vtkIdType AddChildEdgeToSIL(vtkIdType src, vtkIdType dst);
00113   vtkIdType AddCrossEdgeToSIL(vtkIdType src, vtkIdType dst);
00114 
00118   vtkIdType GetPartVertex(const char* part_number_instance_string);
00119 
00120   // For each of the blocks, this maps the "id" attribute in the XML to the
00121   // vertex id for the block in the SIL.
00122   std::map<int, vtkIdType> BlockID_To_VertexID;
00123 
00124 
00125   // Maps block "id"s to material names.
00126   std::map<int, std::string> BlockID_To_MaterialName;
00127 
00128   // Maps material name to vertex id.
00129   // This will be build only if <material-list> is present in the XML.
00130   std::map<std::string, vtkIdType> MaterialName_To_VertexID;
00131 
00132   std::map<vtkIdType, std::string> PartVertexID_To_Descriptions;
00133 
00134   // These save the values read from <material-specification /> element present
00135   // withint the <part /> elements.
00136   // key: part vertex id
00137   // value: material name = (desp + spec)
00138   std::map<vtkIdType, std::string> MaterialSpecifications;
00139 
00140   // Maps the "{part-number} Instance: {part-instance}" key for the vertex id
00141   // for the part vertex in the Assemblies hierarchy.
00142   std::map<std::string, vtkIdType> Part_To_VertexID;
00143 
00144   // Maps a block-id to the "{part-number} Instance: {part-instance}" string.
00145   std::map<int, std::string> BlockID_To_Part;
00146 
00147   vtkMutableDirectedGraph* SIL;
00148   vtkSmartPointer<vtkStringArray> NamesArray;
00149   vtkSmartPointer<vtkUnsignedCharArray> CrossEdgesArray;
00150 
00151   std::string BlockPartNumberString;
00152 
00153   vtkIdType RootVertex;
00154   vtkIdType BlocksVertex;
00155   vtkIdType AssembliesVertex;
00156   vtkIdType MaterialsVertex;
00157   std::vector<vtkIdType> CurrentVertex;
00158 
00159   bool InBlocks;
00160   bool InMaterialAssignments;
00161 
00162 private:
00163   vtkExodusIIReaderParser(const vtkExodusIIReaderParser&); // Not implemented
00164   void operator=(const vtkExodusIIReaderParser&); // Not implemented
00165 //ETX
00166 };
00167 
00168 #endif
00169 
00170 // VTK-HeaderTest-Exclude: vtkExodusIIReaderParser.h