GenericMeshReader.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 #ifndef _GENERICMESHREADER_HPP_
00030 #define _GENERICMESHREADER_HPP_
00031 
00032 #include "AbstractMeshReader.hpp"
00033 //Possible subclasses to delegate
00034 #include "TrianglesMeshReader.hpp"
00035 #include "MemfemMeshReader.hpp"
00036 #include "VtkMeshReader.hpp"
00037 
00050 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00051 class GenericMeshReader : public AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>
00052 {
00053 private:
00057     AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>* mpMeshReader;
00058 public:
00071     GenericMeshReader(std::string pathBaseName,
00072                       unsigned orderOfElements=1,
00073                       unsigned orderOfBoundaryElements=1,
00074                       bool readContainingElementsForBoundaryElements=false)
00075     {
00076         try
00077         {
00078             mpMeshReader = new TrianglesMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName,
00079                                                                            orderOfElements,
00080                                                                            orderOfBoundaryElements,
00081                                                                            readContainingElementsForBoundaryElements);
00082         }
00083         catch (const Exception& r_triangles_exception)
00084         {
00085             if (orderOfElements!=1 || orderOfBoundaryElements!=1 || readContainingElementsForBoundaryElements)
00086             {
00087                 EXCEPTION("Quadratic meshes are only supported in Triangles format.");
00088             }
00089 
00090             try
00091             {
00092                 mpMeshReader = new MemfemMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00093             }
00094             catch (const Exception& r_memfem_exception)
00095             {
00096 #ifdef CHASTE_VTK
00097                 try
00098                 {
00099                     mpMeshReader = new VtkMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00100                 }
00101                 catch (const Exception& r_vtk_exception)
00102                 {
00103 #endif // CHASTE_VTK
00104                     std::string eol("\n");
00105                     std::string combined_message = "Could not open appropriate mesh files for " + pathBaseName + eol;
00106                     combined_message += "Triangle format: " + r_triangles_exception.GetShortMessage() + eol;
00107                     combined_message += "Memfem format: " + r_memfem_exception.GetShortMessage() + eol;
00108 #ifdef CHASTE_VTK
00109                     combined_message += "Vtk format: " + r_vtk_exception.GetShortMessage() + eol;
00110 #endif // CHASTE_VTK
00111                     EXCEPTION(combined_message);
00112 #ifdef CHASTE_VTK
00113                 }
00114 #endif // CHASTE_VTK
00115             }
00116         }
00117 
00118     }
00119 
00120 
00124     ~GenericMeshReader()
00125     {
00126         delete mpMeshReader;
00127     }
00128 
00129 
00133     unsigned GetNumNodes() const
00134     {
00135         return mpMeshReader->GetNumNodes();
00136     }
00137 
00141     unsigned GetNumElements() const
00142     {
00143         return mpMeshReader->GetNumElements();
00144     }
00145 
00149     unsigned GetNumFaces() const
00150     {
00151         return mpMeshReader->GetNumFaces();
00152     }
00156     unsigned GetNumElementAttributes() const
00157     {
00158         return mpMeshReader->GetNumElementAttributes();
00159     }
00160 
00164     unsigned GetNumFaceAttributes() const
00165     {
00166         return mpMeshReader->GetNumFaceAttributes();
00167     }
00168 
00172     void Reset()
00173     {
00174         mpMeshReader->Reset();
00175     }
00176 
00180     std::vector<double> GetNextNode()
00181     {
00182         return mpMeshReader->GetNextNode();
00183     }
00184 
00188     ElementData GetNextElementData()
00189     {
00190         return mpMeshReader->GetNextElementData();
00191     }
00195     ElementData GetNextFaceData()
00196     {
00197         return mpMeshReader->GetNextFaceData();
00198     }
00199 
00206     std::vector<double> GetNode(unsigned index)
00207     {
00208         return mpMeshReader->GetNode(index);
00209     }
00210 
00211 
00218     ElementData GetElementData(unsigned index)
00219     {
00220         return mpMeshReader->GetElementData(index);
00221     }
00222 
00223 
00230     ElementData GetFaceData(unsigned index)
00231     {
00232         return mpMeshReader->GetFaceData(index);
00233     }
00234 
00235 
00243     std::vector<unsigned> GetContainingElementIndices(unsigned index)
00244     {
00245         return mpMeshReader->GetContainingElementIndices(index);
00246     }
00247 
00252     std::string GetMeshFileBaseName()
00253     {
00254         return mpMeshReader->GetMeshFileBaseName();
00255     }
00256 
00260     bool IsFileFormatBinary()
00261     {
00262         return mpMeshReader->IsFileFormatBinary();
00263     }
00264 
00268     bool HasNclFile()
00269     {
00270         return mpMeshReader->HasNclFile();
00271     }
00272 
00273 
00274 };
00275 
00276 #endif //_GENERICMESHREADER_HPP_

Generated on Mon Apr 18 11:35:35 2011 for Chaste by  doxygen 1.5.5