VtkMeshReader.hpp

00001 /*
00002 
00003 Copyright (C) Fujitsu Laboratories of Europe, 2009
00004 
00005 */
00006 
00007 /*
00008 
00009 Copyright (c) 2005-2015, 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 #include <vtkSmartPointer.h>
00069 
00070 
00071 #include "UblasVectorInclude.hpp"
00072 #include "AbstractMeshReader.hpp"
00073 
00079 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00080 class VtkMeshReader : public AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>
00081 {
00082 private:
00083 
00085     vtkSmartPointer<vtkUnstructuredGrid> mpVtkUnstructuredGrid; //This is a smart pointer to keep Vtk from deleting the object in the 1D case
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 
00148     virtual ~VtkMeshReader();
00149 
00153     unsigned GetNumElements() const;
00154 
00158     unsigned GetNumCableElements() const;
00159 
00163     unsigned GetNumNodes() const;
00164 
00168     unsigned GetNumFaces() const;
00169 
00173     unsigned GetNumEdges() const;
00174 
00178     unsigned GetNumElementAttributes() const;
00179 
00183     unsigned GetNumCableElementAttributes() const;
00184 
00188     unsigned GetNumFaceAttributes() const;
00189 
00194     void Reset();
00195 
00201     void Initialize();
00202 
00206     std::vector<double> GetNextNode();
00207 
00211     ElementData GetNextElementData();
00212 
00216     ElementData GetNextFaceData();
00217 
00221     ElementData GetNextCableElementData();
00222 
00223 
00230      void GetCellData(std::string dataName, std::vector<double>& dataPayload);
00231 
00239     void GetPointData(std::string dataName, std::vector<double>& dataPayload);
00240 
00247      void GetCellData(std::string dataName, std::vector<c_vector<double,SPACE_DIM> >& dataPayload);
00248 
00256     void GetPointData(std::string dataName, std::vector<c_vector<double,SPACE_DIM> >& dataPayload);
00257 
00261     vtkUnstructuredGrid* OutputMeshAsVtkUnstructuredGrid();
00262 
00263 };
00264 
00265 #endif/*CHASTE_VTK*/
00266 
00267 #endif/*VTKMESHREADER_HPP_*/

Generated by  doxygen 1.6.2