Chaste  Release::2018.1
VtkMeshReader.hpp
1 /*
2 
3 Copyright (C) Fujitsu Laboratories of Europe, 2009
4 
5 */
6 
7 /*
8 
9 Copyright (c) 2005-2018, University of Oxford.
10 All rights reserved.
11 
12 University of Oxford means the Chancellor, Masters and Scholars of the
13 University of Oxford, having an administrative office at Wellington
14 Square, Oxford OX1 2JD, UK.
15 
16 This file is part of Chaste.
17 
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20  * Redistributions of source code must retain the above copyright notice,
21  this list of conditions and the following disclaimer.
22  * Redistributions in binary form must reproduce the above copyright notice,
23  this list of conditions and the following disclaimer in the documentation
24  and/or other materials provided with the distribution.
25  * Neither the name of the University of Oxford nor the names of its
26  contributors may be used to endorse or promote products derived from this
27  software without specific prior written permission.
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
33 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
35 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 
40 */
41 
42 
43 #ifndef VTKMESHREADER_HPP_
44 #define VTKMESHREADER_HPP_
45 
46 #include <vector>
47 #include <string>
48 #include <fstream>
49 #include <sstream>
50 #include <cassert>
51 
52 #ifdef CHASTE_VTK
53 //Requires "sudo aptitude install libvtk5-dev" or similar
54 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the strstream deprecated warning for now (gcc4.3)
55 #include <vtkDataArray.h>
56 #include <vtkDoubleArray.h>
57 #include <vtkCellData.h>
58 #include <vtkPointData.h>
59 #include <vtkTetra.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkUnstructuredGridReader.h>
62 #include <vtkXMLUnstructuredGridReader.h>
63 #include <vtkGeometryFilter.h>
64 #include <vtkGenericGeometryFilter.h>
65 #include <vtkDataCompressor.h>
66 #include <vtkFeatureEdges.h>
67 #include <vtkDataSetSurfaceFilter.h>
68 #include <vtkSmartPointer.h>
69 
70 
71 #include "UblasVectorInclude.hpp"
72 #include "AbstractMeshReader.hpp"
73 
79 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
80 class VtkMeshReader : public AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>
81 {
82 private:
83 
85  vtkSmartPointer<vtkUnstructuredGrid> mpVtkUnstructuredGrid; //This is a smart pointer to keep Vtk from deleting the object in the 1D case
86 
88  vtkGeometryFilter* mpVtkGeometryFilter;
89 
91  vtkFeatureEdges* mpVtkFilterEdges;
92 
95  std::ifstream mVtuFile;
97  unsigned mNumNodes;
98  unsigned mNumElements;
99  unsigned mNumFaces;
100  unsigned mNumCableElements;
102  unsigned mNodesRead;
103  unsigned mElementsRead;
104  unsigned mFacesRead;
111  unsigned mMaxNodeBdyMarker;
116  unsigned mOrderOfElements;
117  unsigned mNodesPerElement;
126  void CommonConstructor();
127 
128 public:
129 
135  VtkMeshReader(std::string pathBaseName);
136 
143  VtkMeshReader(vtkUnstructuredGrid* p_vtkUnstructuredGrid);
144 
148  virtual ~VtkMeshReader();
149 
153  unsigned GetNumElements() const;
154 
158  unsigned GetNumCableElements() const;
159 
163  unsigned GetNumNodes() const;
164 
168  unsigned GetNumFaces() const;
169 
173  unsigned GetNumEdges() const;
174 
178  unsigned GetNumElementAttributes() const;
179 
183  unsigned GetNumCableElementAttributes() const;
184 
188  unsigned GetNumFaceAttributes() const;
189 
194  void Reset();
195 
199  std::vector<double> GetNextNode();
200 
205 
210 
215 
216 
223  void GetCellData(std::string dataName, std::vector<double>& dataPayload);
224 
232  void GetPointData(std::string dataName, std::vector<double>& dataPayload);
233 
240  void GetCellData(std::string dataName, std::vector<c_vector<double,SPACE_DIM> >& dataPayload);
241 
249  void GetPointData(std::string dataName, std::vector<c_vector<double,SPACE_DIM> >& dataPayload);
250 
254  vtkUnstructuredGrid* OutputMeshAsVtkUnstructuredGrid();
255 };
256 
257 #endif/*CHASTE_VTK*/
258 
259 #endif/*VTKMESHREADER_HPP_*/
void CommonConstructor()
unsigned GetNumCableElementAttributes() const
std::ifstream mVtuFile
unsigned mBoundaryFacesSkipped
unsigned mMaxNodeBdyMarker
unsigned mNodesRead
unsigned mNumNodes
unsigned GetNumEdges() const
unsigned mNumFaceAttributes
void GetPointData(std::string dataName, std::vector< double > &dataPayload)
unsigned GetNumFaceAttributes() const
unsigned mOrderOfElements
vtkGeometryFilter * mpVtkGeometryFilter
ElementData GetNextFaceData()
unsigned GetNumElementAttributes() const
ElementData GetNextElementData()
unsigned mNumElementAttributes
unsigned mNumCableElements
unsigned GetNumElements() const
virtual ~VtkMeshReader()
unsigned mNodesPerElement
unsigned mNumFaces
ElementData GetNextCableElementData()
unsigned mCableElementsRead
unsigned GetNumCableElements() const
unsigned mBoundaryFacesRead
vtkFeatureEdges * mpVtkFilterEdges
void GetCellData(std::string dataName, std::vector< double > &dataPayload)
unsigned mNumElements
unsigned mNumCableElementAttributes
unsigned GetNumFaces() const
unsigned GetNumNodes() const
unsigned mNumNodeAttributes
vtkUnstructuredGrid * OutputMeshAsVtkUnstructuredGrid()
unsigned mFacesRead
std::vector< double > GetNextNode()
vtkSmartPointer< vtkUnstructuredGrid > mpVtkUnstructuredGrid
VtkMeshReader(std::string pathBaseName)
unsigned mElementsRead