VMTK
Loading...
Searching...
No Matches
vtkvmtkConstrainedLaplacianPolyDataFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkConstrainedLaplacianPolyDataFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:48:25 $
7Version: $Revision: 1.3 $
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 Portions of this code are covered under the ITK copyright.
17 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm
18 for details.
19
20 This software is distributed WITHOUT ANY WARRANTY; without even
21 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22 PURPOSE. See the above copyright notices for more information.
23
24=========================================================================*/
25
27
28#include "vtkvmtkConstants.h"
29#include "vtkbvgNeighborhoods.h"
30#include "vtkPolyData.h"
31#include "vtkPointData.h"
32#include "vtkCellData.h"
33#include "vtkCharArray.h"
34#include "vtkIdList.h"
35#include "vtkMath.h"
36#include "vtkObjectFactory.h"
37
38
40
50
59
61
63{
64 vtkPolyData *input;
65 vtkPolyData *output;
66 vtkPoints *newPoints;
67 vtkbvgNeighborhoods* neighborhoods;
68 vtkbvgNeighborhood *neighborhood;
69 vtkIdType n, i, j, step;
70 vtkIdType neighborhoodPointId;
71 double point[3], newPoint[3];
72 double neighborhoodPoint[3];
73 double laplacianPoint[3];
74 double displacement[3], displacementNorm;
75 double maxDisplacementNorm;
76 vtkIdType numberOfPoints;
77 vtkIdType numberOfNeighborhoodPoints;
78 vtkIdType numberOfConstrainedPoints;
79 vtkIdType constrainedStatus;
80 vtkIdType constrainedPointId;
81 vtkCharArray *constrainedStatusArray;
82
83 newPoints = vtkPoints::New();
84 constrainedStatusArray = vtkCharArray::New();
85 constrainedStatusArray->SetNumberOfComponents(1);
86
87 input = this->GetInput();
88 output = this->GetOutput();
89
90 newPoints->DeepCopy(input->GetPoints());
91
92 numberOfPoints = input->GetNumberOfPoints();
93
94 constrainedStatusArray->SetNumberOfTuples(numberOfPoints);
95 constrainedStatusArray->FillComponent(0,0.0);
96
97 if (this->ConstrainedPointIds)
98 {
99 numberOfConstrainedPoints = this->ConstrainedPointIds->GetNumberOfIds();
100 for (i=0; i<numberOfConstrainedPoints; i++)
101 {
102 constrainedPointId = this->ConstrainedPointIds->GetId(i);
103 constrainedStatusArray->SetValue(constrainedPointId,1);
104 }
105 }
106
107 output->SetPoints(newPoints);
108 output->SetVerts(input->GetVerts());
109 output->SetLines(input->GetLines());
110 output->SetPolys(input->GetPolys());
111 output->SetStrips(input->GetStrips());
112 output->GetPointData()->PassData(input->GetPointData());
113 output->GetCellData()->PassData(input->GetCellData());
114
115 neighborhoods = vtkbvgNeighborhoods::New();
116 neighborhoods->SetDataSet(input);
117 neighborhoods->SetNeighborhoodTypeToPolyDataManifoldNeighborhood();
118 neighborhoods->Build();
119
120 for (n=0; n<this->NumberOfIterations; n++)
121 {
122 maxDisplacementNorm = 0.0;
123 for (step=0; step<2; step++)
124 {
125 for (i=0; i<numberOfPoints; i++)
126 {
127 constrainedStatus = constrainedStatusArray->GetValue(i);
128 if (constrainedStatus == 1)
129 {
130 continue;
131 }
132
133 neighborhood = neighborhoods->GetNeighborhood(i);
134
135 if (neighborhood->GetIsBoundary() && !this->BoundarySmoothing)
136 {
137 continue;
138 }
139
140 newPoints->GetPoint(i,point);
141 laplacianPoint[0] = laplacianPoint[1] = laplacianPoint[2] = 0.0;
142 numberOfNeighborhoodPoints = neighborhood->GetNumberOfPoints();
143 for (j=0; j<numberOfNeighborhoodPoints; j++)
144 {
145 newPoints->GetPoint(neighborhood->GetPointId(j),neighborhoodPoint);
146 laplacianPoint[0] += neighborhoodPoint[0];
147 laplacianPoint[1] += neighborhoodPoint[1];
148 laplacianPoint[2] += neighborhoodPoint[2];
149 }
150 laplacianPoint[0] /= (double)numberOfNeighborhoodPoints;
151 laplacianPoint[1] /= (double)numberOfNeighborhoodPoints;
152 laplacianPoint[2] /= (double)numberOfNeighborhoodPoints;
153
154 displacement[0] = laplacianPoint[0] - point[0];
155 displacement[1] = laplacianPoint[1] - point[1];
156 displacement[2] = laplacianPoint[2] - point[2];
157
158 displacementNorm = vtkMath::Norm(displacement);
159 if (displacementNorm > maxDisplacementNorm)
160 {
161 maxDisplacementNorm = displacementNorm;
162 }
163
164 if (step == 0)
165 {
166 newPoint[0] = point[0] + this->RelaxationFactor * displacement[0];
167 newPoint[1] = point[1] + this->RelaxationFactor * displacement[1];
168 newPoint[2] = point[2] + this->RelaxationFactor * displacement[2];
169 newPoints->SetPoint(i,newPoint);
170 }
171 else if (step == 1)
172 {
173 for (j=0; j<numberOfNeighborhoodPoints; j++)
174 {
175 neighborhoodPointId = neighborhood->GetPointId(j);
176
177 if ((constrainedStatusArray->GetValue(neighborhoodPointId) == 1) || neighborhoods->GetNeighborhood(neighborhoodPointId)->GetIsBoundary())
178 {
179 continue;
180 }
181
182 newPoints->GetPoint(neighborhoodPointId,neighborhoodPoint);
183
184 newPoint[0] = neighborhoodPoint[0] - this->RelaxationFactor * displacement[0] / (double)numberOfNeighborhoodPoints;
185 newPoint[1] = neighborhoodPoint[1] - this->RelaxationFactor * displacement[1] / (double)numberOfNeighborhoodPoints;
186 newPoint[2] = neighborhoodPoint[2] - this->RelaxationFactor * displacement[2] / (double)numberOfNeighborhoodPoints;
187
188 newPoints->SetPoint(neighborhoodPointId,newPoint);
189 }
190 }
191 }
192 }
193
194 if (maxDisplacementNorm < this->Convergence)
195 {
196 break;
197 }
198 }
199
200 neighborhoods->Delete();
201 newPoints->Delete();
202 constrainedStatusArray->Delete();
203}
204
205void vtkvmtkConstrainedLaplacianPolyDataFilter::PrintSelf(std::ostream& os, vtkIndent indent)
206{
207 this->Superclass::PrintSelf(os,indent);
208}
209
Smooth a surface mesh by constraining the motion of selected point ids.
void PrintSelf(std::ostream &os, vtkIndent indent) override
#define VTK_VMTK_LARGE_INTEGER
vtkStandardNewMacro(vtkvmtkConstrainedLaplacianPolyDataFilter)
vtkCxxSetObjectMacro(vtkvmtkConstrainedLaplacianPolyDataFilter, ConstrainedPointIds, vtkIdList)