DeleteSetOfPoints function working
[engrid.git] / stlreader.cpp
bloba28015cf75e0c4d5d2ec6f5c9fdf80500cbca340
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "stlreader.h"
24 #include "correctsurfaceorientation.h"
26 #include "vtkEgPolyDataToUnstructuredGridFilter.h"
27 #include <vtkSTLReader.h>
28 #include <vtkCleanPolyData.h>
30 StlReader::StlReader()
32 setFormat("STL files(*.stl *.STL)");
35 void StlReader::operate()
37 readInputFileName();
38 if (isValid()) {
39 vtkSTLReader *stl = vtkSTLReader::New();
40 stl->MergingOn();
41 stl->SetFileName(getCFileName());
42 stl->Update();
43 EG_VTKSP(vtkPolyData, poly);
44 poly->DeepCopy(stl->GetOutput());
45 poly->BuildCells();
46 double L = 1e99;
47 for (vtkIdType cellId = 0; cellId < poly->GetNumberOfCells(); ++cellId) {
48 vtkIdType *pts, Npts;
49 poly->GetCellPoints(cellId, Npts, pts);
50 for (int i = 0; i < Npts; ++i) {
51 vec3_t x1, x2;
52 poly->GetPoints()->GetPoint(pts[i], x1.data());
53 if (i == Npts - 1) {
54 poly->GetPoints()->GetPoint(pts[0], x2.data());
55 } else {
56 poly->GetPoints()->GetPoint(pts[i+1], x2.data());
58 L = min(L, (x1-x2).abs());
61 EG_VTKSP(vtkCleanPolyData, poly_clean);
62 poly_clean->ToleranceIsAbsoluteOn();
63 poly_clean->SetAbsoluteTolerance(0.5*L);
64 poly_clean->SetInput(poly);
65 EG_VTKSP(vtkEgPolyDataToUnstructuredGridFilter, poly2ugrid);
66 poly2ugrid->SetInput(poly_clean->GetOutput());
67 poly2ugrid->Update();
69 allocateGrid(grid, poly2ugrid->GetOutput()->GetNumberOfCells(), poly2ugrid->GetOutput()->GetNumberOfPoints());
70 for (vtkIdType id_node = 0; id_node < poly2ugrid->GetOutput()->GetNumberOfPoints(); ++id_node) {
71 vec3_t x;
72 poly2ugrid->GetOutput()->GetPoints()->GetPoint(id_node, x.data());
73 grid->GetPoints()->SetPoint(id_node, x.data());
75 for (vtkIdType id_cell = 0; id_cell < poly2ugrid->GetOutput()->GetNumberOfCells(); ++id_cell) {
76 vtkIdType N_pts, *pts;
77 vtkIdType type_cell = poly2ugrid->GetOutput()->GetCellType(id_cell);
78 poly2ugrid->GetOutput()->GetCellPoints(id_cell, N_pts, pts);
79 grid->InsertNextCell(type_cell, N_pts, pts);
82 EG_VTKDCC(vtkIntArray, bc, grid, "cell_code");
83 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
84 bc->SetValue(cellId, 999);
87 CorrectSurfaceOrientation corr_surf;
88 corr_surf.setGrid(grid);
89 corr_surf();