TrianglesMeshReader.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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;//for testing
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 //    /** The containing element for each boundary element (obtaining by doing tetgen with the -nn flag).
00114 //     *  In a std::vector rather than the struct to save space if not read.
00115 //     */
00116 //    std::vector<unsigned> mContainingElementsOfBoundaryElement;
00117 //
00118 //    unsigned mIndexIntoContainingElementsVector; /**< Which index to use when GetNextContainingElementOfBoundaryElement() is called */
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     /*** Returns true if reading binary files, false if reading ascii files */
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>
00311     void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00312                                std::vector<T>& rDataPacket, const unsigned& rNumAttributes, std::vector<T>& 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_

Generated on Tue May 31 14:31:48 2011 for Chaste by  doxygen 1.5.5