35 #include "VertexMeshReader.hpp"
41 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
43 : mFilesBaseName(pathBaseName),
44 mIndexFromZero(false),
49 mNumElementAttributes(0)
55 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
61 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
67 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
70 return mNumElementAttributes;
73 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
80 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
90 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
97 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
108 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
111 std::vector<double> node_data;
114 GetNextLineFromStream(mNodesFile, buffer);
116 std::stringstream buffer_stream(buffer);
119 buffer_stream >> index;
121 unsigned offset = mIndexFromZero ? 0 : 1;
122 if (index != mNodesRead + offset)
124 EXCEPTION(
"Data for node " << mNodesRead <<
" missing");
128 for (
unsigned i=0; i<SPACE_DIM+1; i++)
130 buffer_stream >> node_value;
131 node_data.push_back(node_value);
138 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
145 GetNextLineFromStream(mElementsFile, buffer);
147 std::stringstream buffer_stream(buffer);
149 unsigned element_index;
150 buffer_stream >> element_index;
152 unsigned offset = mIndexFromZero ? 0 : 1;
153 if (element_index != mElementsRead + offset)
155 EXCEPTION(
"Data for element " << mElementsRead <<
" missing");
158 unsigned num_nodes_in_element;
159 buffer_stream >> num_nodes_in_element;
163 for (
unsigned i=0; i<num_nodes_in_element; i++)
165 buffer_stream >> node_index;
166 element_data.
NodeIndices.push_back(node_index - offset);
169 if (mNumElementAttributes > 0)
171 assert(mNumElementAttributes == 1);
185 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
192 GetNextLineFromStream(mElementsFile, buffer);
194 std::stringstream buffer_stream(buffer);
196 unsigned element_index;
197 buffer_stream >> element_index;
199 unsigned offset = mIndexFromZero ? 0 : 1;
200 if (element_index != mElementsRead + offset)
202 EXCEPTION(
"Data for element " << mElementsRead <<
" missing");
206 unsigned num_nodes_in_element;
207 buffer_stream >> num_nodes_in_element;
210 for (
unsigned i=0; i<num_nodes_in_element; i++)
213 buffer_stream >> node_index;
214 element_data.
NodeIndices.push_back(node_index - offset);
218 unsigned num_faces_in_element;
219 buffer_stream >> num_faces_in_element;
221 element_data.
Faces.resize(num_faces_in_element);
222 for (
unsigned j=0; j<num_faces_in_element; j++)
229 buffer_stream >> face_index;
233 unsigned num_nodes_in_face;
234 buffer_stream >> num_nodes_in_face;
237 for (
unsigned i=0; i<num_nodes_in_face; i++)
239 unsigned node_index_face;
240 buffer_stream >> node_index_face;
241 face_data.
NodeIndices.push_back(node_index_face - offset);
246 element_data.
Faces[j] = face_data;
251 if (mNumElementAttributes > 0)
253 assert(mNumElementAttributes==1);
262 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
269 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
273 std::string file_name = mFilesBaseName +
".node";
274 mNodesFile.open(file_name.c_str());
275 if (!mNodesFile.is_open())
277 EXCEPTION(
"Could not open data file: " + file_name);
281 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
285 std::string file_name;
286 file_name = mFilesBaseName +
".cell";
288 mElementsFile.open(file_name.c_str());
289 if (!mElementsFile.is_open())
291 EXCEPTION(
"Could not open data file: " + file_name);
295 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
300 GetNextLineFromStream(mNodesFile, buffer);
301 std::stringstream buffer_stream(buffer);
302 buffer_stream >> mNumNodes >> mNumNodeAttributes;
305 GetNextLineFromStream(mNodesFile, buffer);
306 std::stringstream node_buffer_stream(buffer);
308 unsigned first_index;
309 node_buffer_stream >> first_index;
310 assert(first_index == 0 || first_index == 1);
311 mIndexFromZero = (first_index == 0);
316 GetNextLineFromStream(mNodesFile, buffer);
318 GetNextLineFromStream(mElementsFile, buffer);
319 std::stringstream element_buffer_stream(buffer);
321 element_buffer_stream >> mNumElements >> mNumElementAttributes;
324 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
328 mElementsFile.close();
331 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
338 getline(fileStream, rawLine);
340 if (fileStream.eof())
342 EXCEPTION(
"Cannot get the next line from node or element file due to incomplete data");
346 rawLine = rawLine.substr(0,rawLine.find(
'#', 0));
348 line_is_blank = (rawLine.find_first_not_of(
" \t", 0) == std::string::npos);
350 while (line_is_blank);
VertexElementData GetNextElementDataWithFaces()
#define EXCEPTION(message)
ElementData GetNextFaceData()
unsigned GetNumElementAttributes() const
std::vector< ElementData > Faces
void GetNextLineFromStream(std::ifstream &fileStream, std::string &rawLine)
std::vector< unsigned > NodeIndices
unsigned GetNumElements() const
VertexMeshReader(std::string pathBaseName)
unsigned GetNumNodes() const
unsigned GetNumEdges() const
ElementData GetNextElementData()
std::vector< double > GetNextNode()
unsigned GetNumFaces() const
std::vector< unsigned > NodeIndices