36 #include "Exception.hpp" 37 #include <boost/filesystem.hpp> 38 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning 39 #include <vtkXMLUnstructuredGridWriter.h> 40 #include <vtkTriangle.h> 41 #include <vtkPoints.h> 43 #include <vtkGeometryFilter.h> 44 #include <vtkTriangleFilter.h> 45 #include <vtkSTLWriter.h> 46 #include <vtkCleanPolyData.h> 47 #include <vtkIdList.h> 48 #include <vtkCellArray.h> 49 #include <vtkDataSetTriangleFilter.h> 50 #include <vtkExtractUnstructuredGrid.h> 51 #include <vtkDataSetSurfaceFilter.h> 53 #include "MultiFormatMeshWriter.hpp" 55 template<
unsigned DIM>
65 template<
unsigned DIM>
72 template<
unsigned DIM>
78 template<
unsigned DIM>
84 template<
unsigned DIM>
90 template<
unsigned DIM>
96 template<
unsigned DIM>
102 template<
unsigned DIM>
107 EXCEPTION(
"Output file not specified for mesh writer");
115 vtkSmartPointer<vtkPoints> p_vtk_points = vtkSmartPointer<vtkPoints>::New();
116 std::vector<c_vector<double, DIM> > node_locations =
mpMesh->GetNodeLocations();
117 p_vtk_points->SetNumberOfPoints(node_locations.size());
118 for(
unsigned idx=0; idx<node_locations.size(); idx++)
122 p_vtk_points->InsertPoint(idx, node_locations[idx][0], node_locations[idx][1], node_locations[idx][2]);
126 p_vtk_points->InsertPoint(idx, node_locations[idx][0], node_locations[idx][1], 0.0);
132 std::vector<std::vector<unsigned> > element_connectivity =
mpMesh->GetConnectivity();
133 unsigned num_elements = element_connectivity.size();
134 mpVtkMesh->Allocate(num_elements, num_elements);
136 for(
unsigned idx=0; idx<num_elements; idx++)
140 vtkSmartPointer<vtkTetra> p_vtk_element = vtkSmartPointer<vtkTetra>::New();
141 unsigned num_nodes = element_connectivity[idx].size();
142 for(
unsigned jdx=0; jdx<num_nodes; jdx++)
144 p_vtk_element->GetPointIds()->SetId(jdx, element_connectivity[idx][jdx]);
146 mpVtkMesh->InsertNextCell(p_vtk_element->GetCellType(), p_vtk_element->GetPointIds());
150 vtkSmartPointer<vtkTriangle> p_vtk_element = vtkSmartPointer<vtkTriangle>::New();
151 unsigned num_nodes = element_connectivity[idx].size();
152 for(
unsigned jdx=0; jdx<num_nodes; jdx++)
154 p_vtk_element->GetPointIds()->SetId(jdx, element_connectivity[idx][jdx]);
156 mpVtkMesh->InsertNextCell(p_vtk_element->GetCellType(), p_vtk_element->GetPointIds());
163 EXCEPTION(
"No mesh has been set, cannot do write.");
168 vtkSmartPointer<vtkXMLUnstructuredGridWriter> p_writer1 = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
169 p_writer1->SetFileName((
mFilepath +
".vtu").c_str());
170 #if VTK_MAJOR_VERSION <= 5 179 vtkSmartPointer<vtkGeometryFilter> p_geom_filter = vtkSmartPointer<vtkGeometryFilter>::New();
180 #if VTK_MAJOR_VERSION <= 5 186 p_geom_filter->Update();
188 vtkSmartPointer<vtkTriangleFilter> p_tri_filter = vtkSmartPointer<vtkTriangleFilter>::New();
189 p_tri_filter->SetInputConnection(p_geom_filter->GetOutputPort());
191 vtkSmartPointer<vtkCleanPolyData> p_clean_filter = vtkSmartPointer<vtkCleanPolyData>::New();
192 p_clean_filter->SetInputConnection(p_tri_filter->GetOutputPort());
193 p_clean_filter->Update();
195 vtkSmartPointer<vtkSTLWriter> p_writer1 = vtkSmartPointer<vtkSTLWriter>::New();
196 p_writer1->SetFileName((
mFilepath +
".stl").c_str());
198 #if VTK_MAJOR_VERSION <= 5 199 p_writer1->SetInput(p_clean_filter->GetOutput());
201 p_writer1->SetInputData(p_clean_filter->GetOutput());
203 p_writer1->SetFileTypeToASCII();