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);
184 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
191 GetNextLineFromStream(mElementsFile, buffer);
193 std::stringstream buffer_stream(buffer);
195 unsigned element_index;
196 buffer_stream >> element_index;
198 unsigned offset = mIndexFromZero ? 0 : 1;
199 if (element_index != mElementsRead + offset)
201 EXCEPTION(
"Data for element " << mElementsRead <<
" missing");
205 unsigned num_nodes_in_element;
206 buffer_stream >> num_nodes_in_element;
209 for (
unsigned i=0; i<num_nodes_in_element; i++)
212 buffer_stream >> node_index;
213 element_data.
NodeIndices.push_back(node_index - offset);
217 unsigned num_faces_in_element;
218 buffer_stream >> num_faces_in_element;
220 element_data.
Faces.resize(num_faces_in_element);
221 for (
unsigned j=0; j<num_faces_in_element; j++)
228 buffer_stream >> face_index;
232 unsigned num_nodes_in_face;
233 buffer_stream >> num_nodes_in_face;
236 for (
unsigned i=0; i<num_nodes_in_face; i++)
238 unsigned node_index_face;
239 buffer_stream >> node_index_face;
240 face_data.
NodeIndices.push_back(node_index_face - offset);
245 element_data.
Faces[j] = face_data;
250 if (mNumElementAttributes > 0)
252 assert(mNumElementAttributes==1);
261 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
268 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
272 std::string file_name = mFilesBaseName +
".node";
273 mNodesFile.open(file_name.c_str());
274 if (!mNodesFile.is_open())
276 EXCEPTION(
"Could not open data file: " + file_name);
280 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
284 std::string file_name;
285 file_name = mFilesBaseName +
".cell";
287 mElementsFile.open(file_name.c_str());
288 if (!mElementsFile.is_open())
290 EXCEPTION(
"Could not open data file: " + file_name);
294 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
299 GetNextLineFromStream(mNodesFile, buffer);
300 std::stringstream buffer_stream(buffer);
301 buffer_stream >> mNumNodes >> mNumNodeAttributes;
304 GetNextLineFromStream(mNodesFile, buffer);
305 std::stringstream node_buffer_stream(buffer);
307 unsigned first_index;
308 node_buffer_stream >> first_index;
309 assert(first_index == 0 || first_index == 1);
310 mIndexFromZero = (first_index == 0);
315 GetNextLineFromStream(mNodesFile, buffer);
317 GetNextLineFromStream(mElementsFile, buffer);
318 std::stringstream element_buffer_stream(buffer);
320 element_buffer_stream >> mNumElements >> mNumElementAttributes;
323 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
327 mElementsFile.close();
330 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
337 getline(fileStream, rawLine);
339 if (fileStream.eof())
341 EXCEPTION(
"Cannot get the next line from node or element file due to incomplete data");
345 rawLine = rawLine.substr(0,rawLine.find(
'#', 0));
347 line_is_blank = (rawLine.find_first_not_of(
" \t", 0) == std::string::npos);
349 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