Chaste Release::3.1
VtkMeshReader.hpp
00001 /*
00002 
00003 Copyright (C) Fujitsu Laboratories of Europe, 2009
00004 
00005 */
00006 
00007 /*
00008 
00009 Copyright (c) 2005-2012, University of Oxford.
00010 All rights reserved.
00011 
00012 University of Oxford means the Chancellor, Masters and Scholars of the
00013 University of Oxford, having an administrative office at Wellington
00014 Square, Oxford OX1 2JD, UK.
00015 
00016 This file is part of Chaste.
00017 
00018 Redistribution and use in source and binary forms, with or without
00019 modification, are permitted provided that the following conditions are met:
00020  * Redistributions of source code must retain the above copyright notice,
00021    this list of conditions and the following disclaimer.
00022  * Redistributions in binary form must reproduce the above copyright notice,
00023    this list of conditions and the following disclaimer in the documentation
00024    and/or other materials provided with the distribution.
00025  * Neither the name of the University of Oxford nor the names of its
00026    contributors may be used to endorse or promote products derived from this
00027    software without specific prior written permission.
00028 
00029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00030 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00031 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00032 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00033 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00034 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00035 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00036 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00037 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00038 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 
00040 */
00041 
00042 
00043 #ifndef VTKMESHREADER_HPP_
00044 #define VTKMESHREADER_HPP_
00045 
00046 #include <vector>
00047 #include <string>
00048 #include <fstream>
00049 #include <sstream>
00050 #include <cassert>
00051 
00052 #ifdef CHASTE_VTK
00053 //Requires  "sudo aptitude install libvtk5-dev" or similar
00054 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the strstream deprecated warning for now (gcc4.3)
00055 #include <vtkDataArray.h>
00056 #include <vtkDoubleArray.h>
00057 #include <vtkCellData.h>
00058 #include <vtkPointData.h>
00059 #include <vtkTetra.h>
00060 #include <vtkUnstructuredGrid.h>
00061 #include <vtkUnstructuredGridReader.h>
00062 #include <vtkXMLUnstructuredGridReader.h>
00063 #include <vtkGeometryFilter.h>
00064 #include <vtkGenericGeometryFilter.h>
00065 #include <vtkDataCompressor.h>
00066 #include <vtkFeatureEdges.h>
00067 #include <vtkDataSetSurfaceFilter.h>
00068 
00069 
00070 #include "UblasVectorInclude.hpp"
00071 #include "AbstractMeshReader.hpp"
00072 
00079 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00080 class VtkMeshReader : public AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>
00081 {
00082 private:
00083 
00085     vtkUnstructuredGrid* mpVtkUnstructuredGrid;
00086 
00088     vtkGeometryFilter* mpVtkGeometryFilter;
00089 
00091     vtkFeatureEdges* mpVtkFilterEdges;
00092 
00093     bool mIndexFromZero;             
00095     std::ifstream mVtuFile;            
00097     unsigned mNumNodes;                
00098     unsigned mNumElements;            
00099     unsigned mNumFaces;                
00100     unsigned mNumCableElements;     
00102     unsigned mNodesRead;            
00103     unsigned mElementsRead;            
00104     unsigned mFacesRead;            
00105     unsigned mBoundaryFacesRead;    
00106     unsigned mBoundaryFacesSkipped; 
00107     unsigned mCableElementsRead;    
00110     unsigned mNumNodeAttributes;    
00111     unsigned mMaxNodeBdyMarker;     
00112     unsigned mNumElementAttributes; 
00113     unsigned mNumFaceAttributes;    
00114     unsigned mNumCableElementAttributes; 
00116     unsigned mOrderOfElements;      
00117     unsigned mNodesPerElement;      
00119     int mVtkCellType;               
00126     void CommonConstructor();
00127 
00128 public:
00129 
00135     VtkMeshReader(std::string pathBaseName);
00136 
00143     VtkMeshReader(vtkUnstructuredGrid* p_vtkUnstructuredGrid);
00144 
00145 
00146 
00150     virtual ~VtkMeshReader();
00151 
00155     unsigned GetNumElements() const;
00156 
00160     unsigned GetNumCableElements() const;
00161 
00165     unsigned GetNumNodes() const;
00166 
00170     unsigned GetNumFaces() const;
00171 
00175     unsigned GetNumEdges() const;
00176 
00180     unsigned GetNumElementAttributes() const;
00181 
00185     unsigned GetNumCableElementAttributes() const;
00186 
00190     unsigned GetNumFaceAttributes() const;
00191 
00196     void Reset();
00197 
00203     void Initialize();
00204 
00208     std::vector<double> GetNextNode();
00209 
00213     ElementData GetNextElementData();
00214 
00218     ElementData GetNextFaceData();
00219 
00223     ElementData GetNextCableElementData();
00224 
00225 
00232      void GetCellData(std::string dataName, std::vector<double>& dataPayload);
00233 
00241     void GetPointData(std::string dataName, std::vector<double>& dataPayload);
00242 
00249      void GetCellData(std::string dataName, std::vector<c_vector<double,SPACE_DIM> >& dataPayload);
00250 
00258     void GetPointData(std::string dataName, std::vector<c_vector<double,SPACE_DIM> >& dataPayload);
00259 
00263     vtkUnstructuredGrid* OutputMeshAsVtkUnstructuredGrid();
00264 
00265 };
00266 
00267 #endif/*CHASTE_VTK*/
00268 
00269 #endif/*VTKMESHREADER_HPP_*/