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 "vtkSmartPointer.h"
28 #include "vtkXMLParser.h"
29 
30 #include <map>
31 #include <set>
32 #include <sstream>
33 #include <string>
34 #include <vector>
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(); iter != this->BlockID_To_VertexID.end(); ++iter)
82  {
83  blockIdsSet.insert(iter->first);
84  }
85  }
87 
88 protected:
90  ~vtkExodusIIReaderParser() override;
91 
92  void StartElement(const char* tagName, const char** attrs) override;
93  void EndElement(const char* tagName) override;
94  void FinishedParsing();
95 
96  const char* GetValue(const char* attr, const char** attrs)
97  {
98  int i;
99  for (i = 0; attrs[i]; i += 2)
100  {
101  const char* name = strrchr(attrs[i], ':');
102  if (!name)
103  {
104  name = attrs[i];
105  }
106  else
107  {
108  name++;
109  }
110  if (strcmp(attr, name) == 0)
111  {
112  return attrs[i + 1];
113  }
114  }
115  return nullptr;
116  }
117 
118  // Convenience methods to add vertices/edges to the SIL.
119  vtkIdType AddVertexToSIL(const char* name);
120  vtkIdType AddChildEdgeToSIL(vtkIdType src, vtkIdType dst);
121  vtkIdType AddCrossEdgeToSIL(vtkIdType src, vtkIdType dst);
122 
128  vtkIdType GetPartVertex(const char* part_number_instance_string);
129 
130  // For each of the blocks, this maps the "id" attribute in the XML to the
131  // vertex id for the block in the SIL.
132  std::map<int, vtkIdType> BlockID_To_VertexID;
133 
134  // Maps block "id"s to material names.
135  std::map<int, std::string> BlockID_To_MaterialName;
136 
137  // Maps material name to vertex id.
138  // This will be build only if <material-list> is present in the XML.
139  std::map<std::string, vtkIdType> MaterialName_To_VertexID;
140 
141  std::map<vtkIdType, std::string> PartVertexID_To_Descriptions;
142 
143  // These save the values read from <material-specification /> element present
144  // withint the <part /> elements.
145  // key: part vertex id
146  // value: material name = (desp + spec)
147  std::map<vtkIdType, std::string> MaterialSpecifications;
148 
149  // Maps the "{part-number} Instance: {part-instance}" key for the vertex id
150  // for the part vertex in the Assemblies hierarchy.
151  std::map<std::string, vtkIdType> Part_To_VertexID;
152 
153  // Maps a block-id to the "{part-number} Instance: {part-instance}" string.
154  std::map<int, std::string> BlockID_To_Part;
155 
159 
161 
166  std::vector<vtkIdType> CurrentVertex;
167 
168  bool InBlocks;
170 
171 private:
173  void operator=(const vtkExodusIIReaderParser&) = delete;
174 };
175 
176 #endif
177 
178 // VTK-HeaderTest-Exclude: vtkExodusIIReaderParser.h
vtkExodusIIReaderParser
internal parser used by vtkExodusIIReader.
Definition: vtkExodusIIReaderParser.h:40
vtkExodusIIReaderParser::CurrentVertex
std::vector< vtkIdType > CurrentVertex
Definition: vtkExodusIIReaderParser.h:166
vtkMutableDirectedGraph
An editable directed graph.
Definition: vtkMutableDirectedGraph.h:45
vtkExodusIIReaderParser::NamesArray
vtkSmartPointer< vtkStringArray > NamesArray
Definition: vtkExodusIIReaderParser.h:157
vtkExodusIIReaderParser::BlockPartNumberString
std::string BlockPartNumberString
Definition: vtkExodusIIReaderParser.h:160
vtkXMLParser
Parse XML to handle element tags and attributes.
Definition: vtkXMLParser.h:39
vtkIdType
int vtkIdType
Definition: vtkType.h:343
vtkExodusIIReaderParser::BlockID_To_VertexID
std::map< int, vtkIdType > BlockID_To_VertexID
Definition: vtkExodusIIReaderParser.h:132
vtkExodusIIReaderParser::MaterialsVertex
vtkIdType MaterialsVertex
Definition: vtkExodusIIReaderParser.h:165
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkSmartPointer< vtkStringArray >
vtkXMLParser.h
vtkExodusIIReaderParser::InBlocks
bool InBlocks
Definition: vtkExodusIIReaderParser.h:168
vtkExodusIIReaderParser::HasInformationAboutBlock
bool HasInformationAboutBlock(int id)
Definition: vtkExodusIIReaderParser.h:62
vtkExodusIIReaderParser::CrossEdgesArray
vtkSmartPointer< vtkUnsignedCharArray > CrossEdgesArray
Definition: vtkExodusIIReaderParser.h:158
vtkExodusIIReaderParser::SIL
vtkMutableDirectedGraph * SIL
Definition: vtkExodusIIReaderParser.h:156
vtkExodusIIReaderParser::BlockID_To_MaterialName
std::map< int, std::string > BlockID_To_MaterialName
Definition: vtkExodusIIReaderParser.h:135
vtkXMLParser::New
static vtkXMLParser * New()
vtkExodusIIReaderParser::PartVertexID_To_Descriptions
std::map< vtkIdType, std::string > PartVertexID_To_Descriptions
Definition: vtkExodusIIReaderParser.h:141
vtkExodusIIReaderParser::GetValue
const char * GetValue(const char *attr, const char **attrs)
Definition: vtkExodusIIReaderParser.h:96
vtkExodusIIReaderParser::InMaterialAssignments
bool InMaterialAssignments
Definition: vtkExodusIIReaderParser.h:169
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkSmartPointer.h
vtkExodusIIReaderParser::RootVertex
vtkIdType RootVertex
Definition: vtkExodusIIReaderParser.h:162
vtkExodusIIReaderParser::MaterialName_To_VertexID
std::map< std::string, vtkIdType > MaterialName_To_VertexID
Definition: vtkExodusIIReaderParser.h:139
vtkXMLParser::EndElement
virtual void EndElement(const char *name)
vtkX3D::name
Definition: vtkX3D.h:225
vtkExodusIIReaderParser::Part_To_VertexID
std::map< std::string, vtkIdType > Part_To_VertexID
Definition: vtkExodusIIReaderParser.h:151
vtkExodusIIReaderParser::BlockID_To_Part
std::map< int, std::string > BlockID_To_Part
Definition: vtkExodusIIReaderParser.h:154
vtkX3D::string
Definition: vtkX3D.h:496
vtkXMLParser::StartElement
virtual void StartElement(const char *name, const char **atts)
vtkExodusIIReaderParser::GetBlockIds
void GetBlockIds(std::set< int > &blockIdsSet)
Fills up the blockIdsSet with the block ids referred to by the XML.
Definition: vtkExodusIIReaderParser.h:78
vtkExodusIIReaderParser::AssembliesVertex
vtkIdType AssembliesVertex
Definition: vtkExodusIIReaderParser.h:164
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:36
vtkXMLParser::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkExodusIIReaderParser::BlocksVertex
vtkIdType BlocksVertex
Definition: vtkExodusIIReaderParser.h:163
vtkExodusIIReaderParser::MaterialSpecifications
std::map< vtkIdType, std::string > MaterialSpecifications
Definition: vtkExodusIIReaderParser.h:147