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
00048 friend class TestTrianglesMeshReader;
00049
00050 private:
00051
00052 bool mIndexFromZero;
00054 std::string mFilesBaseName;
00056 std::ifstream mNodesFile;
00057 std::ifstream mElementsFile;
00058 std::ifstream mFacesFile;
00059 std::ifstream mNclFile;
00060 std::ifstream mCableElementsFile;
00062 std::streampos mNodeFileDataStart;
00063 std::streamoff mNodeItemWidth;
00064 std::streampos mElementFileDataStart;
00065 std::streamoff mElementItemWidth;
00066 std::streampos mFaceFileDataStart;
00067 std::streamoff mFaceItemWidth;
00068 std::streampos mNclFileDataStart;
00069 std::streamoff mNclItemWidth;
00071 unsigned mNumNodes;
00072 unsigned mNumElements;
00073 unsigned mNumFaces;
00074 unsigned mNumCableElements;
00076 unsigned mNodesRead;
00077 unsigned mElementsRead;
00078 unsigned mCableElementsRead;
00079 unsigned mFacesRead;
00080 unsigned mBoundaryFacesRead;
00081 std::vector<unsigned> mOneDimBoundary;
00083 unsigned mNumNodeAttributes;
00084 std::vector<double> mNodeAttributes;
00085 unsigned mMaxNodeBdyMarker;
00086 unsigned mNumElementNodes;
00087 unsigned mNumElementAttributes;
00088 unsigned mNumFaceAttributes;
00089 unsigned mNumCableElementAttributes;
00091 unsigned mOrderOfElements;
00092 unsigned mOrderOfBoundaryElements;
00093 unsigned mNodesPerElement;
00094 unsigned mNodesPerBoundaryElement;
00096 unsigned mMaxContainingElements;
00098 bool mEofException;
00100 bool mReadContainingElementOfBoundaryElement;
00101 bool mFilesAreBinary;
00102 bool mMeshIsHexahedral;
00103 bool mNclFileAvailable;
00105 char* mNodeFileReadBuffer;
00106 char* mElementFileReadBuffer;
00107 char* mFaceFileReadBuffer;
00109 bool mNodePermutationDefined;
00110 std::vector<unsigned> mPermutationVector;
00111 std::vector<unsigned> mInversePermutationVector;
00113
00114
00115
00116
00117
00118
00119
00120 public:
00121
00134 TrianglesMeshReader(std::string pathBaseName,
00135 unsigned orderOfElements=1,
00136 unsigned orderOfBoundaryElements=1,
00137 bool readContainingElementsForBoundaryElements=false);
00138
00142 ~TrianglesMeshReader();
00143
00145 unsigned GetNumElements() const;
00146
00148 unsigned GetNumNodes() const;
00149
00151 unsigned GetNumFaces() const;
00152
00154 unsigned GetNumCableElements() const;
00155
00157 unsigned GetNumElementAttributes() const;
00158
00160 unsigned GetNumFaceAttributes() const;
00161
00163 unsigned GetNumCableElementAttributes() const;
00164
00166 void Reset();
00167
00169 std::vector<double> GetNextNode();
00170
00172 ElementData GetNextElementData();
00173
00175 ElementData GetNextFaceData();
00176
00178 ElementData GetNextCableElementData();
00179
00180
00184 unsigned GetOrderOfElements()
00185 {
00186 return mOrderOfElements;
00187 }
00191 unsigned GetOrderOfBoundaryElements()
00192 {
00193 return mOrderOfBoundaryElements;
00194 }
00195
00199 bool GetReadContainingElementOfBoundaryElement()
00200 {
00201 return mReadContainingElementOfBoundaryElement;
00202 }
00203
00207 std::vector<double> GetNodeAttributes();
00208
00215 std::vector<double> GetNode(unsigned index);
00216
00223 ElementData GetElementData(unsigned index);
00224
00231 ElementData GetFaceData(unsigned index);
00232
00240 std::vector<unsigned> GetContainingElementIndices(unsigned index);
00241
00242
00243
00244 bool IsFileFormatBinary();
00245
00251 bool HasNclFile();
00252
00258 void SetReadBufferSize(unsigned bufferSize);
00259
00265 void SetNodePermutation(std::vector<unsigned>& rPermutationVector);
00266
00267 private:
00268
00270 void OpenFiles();
00271
00273 void OpenNodeFile();
00274
00276 void OpenElementsFile();
00277
00279 void OpenFacesFile();
00280
00282 void OpenNclFile();
00283
00285 void OpenCableElementsFile();
00286
00288 void ReadHeaders();
00289
00291 void CloseFiles();
00292
00299 void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00300
00310 template<class T_DATA, class T_ATTR>
00311 void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00312 std::vector<T_DATA>& rDataPacket, const unsigned& rNumAttributes, std::vector<T_ATTR>& rAttributes);
00313
00315 std::string GetMeshFileBaseName();
00316
00318 void GetOneDimBoundary();
00319
00327 void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00328
00329 };
00330
00331 #endif //_TRIANGLESMESHREADER_HPP_