Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NekMesh/OutputModules/OutputVtk.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: OutputVtk.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: VTK file format output.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
37 
38 #include <vtkPolyDataWriter.h>
39 #include <vtkPolyData.h>
40 #include <vtkPoints.h>
41 #include <vtkCellArray.h>
42 
43 #include "OutputVtk.h"
44 
45 using namespace std;
46 using namespace Nektar::NekMeshUtils;
47 
48 namespace Nektar
49 {
50 namespace Utilities
51 {
52 
53 ModuleKey OutputVtk::className = GetModuleFactory().RegisterCreatorFunction(
54  ModuleKey(eOutputModule, "vtk"), OutputVtk::create, "Writes a VTK file.");
55 
56 OutputVtk::OutputVtk(MeshSharedPtr m) : OutputModule(m)
57 {
58 }
59 
61 {
62 }
63 
65 {
66  if (m_mesh->m_verbose)
67  {
68  cout << "OutputVtk: Writing file..." << endl;
69  }
70 
71  vtkPolyData *vtkMesh = vtkPolyData::New();
72  vtkPoints *vtkPoints = vtkPoints::New();
73  vtkCellArray *vtkPolys = vtkCellArray::New();
74 
76 
77  std::set<NodeSharedPtr> tmp(m_mesh->m_vertexSet.begin(),
78  m_mesh->m_vertexSet.end());
79 
80  for (it = tmp.begin(); it != tmp.end(); ++it)
81  {
82  NodeSharedPtr n = *it;
83  vtkPoints->InsertPoint(n->m_id, n->m_x, n->m_y, n->m_z);
84  }
85 
86  vtkIdType p[8];
87  vector<ElementSharedPtr> &elmt = m_mesh->m_element[m_mesh->m_expDim];
88  for (int i = 0; i < elmt.size(); ++i)
89  {
90  int vertexCount = elmt[i]->GetVertexCount();
91  for (int j = 0; j < vertexCount; ++j)
92  {
93  p[j] = elmt[i]->GetVertex(j)->m_id;
94  }
95  vtkPolys->InsertNextCell(vertexCount, &p[0]);
96  }
97 
98  vtkMesh->SetPoints(vtkPoints);
99  vtkMesh->SetPolys(vtkPolys);
100 
101  // Write out the new mesh
102  vtkPolyDataWriter *vtkMeshWriter = vtkPolyDataWriter::New();
103  vtkMeshWriter->SetFileName(m_config["outfile"].as<string>().c_str());
104 #if VTK_MAJOR_VERSION <= 5
105  vtkMeshWriter->SetInput(vtkMesh);
106 #else
107  vtkMeshWriter->SetInputData(vtkMesh);
108 #endif
109  vtkMeshWriter->Update();
110 }
111 }
112 }
pair< ModuleType, string > ModuleKey
Abstract base class for output modules.
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
MeshSharedPtr m_mesh
Mesh object.
virtual void Process()
Write mesh to output file.
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:137
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215