TrianglesMeshReader.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 private:
00048 
00049     bool mIndexFromZero;            
00051     std::string mFilesBaseName;     
00053     std::ifstream mNodesFile;       
00054     std::ifstream mElementsFile;    
00055     std::ifstream mFacesFile;       
00056     std::streampos mNodeFileDataStart; 
00057     std::streamoff mNodeItemWidth;  
00058     std::streampos mElementFileDataStart; 
00059     std::streamoff mElementItemWidth;  
00060     std::streampos mFaceFileDataStart; 
00061     std::streamoff mFaceItemWidth;  
00063     unsigned mNumNodes;             
00064     unsigned mNumElements;          
00065     unsigned mNumFaces;             
00067     unsigned mNodesRead;            
00068     unsigned mElementsRead;         
00069     unsigned mFacesRead;            
00070     unsigned mBoundaryFacesRead;    
00071     std::vector<unsigned> mOneDimBoundary; 
00073     unsigned mNumNodeAttributes;    
00074     unsigned mMaxNodeBdyMarker;     
00075     unsigned mNumElementNodes;      
00076     unsigned mNumElementAttributes; 
00077     unsigned mNumFaceAttributes;    
00079     unsigned mOrderOfElements;      
00080     unsigned mOrderOfBoundaryElements; 
00081     unsigned mNodesPerElement;      
00082     unsigned mNodesPerBoundaryElement; 
00084     bool mEofException; 
00086     bool mReadContainingElementOfBoundaryElement; 
00087     bool mFilesAreBinary; 
00088     bool mMeshIsHexahedral; 
00090     char* mNodeFileReadBuffer; 
00091     char* mElementFileReadBuffer; 
00092     char* mFaceFileReadBuffer; 
00094 //    /** The containing element for each boundary element (obtaining by doing tetgen with the -nn flag).
00095 //     *  In a std::vector rather than the struct to save space if not read.
00096 //     */
00097 //    std::vector<unsigned> mContainingElementsOfBoundaryElement;
00098 //
00099 //    unsigned mIndexIntoContainingElementsVector; /**< Which index to use when GetNextContainingElementOfBoundaryElement() is called */
00100 
00101 public:
00102 
00115     TrianglesMeshReader(std::string pathBaseName,
00116                         unsigned orderOfElements=1,
00117                         unsigned orderOfBoundaryElements=1,
00118                         bool readContainingElementsForBoundaryElements=false);
00119 
00123      ~TrianglesMeshReader();
00124 
00126     unsigned GetNumElements() const;
00127 
00129     unsigned GetNumNodes() const;
00130 
00132     unsigned GetNumFaces() const;
00133 
00135     unsigned GetNumElementAttributes() const;
00136 
00138     unsigned GetNumFaceAttributes() const;
00139 
00141     void Reset();
00142 
00144     std::vector<double> GetNextNode();
00145 
00147     ElementData GetNextElementData();
00148 
00150     ElementData GetNextFaceData();
00151 
00152 
00156     unsigned GetOrderOfElements()
00157     {
00158         return mOrderOfElements;
00159     }
00163     unsigned GetOrderOfBoundaryElements()
00164     {
00165         return mOrderOfBoundaryElements;
00166     }
00167 
00171     bool GetReadContainingElementOfBoundaryElement()
00172     {
00173         return mReadContainingElementOfBoundaryElement;
00174     }
00175 
00182     std::vector<double> GetNode(unsigned index);
00183 
00190     ElementData GetElementData(unsigned index);
00191 
00198     ElementData GetFaceData(unsigned index);
00199 
00200     /*** Returns true if reading binary files, false if reading ascii files */
00201     bool IsFileFormatBinary();
00202 
00208     void SetReadBufferSize(unsigned bufferSize);
00209 
00210 private:
00211 
00213     void OpenFiles();
00214 
00216     void OpenNodeFile();
00217 
00219     void OpenElementsFile();
00220 
00222     void OpenFacesFile();
00223 
00225     void ReadHeaders();
00226 
00228     void CloseFiles();
00229 
00236     void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00237 
00247     template<class T>
00248     void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00249                                std::vector<T>& rDataPacket, const unsigned& rNumAttributes, unsigned& rAttribute);
00250 
00252     std::string GetMeshFileBaseName();
00253 
00255     void GetOneDimBoundary();
00256 
00264     void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00265     
00266 };
00267 
00268 #endif //_TRIANGLESMESHREADER_HPP_

Generated on Mon Nov 1 12:35:23 2010 for Chaste by  doxygen 1.5.5