VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataKiteRemovalFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataKiteRemovalFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:47:48 $
7Version: $Revision: 1.2 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkvmtkConstants.h"
24#include "vtkPolyData.h"
25#include "vtkPointData.h"
26#include "vtkCellData.h"
27#include "vtkIdList.h"
28#include "vtkTriangleFilter.h"
29#include "vtkCleanPolyData.h"
30#include "vtkTriangle.h"
31#include "vtkInformation.h"
32#include "vtkInformationVector.h"
33#include "vtkObjectFactory.h"
34#include "vtkVersion.h"
35
36
38
43
47
49 vtkInformation *vtkNotUsed(request),
50 vtkInformationVector **inputVector,
51 vtkInformationVector *outputVector)
52{
53 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
54 vtkInformation *outInfo = outputVector->GetInformationObject(0);
55
56 vtkPolyData *input = vtkPolyData::SafeDownCast(
57 inInfo->Get(vtkDataObject::DATA_OBJECT()));
58 vtkPolyData *output = vtkPolyData::SafeDownCast(
59 outInfo->Get(vtkDataObject::DATA_OBJECT()));
60
61 vtkTriangleFilter* triangleFilter = vtkTriangleFilter::New();
62 triangleFilter->SetInputData(input);
63 triangleFilter->PassLinesOff();
64 triangleFilter->PassVertsOff();
65 triangleFilter->Update();
66
67 vtkPolyData* surface = vtkPolyData::New();
68 surface->CopyStructure(triangleFilter->GetOutput());
69 surface->GetPointData()->PassData(triangleFilter->GetOutput()->GetPointData());
70 surface->GetCellData()->PassData(triangleFilter->GetOutput()->GetCellData());
71 surface->GetFieldData()->PassData(triangleFilter->GetOutput()->GetFieldData());
72 surface->BuildCells();
73 surface->BuildLinks();
74
75 double averageTriangleArea = 0.0;
76 int numberOfCells = surface->GetNumberOfCells();
77 double point[3], point1[3], point2[3];
78 vtkIdList* cellPointIds = vtkIdList::New();
79 for (vtkIdType cellId=0; cellId<numberOfCells; cellId++)
80 {
81 cellPointIds->Initialize();
82 surface->GetCellPoints(cellId,cellPointIds);
83 surface->GetPoint(cellPointIds->GetId(0),point);
84 surface->GetPoint(cellPointIds->GetId(1),point1);
85 surface->GetPoint(cellPointIds->GetId(2),point2);
86 averageTriangleArea += vtkTriangle::TriangleArea(point,point1,point2);
87 }
88 averageTriangleArea /= numberOfCells;
89
90 int numberOfPoints = surface->GetNumberOfPoints();
91 vtkIdList* cellIds = vtkIdList::New();
92 for (int pointId=0; pointId<numberOfPoints; pointId++)
93 {
94 surface->GetPoint(pointId,point);
95 cellIds->Initialize();
96 surface->GetPointCells(pointId,cellIds);
97 if (cellIds->GetNumberOfIds() != 4)
98 {
99 continue;
100 }
101 double localAverageTriangleArea = 0.0;
102 int numberOfCellIds = cellIds->GetNumberOfIds();
103 int i, j;
104 for (i=0; i<numberOfCellIds; i++)
105 {
106 vtkIdType cellId = cellIds->GetId(i);
107 cellPointIds->Initialize();
108 surface->GetCellPoints(cellId,cellPointIds);
109 surface->GetPoint(cellPointIds->GetId(0),point);
110 surface->GetPoint(cellPointIds->GetId(1),point1);
111 surface->GetPoint(cellPointIds->GetId(2),point2);
112 localAverageTriangleArea += vtkTriangle::TriangleArea(point,point1,point2);
113 }
114 localAverageTriangleArea /= numberOfCellIds;
115 if (localAverageTriangleArea < VTK_VMTK_DOUBLE_TOL)
116 {
117 continue;
118 }
119 if (localAverageTriangleArea > this->SizeFactor * averageTriangleArea)
120 {
121 continue;
122 }
123 for (i=0; i<numberOfCellIds; i++)
124 {
125 vtkIdType cellId = cellIds->GetId(i);
126 cellPointIds->Initialize();
127 surface->GetCellPoints(cellId,cellPointIds);
128 surface->GetPoint(cellPointIds->GetId(0),point);
129 surface->GetPoint(cellPointIds->GetId(1),point1);
130 surface->GetPoint(cellPointIds->GetId(2),point2);
131 double area = vtkTriangle::TriangleArea(point,point1,point2);
132 if (area > this->SizeFactor * averageTriangleArea)
133 {
134 continue;
135 }
136 int numberOfCellPointIds = cellPointIds->GetNumberOfIds();
137 for (j=0; j<numberOfCellPointIds; j++)
138 {
139 vtkIdType cellPointId = cellPointIds->GetId(j);
140 surface->GetPoints()->SetPoint(cellPointId,point);
141 }
142 }
143 }
144
145 vtkCleanPolyData* cleaner = vtkCleanPolyData::New();
146 cleaner->SetInputData(surface);
147
148 vtkTriangleFilter* triangleFilter2 = vtkTriangleFilter::New();
149 triangleFilter2->SetInputConnection(cleaner->GetOutputPort());
150 triangleFilter2->PassLinesOff();
151 triangleFilter2->PassVertsOff();
152 triangleFilter2->Update();
153
154 output->CopyStructure(triangleFilter2->GetOutput());
155 output->GetPointData()->PassData(triangleFilter2->GetOutput()->GetPointData());
156 output->GetCellData()->PassData(triangleFilter2->GetOutput()->GetCellData());
157 output->GetFieldData()->PassData(triangleFilter2->GetOutput()->GetFieldData());
158
159 triangleFilter->Delete();
160 triangleFilter2->Delete();
161 cleaner->Delete();
162 surface->Delete();
163 cellPointIds->Delete();
164 cellIds->Delete();
165
166 return 1;
167}
168
169void vtkvmtkPolyDataKiteRemovalFilter::PrintSelf(std::ostream& os, vtkIndent indent)
170{
171 this->Superclass::PrintSelf(os,indent);
172}
Removes small protrusions (kites) from a surface based on a SizeFactor parameter.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
#define VTK_VMTK_DOUBLE_TOL
vtkStandardNewMacro(vtkvmtkPolyDataKiteRemovalFilter)