VTK
vtkExodusIIReaderParser.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkExodusIIReaderParser.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 =========================================================================*/
23 #ifndef vtkExodusIIReaderParser_h
24 #define vtkExodusIIReaderParser_h
25 
26 #include "vtkIOExodusModule.h" // For export macro
27 #include "vtkXMLParser.h"
28 #include "vtkSmartPointer.h"
29 
30 #include <sstream>
31 #include <map>
32 #include <vector>
33 #include <set>
34 #include <string>
35 
37 class vtkStringArray;
39 
40 class VTKIOEXODUS_EXPORT vtkExodusIIReaderParser : public vtkXMLParser
41 {
42 public:
43  static vtkExodusIIReaderParser* New();
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
48 
52  vtkGetObjectMacro(SIL, vtkMutableDirectedGraph);
54 
58  void Go(const char* filename);
59 
60  // Returns if the parser has some information about the block with given "id".
61  // This is valid only after Go().
63  {
64  return (this->BlockID_To_VertexID.find(id) != this->BlockID_To_VertexID.end());
65  }
66 
71  std::string GetBlockName(int id);
72 
74 
78  void GetBlockIds(std::set<int>& blockIdsSet)
79  {
80  std::map<int, vtkIdType>::iterator iter;
81  for (iter = this->BlockID_To_VertexID.begin();
82  iter != this->BlockID_To_VertexID.end();
83  ++iter)
84  {
85  blockIdsSet.insert(iter->first);
86  }
87  }
89 
90 protected:
92  ~vtkExodusIIReaderParser() override;
93 
94  void StartElement( const char* tagName, const char** attrs) override;
95  void EndElement(const char* tagName) override;
96  void FinishedParsing();
97 
98  const char* GetValue(const char* attr,const char** attrs)
99  {
100  int i;
101  for (i=0;attrs[i];i+=2)
102  {
103  const char* name=strrchr(attrs[i],':');
104  if (!name)
105  {
106  name=attrs[i];
107  }
108  else
109  {
110  name++;
111  }
112  if (strcmp(attr,name)==0)
113  {
114  return attrs[i+1];
115  }
116  }
117  return nullptr;
118  }
119 
120  // Convenience methods to add vertices/edges to the SIL.
121  vtkIdType AddVertexToSIL(const char* name);
122  vtkIdType AddChildEdgeToSIL(vtkIdType src, vtkIdType dst);
123  vtkIdType AddCrossEdgeToSIL(vtkIdType src, vtkIdType dst);
124 
130  vtkIdType GetPartVertex(const char* part_number_instance_string);
131 
132  // For each of the blocks, this maps the "id" attribute in the XML to the
133  // vertex id for the block in the SIL.
134  std::map<int, vtkIdType> BlockID_To_VertexID;
135 
136 
137  // Maps block "id"s to material names.
138  std::map<int, std::string> BlockID_To_MaterialName;
139 
140  // Maps material name to vertex id.
141  // This will be build only if <material-list> is present in the XML.
142  std::map<std::string, vtkIdType> MaterialName_To_VertexID;
143 
144  std::map<vtkIdType, std::string> PartVertexID_To_Descriptions;
145 
146  // These save the values read from <material-specification /> element present
147  // withint the <part /> elements.
148  // key: part vertex id
149  // value: material name = (desp + spec)
150  std::map<vtkIdType, std::string> MaterialSpecifications;
151 
152  // Maps the "{part-number} Instance: {part-instance}" key for the vertex id
153  // for the part vertex in the Assemblies hierarchy.
154  std::map<std::string, vtkIdType> Part_To_VertexID;
155 
156  // Maps a block-id to the "{part-number} Instance: {part-instance}" string.
157  std::map<int, std::string> BlockID_To_Part;
158 
162 
164 
169  std::vector<vtkIdType> CurrentVertex;
170 
171  bool InBlocks;
173 
174 private:
176  void operator=(const vtkExodusIIReaderParser&) = delete;
177 
178 };
179 
180 #endif
181 
182 // VTK-HeaderTest-Exclude: vtkExodusIIReaderParser.h
std::map< vtkIdType, std::string > MaterialSpecifications
vtkSmartPointer< vtkStringArray > NamesArray
Parse XML to handle element tags and attributes.
Definition: vtkXMLParser.h:42
virtual void StartElement(const char *name, const char **atts)
std::vector< vtkIdType > CurrentVertex
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:349
std::map< int, vtkIdType > BlockID_To_VertexID
vtkSmartPointer< vtkUnsignedCharArray > CrossEdgesArray
vtkMutableDirectedGraph * SIL
std::map< vtkIdType, std::string > PartVertexID_To_Descriptions
std::map< int, std::string > BlockID_To_MaterialName
const char * GetValue(const char *attr, const char **attrs)
a simple class to control print indentation
Definition: vtkIndent.h:39
std::map< std::string, vtkIdType > Part_To_VertexID
An editable directed graph.
dynamic, self-adjusting array of unsigned char
std::map< std::string, vtkIdType > MaterialName_To_VertexID
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
internal parser used by vtkExodusIIReader.
void GetBlockIds(std::set< int > &blockIdsSet)
Fills up the blockIdsSet with the block ids referred to by the XML.
std::map< int, std::string > BlockID_To_Part
virtual void EndElement(const char *name)
static vtkXMLParser * New()