TrianglesMeshReader.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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;//for testing
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 //    /** The containing element for each boundary element (obtaining by doing tetgen with the -nn flag).
00122 //     *  In a std::vector rather than the struct to save space if not read.
00123 //     */
00124 //    std::vector<unsigned> mContainingElementsOfBoundaryElement;
00125 //
00126 //    unsigned mIndexIntoContainingElementsVector; /**< Which index to use when GetNextContainingElementOfBoundaryElement() is called */
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     /*** @return true if reading binary files, false if reading ascii files */
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_

Generated by  doxygen 1.6.2