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