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; 
00091 //    /** The containing element for each boundary element (obtaining by doing tetgen with the -nn flag).
00092 //     *  In a std::vector rather than the struct to save space if not read.
00093 //     */
00094 //    std::vector<unsigned> mContainingElementsOfBoundaryElement;
00095 //
00096 //    unsigned mIndexIntoContainingElementsVector; /**< Which index to use when GetNextContainingElementOfBoundaryElement() is called */
00097 
00098 public:
00099 
00111     TrianglesMeshReader(std::string pathBaseName,
00112                         unsigned orderOfElements=1,
00113                         unsigned orderOfBoundaryElements=1,
00114                         bool readContainingElementsForBoundaryElements=false);
00115 
00117     unsigned GetNumElements() const;
00118 
00120     unsigned GetNumNodes() const;
00121 
00123     unsigned GetNumFaces() const;
00124 
00126     unsigned GetNumEdges() const;
00127 
00129     unsigned GetNumElementAttributes() const;
00130 
00132     unsigned GetNumFaceAttributes() const;
00133 
00135     void Reset();
00136 
00138     std::vector<double> GetNextNode();
00139 
00141     ElementData GetNextElementData();
00142 
00144     ElementData GetNextFaceData();
00145 
00146 
00150     unsigned GetOrderOfElements()
00151     {
00152         return mOrderOfElements;
00153     }
00157     unsigned GetOrderOfBoundaryElements()
00158     {
00159         return mOrderOfBoundaryElements;
00160     }
00161 
00165     bool GetReadContainingElementOfBoundaryElement()
00166     {
00167         return mReadContainingElementOfBoundaryElement;
00168     }
00169 
00176     std::vector<double> GetNode(unsigned index);
00177 
00184     ElementData GetElementData(unsigned index);
00185 
00192     ElementData GetFaceData(unsigned index);
00193 
00194     /*** Returns true if reading binary files, false if reading ascii files */
00195     bool IsFileFormatBinary();
00196 
00197 private:
00198 
00200     void OpenFiles();
00201 
00203     void OpenNodeFile();
00204 
00206     void OpenElementsFile();
00207 
00209     void OpenFacesFile();
00210 
00212     void ReadHeaders();
00213 
00215     void CloseFiles();
00216 
00223     void GetNextLineFromStream(std::ifstream& rFileStream, std::string& rRawLine);
00224 
00234     template<class T>
00235     void GetNextItemFromStream(std::ifstream& rFileStream, unsigned expectedItemNumber,
00236                                std::vector<T>& rDataPacket, const unsigned& rNumAttributes, unsigned& rAttribute);
00237 
00239     std::string GetMeshFileBaseName();
00240 
00242     void GetOneDimBoundary();
00243 
00251     void EnsureIndexingFromZero(std::vector<unsigned>& rNodeIndices);
00252 };
00253 
00254 #endif //_TRIANGLESMESHREADER_HPP_

Generated by  doxygen 1.6.2