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;
00090 char* mNodeFileReadBuffer;
00091 char* mElementFileReadBuffer;
00092 char* mFaceFileReadBuffer;
00094
00095
00096
00097
00098
00099
00100
00101 public:
00102
00115 TrianglesMeshReader(std::string pathBaseName,
00116 unsigned orderOfElements=1,
00117 unsigned orderOfBoundaryElements=1,
00118 bool readContainingElementsForBoundaryElements=false);
00119
00123 ~TrianglesMeshReader();
00124
00126 unsigned GetNumElements() const;
00127
00129 unsigned GetNumNodes() const;
00130
00132 unsigned GetNumFaces() const;
00133
00135 unsigned GetNumElementAttributes() const;
00136
00138 unsigned GetNumFaceAttributes() const;
00139
00141 void Reset();
00142
00144 std::vector<double> GetNextNode();
00145
00147 ElementData GetNextElementData();
00148
00150 ElementData GetNextFaceData();
00151
00152
00156 unsigned GetOrderOfElements()
00157 {
00158 return mOrderOfElements;
00159 }
00163 unsigned GetOrderOfBoundaryElements()
00164 {
00165 return mOrderOfBoundaryElements;
00166 }
00167
00171 bool GetReadContainingElementOfBoundaryElement()
00172 {
00173 return mReadContainingElementOfBoundaryElement;
00174 }
00175
00182 std::vector<double> GetNode(unsigned index);
00183
00190 ElementData GetElementData(unsigned index);
00191
00198 ElementData GetFaceData(unsigned index);
00199
00200
00201 bool IsFileFormatBinary();
00202
00208 void SetReadBufferSize(unsigned bufferSize);
00209
00210 private:
00211
00213 void OpenFiles();
00214
00216 void OpenNodeFile();
00217
00219 void OpenElementsFile();
00220
00222 void OpenFacesFile();
00223
00225 void ReadHeaders();
00226
00228 void CloseFiles();
00229
00236 void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00237
00247 template<class T>
00248 void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00249 std::vector<T>& rDataPacket, const unsigned& rNumAttributes, unsigned& rAttribute);
00250
00252 std::string GetMeshFileBaseName();
00253
00255 void GetOneDimBoundary();
00256
00264 void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00265
00266 };
00267
00268 #endif //_TRIANGLESMESHREADER_HPP_