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;
00061 std::streampos mNodeFileDataStart;
00062 std::streamoff mNodeItemWidth;
00063 std::streampos mElementFileDataStart;
00064 std::streamoff mElementItemWidth;
00065 std::streampos mFaceFileDataStart;
00066 std::streamoff mFaceItemWidth;
00067 std::streampos mNclFileDataStart;
00068 std::streamoff mNclItemWidth;
00070 unsigned mNumNodes;
00071 unsigned mNumElements;
00072 unsigned mNumFaces;
00074 unsigned mNodesRead;
00075 unsigned mElementsRead;
00076 unsigned mFacesRead;
00077 unsigned mBoundaryFacesRead;
00078 std::vector<unsigned> mOneDimBoundary;
00080 unsigned mNumNodeAttributes;
00081 std::vector<double> mNodeAttributes;
00082 unsigned mMaxNodeBdyMarker;
00083 unsigned mNumElementNodes;
00084 unsigned mNumElementAttributes;
00085 unsigned mNumFaceAttributes;
00087 unsigned mOrderOfElements;
00088 unsigned mOrderOfBoundaryElements;
00089 unsigned mNodesPerElement;
00090 unsigned mNodesPerBoundaryElement;
00092 unsigned mMaxContainingElements;
00094 bool mEofException;
00096 bool mReadContainingElementOfBoundaryElement;
00097 bool mFilesAreBinary;
00098 bool mMeshIsHexahedral;
00099 bool mNclFileAvailable;
00101 char* mNodeFileReadBuffer;
00102 char* mElementFileReadBuffer;
00103 char* mFaceFileReadBuffer;
00105 bool mNodePermutationDefined;
00106 std::vector<unsigned> mPermutationVector;
00107 std::vector<unsigned> mInversePermutationVector;
00109
00110
00111
00112
00113
00114
00115
00116 public:
00117
00130 TrianglesMeshReader(std::string pathBaseName,
00131 unsigned orderOfElements=1,
00132 unsigned orderOfBoundaryElements=1,
00133 bool readContainingElementsForBoundaryElements=false);
00134
00138 ~TrianglesMeshReader();
00139
00141 unsigned GetNumElements() const;
00142
00144 unsigned GetNumNodes() const;
00145
00147 unsigned GetNumFaces() const;
00148
00150 unsigned GetNumElementAttributes() const;
00151
00153 unsigned GetNumFaceAttributes() const;
00154
00156 void Reset();
00157
00159 std::vector<double> GetNextNode();
00160
00162 ElementData GetNextElementData();
00163
00165 ElementData GetNextFaceData();
00166
00167
00171 unsigned GetOrderOfElements()
00172 {
00173 return mOrderOfElements;
00174 }
00178 unsigned GetOrderOfBoundaryElements()
00179 {
00180 return mOrderOfBoundaryElements;
00181 }
00182
00186 bool GetReadContainingElementOfBoundaryElement()
00187 {
00188 return mReadContainingElementOfBoundaryElement;
00189 }
00190
00194 std::vector<double> GetNodeAttributes();
00195
00202 std::vector<double> GetNode(unsigned index);
00203
00210 ElementData GetElementData(unsigned index);
00211
00218 ElementData GetFaceData(unsigned index);
00219
00227 std::vector<unsigned> GetContainingElementIndices(unsigned index);
00228
00229
00230
00231 bool IsFileFormatBinary();
00232
00238 bool HasNclFile();
00239
00245 void SetReadBufferSize(unsigned bufferSize);
00246
00252 void SetNodePermutation(std::vector<unsigned>& rPermutationVector);
00253
00254 private:
00255
00257 void OpenFiles();
00258
00260 void OpenNodeFile();
00261
00263 void OpenElementsFile();
00264
00266 void OpenFacesFile();
00267
00269 void OpenNclFile();
00270
00272 void ReadHeaders();
00273
00275 void CloseFiles();
00276
00283 void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00284
00294 template<class T>
00295 void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00296 std::vector<T>& rDataPacket, const unsigned& rNumAttributes, std::vector<T>& rAttributes);
00297
00299 std::string GetMeshFileBaseName();
00300
00302 void GetOneDimBoundary();
00303
00311 void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00312
00313 };
00314
00315 #endif //_TRIANGLESMESHREADER_HPP_