GenericMeshReader.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 #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:
00065     GenericMeshReader(std::string pathBaseName)
00066     {
00067         try
00068         {
00069             mpMeshReader = new TrianglesMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00070         }
00071         catch (const Exception& r_triangles_exception)
00072         {
00073             try
00074             {
00075                 mpMeshReader = new MemfemMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00076             }
00077             catch (const Exception& r_memfem_exception)
00078             {
00079 #ifdef CHASTE_VTK
00080                 try
00081                 {
00082                     mpMeshReader = new VtkMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00083                 }
00084                 catch (const Exception& r_vtk_exception)
00085                 {
00086 #endif // CHASTE_VTK
00087                     std::string eol("\n");
00088                     std::string combined_message = "Could not open appropriate mesh files for " + pathBaseName + eol;
00089                     combined_message += "Triangle format: " + r_triangles_exception.GetShortMessage() + eol; 
00090                     combined_message += "Memfem format: " + r_memfem_exception.GetShortMessage() + eol;
00091 #ifdef CHASTE_VTK
00092                     combined_message += "Vtk format: " + r_vtk_exception.GetShortMessage() + eol;
00093 #endif // CHASTE_VTK
00094                     EXCEPTION(combined_message);
00095 #ifdef CHASTE_VTK
00096                 }
00097 #endif // CHASTE_VTK
00098             }
00099         }
00100         
00101     }
00102     
00103     
00107     ~GenericMeshReader()
00108     {
00109         delete mpMeshReader;
00110     }
00111 
00112 
00116     unsigned GetNumNodes() const
00117     {
00118         return mpMeshReader->GetNumNodes();
00119     }
00120 
00124     unsigned GetNumElements() const
00125     {
00126         return mpMeshReader->GetNumElements();
00127     }
00128 
00132     unsigned GetNumFaces() const
00133     {
00134         return mpMeshReader->GetNumFaces();
00135     }
00139     unsigned GetNumElementAttributes() const
00140     {
00141         return mpMeshReader->GetNumElementAttributes();
00142     }
00143 
00147     unsigned GetNumFaceAttributes() const
00148     {
00149         return mpMeshReader->GetNumFaceAttributes();
00150     }
00151 
00155     void Reset()
00156     {
00157         mpMeshReader->Reset();
00158     }
00159     
00163     std::vector<double> GetNextNode()
00164     {
00165         return mpMeshReader->GetNextNode();
00166     }
00167 
00171     ElementData GetNextElementData()
00172     {
00173         return mpMeshReader->GetNextElementData();
00174     }
00178     ElementData GetNextFaceData()
00179     {
00180         return mpMeshReader->GetNextFaceData();
00181     }
00182     
00187     std::string GetMeshFileBaseName()
00188     {
00189         return mpMeshReader->GetMeshFileBaseName();
00190     }
00191   
00192 };
00193 
00194 #endif //_GENERICMESHREADER_HPP_

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