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
00031
00032
00033
00034
00035
00036
00037 #ifndef _TRIANGLESMESHREADER_HPP_
00038 #define _TRIANGLESMESHREADER_HPP_
00039
00040 #include <vector>
00041 #include <string>
00042 #include <fstream>
00043 #include "AbstractMeshReader.hpp"
00044
00051 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00052 class TrianglesMeshReader : public AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>
00053 {
00054
00055 friend class TestTrianglesMeshReader;
00056
00057 private:
00058
00059 bool mIndexFromZero;
00061 std::string mFilesBaseName;
00063 std::ifstream mNodesFile;
00064 std::ifstream mElementsFile;
00065 std::ifstream mFacesFile;
00066 std::ifstream mNclFile;
00067 std::ifstream mCableElementsFile;
00069 std::streampos mNodeFileDataStart;
00070 std::streamoff mNodeItemWidth;
00071 std::streampos mElementFileDataStart;
00072 std::streamoff mElementItemWidth;
00073 std::streampos mFaceFileDataStart;
00074 std::streamoff mFaceItemWidth;
00075 std::streampos mNclFileDataStart;
00076 std::streamoff mNclItemWidth;
00078 unsigned mNumNodes;
00079 unsigned mNumElements;
00080 unsigned mNumFaces;
00081 unsigned mNumCableElements;
00083 unsigned mNodesRead;
00084 unsigned mElementsRead;
00085 unsigned mCableElementsRead;
00086 unsigned mFacesRead;
00087 unsigned mBoundaryFacesRead;
00088 unsigned mNclItemsRead;
00089 std::vector<unsigned> mOneDimBoundary;
00091 unsigned mNumNodeAttributes;
00092 std::vector<double> mNodeAttributes;
00093 unsigned mMaxNodeBdyMarker;
00094 unsigned mNumElementNodes;
00095 unsigned mNumElementAttributes;
00096 unsigned mNumFaceAttributes;
00097 unsigned mNumCableElementAttributes;
00099 unsigned mOrderOfElements;
00100 unsigned mOrderOfBoundaryElements;
00101 unsigned mNodesPerElement;
00102 unsigned mNodesPerBoundaryElement;
00104 unsigned mMaxContainingElements;
00106 bool mEofException;
00108 bool mReadContainingElementOfBoundaryElement;
00109 bool mFilesAreBinary;
00110 bool mMeshIsHexahedral;
00111 bool mNclFileAvailable;
00113 char* mNodeFileReadBuffer;
00114 char* mElementFileReadBuffer;
00115 char* mFaceFileReadBuffer;
00117 bool mNodePermutationDefined;
00118 std::vector<unsigned> mPermutationVector;
00119 std::vector<unsigned> mInversePermutationVector;
00121
00122
00123
00124
00125
00126
00127
00128 public:
00129
00142 TrianglesMeshReader(std::string pathBaseName,
00143 unsigned orderOfElements=1,
00144 unsigned orderOfBoundaryElements=1,
00145 bool readContainingElementsForBoundaryElements=false);
00146
00150 ~TrianglesMeshReader();
00151
00153 unsigned GetNumElements() const;
00154
00156 unsigned GetNumNodes() const;
00157
00159 unsigned GetNumFaces() const;
00160
00162 unsigned GetNumCableElements() const;
00163
00165 unsigned GetNumElementAttributes() const;
00166
00168 unsigned GetNumFaceAttributes() const;
00169
00171 unsigned GetNumCableElementAttributes() const;
00172
00174 void Reset();
00175
00177 std::vector<double> GetNextNode();
00178
00180 ElementData GetNextElementData();
00181
00183 ElementData GetNextFaceData();
00184
00186 ElementData GetNextCableElementData();
00187
00188
00192 unsigned GetOrderOfElements()
00193 {
00194 return mOrderOfElements;
00195 }
00199 unsigned GetOrderOfBoundaryElements()
00200 {
00201 return mOrderOfBoundaryElements;
00202 }
00203
00207 bool GetReadContainingElementOfBoundaryElement()
00208 {
00209 return mReadContainingElementOfBoundaryElement;
00210 }
00211
00215 std::vector<double> GetNodeAttributes();
00216
00223 std::vector<double> GetNode(unsigned index);
00224
00231 ElementData GetElementData(unsigned index);
00232
00239 ElementData GetFaceData(unsigned index);
00240
00248 std::vector<unsigned> GetContainingElementIndices(unsigned index);
00249
00250
00251
00252 bool IsFileFormatBinary();
00253
00259 bool HasNclFile();
00260
00266 void SetReadBufferSize(unsigned bufferSize);
00267
00275 void SetNodePermutation(std::vector<unsigned>& rPermutationVector);
00276
00280 bool HasNodePermutation();
00281
00285 const std::vector<unsigned>& rGetNodePermutation();
00286
00287
00288 private:
00289
00291 void OpenFiles();
00292
00294 void OpenNodeFile();
00295
00297 void OpenElementsFile();
00298
00300 void OpenFacesFile();
00301
00303 void OpenNclFile();
00304
00306 void OpenCableElementsFile();
00307
00309 void ReadHeaders();
00310
00312 void CloseFiles();
00313
00320 void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00321
00331 template<class T_DATA>
00332 void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00333 std::vector<T_DATA>& rDataPacket, const unsigned& rNumAttributes,
00334 std::vector<double>& rAttributes);
00335
00337 std::string GetMeshFileBaseName();
00338
00340 void GetOneDimBoundary();
00341
00349 void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00350
00351 };
00352
00353 #endif //_TRIANGLESMESHREADER_HPP_