TrianglesMeshReader.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _TRIANGLESMESHREADER_HPP_
00031 #define _TRIANGLESMESHREADER_HPP_
00032
00033 #include <vector>
00034 #include <string>
00035 #include <fstream>
00036 #include "AbstractMeshReader.hpp"
00037
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 class TrianglesMeshReader : public AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>
00046 {
00047 private:
00048
00049 bool mIndexFromZero;
00051 std::string mFilesBaseName;
00053 std::ifstream mNodesFile;
00054 std::ifstream mElementsFile;
00055 std::ifstream mFacesFile;
00056 std::streampos mNodeFileDataStart;
00057 std::streamoff mNodeItemWidth;
00058 std::streampos mElementFileDataStart;
00059 std::streamoff mElementItemWidth;
00060 std::streampos mFaceFileDataStart;
00061 std::streamoff mFaceItemWidth;
00063 unsigned mNumNodes;
00064 unsigned mNumElements;
00065 unsigned mNumFaces;
00067 unsigned mNodesRead;
00068 unsigned mElementsRead;
00069 unsigned mFacesRead;
00070 unsigned mBoundaryFacesRead;
00071 std::vector<unsigned> mOneDimBoundary;
00073 unsigned mNumNodeAttributes;
00074 unsigned mMaxNodeBdyMarker;
00075 unsigned mNumElementNodes;
00076 unsigned mNumElementAttributes;
00077 unsigned mNumFaceAttributes;
00079 unsigned mOrderOfElements;
00080 unsigned mOrderOfBoundaryElements;
00081 unsigned mNodesPerElement;
00082 unsigned mNodesPerBoundaryElement;
00084 bool mEofException;
00086 bool mReadContainingElementOfBoundaryElement;
00087 bool mFilesAreBinary;
00088 bool mMeshIsHexahedral;
00091
00092
00093
00094
00095
00096
00097
00098 public:
00099
00111 TrianglesMeshReader(std::string pathBaseName,
00112 unsigned orderOfElements=1,
00113 unsigned orderOfBoundaryElements=1,
00114 bool readContainingElementsForBoundaryElements=false);
00115
00117 unsigned GetNumElements() const;
00118
00120 unsigned GetNumNodes() const;
00121
00123 unsigned GetNumFaces() const;
00124
00126 unsigned GetNumEdges() const;
00127
00129 unsigned GetNumElementAttributes() const;
00130
00132 unsigned GetNumFaceAttributes() const;
00133
00135 void Reset();
00136
00138 std::vector<double> GetNextNode();
00139
00141 ElementData GetNextElementData();
00142
00144 ElementData GetNextFaceData();
00145
00146
00150 unsigned GetOrderOfElements()
00151 {
00152 return mOrderOfElements;
00153 }
00157 unsigned GetOrderOfBoundaryElements()
00158 {
00159 return mOrderOfBoundaryElements;
00160 }
00161
00165 bool GetReadContainingElementOfBoundaryElement()
00166 {
00167 return mReadContainingElementOfBoundaryElement;
00168 }
00169
00176 std::vector<double> GetNode(unsigned index);
00177
00184 ElementData GetElementData(unsigned index);
00185
00192 ElementData GetFaceData(unsigned index);
00193
00194
00195 bool IsFileFormatBinary();
00196
00197 private:
00198
00200 void OpenFiles();
00201
00203 void OpenNodeFile();
00204
00206 void OpenElementsFile();
00207
00209 void OpenFacesFile();
00210
00212 void ReadHeaders();
00213
00215 void CloseFiles();
00216
00223 void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00224
00234 template<class T>
00235 void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00236 std::vector<T>& rDataPacket, const unsigned& rNumAttributes, unsigned& rAttribute);
00237
00239 std::string GetMeshFileBaseName();
00240
00242 void GetOneDimBoundary();
00243
00251 void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00252 };
00253
00254 #endif //_TRIANGLESMESHREADER_HPP_