VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataClampedSmoothingFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataClampedSmoothingFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.5 $
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
24#include "vtkCurvatures.h"
25#include "vtkPolyDataNormals.h"
26#include "vtkPointData.h"
27#include "vtkDoubleArray.h"
28#include "vtkvmtkMath.h"
29#include "vtkInformation.h"
30#include "vtkInformationVector.h"
31#include "vtkObjectFactory.h"
32#include "vtkVersion.h"
33
34
36
46
55
57{
58 int numberOfCells = surface->GetNumberOfCells();
59 vtkIdType npts;
60 const vtkIdType *pts;
61 double point0[3], point1[3], point2[3];
62 double minTriangleArea = 1E20;
63 for (int i=0; i<numberOfCells; i++)
64 {
65 surface->GetCellPoints(i,npts,pts);
66 if (npts < 3)
67 {
68 continue;
69 }
70 else if (npts > 3)
71 {
72 vtkErrorMacro(<<"Not triangle");
73 return 0.0;
74 }
75 surface->GetPoint(pts[0],point0);
76 surface->GetPoint(pts[1],point1);
77 surface->GetPoint(pts[2],point2);
78 double triangleArea = vtkvmtkMath::TriangleArea(point0,point1,point2);
79 if (triangleArea < minTriangleArea)
80 {
81 minTriangleArea = triangleArea;
82 }
83 }
84
85 return this->TimeStepFactor * minTriangleArea;
86}
87
89{
90 vtkDataArray* clampArray = surface->GetPointData()->GetArray(this->ClampArrayName);
91
93 neighborhood->SetDataSet(surface);
94
95 int numberOfPoints = surface->GetNumberOfPoints();
96
97 vtkPoints* newPoints = vtkPoints::New();
98 newPoints->DeepCopy(surface->GetPoints());
99
100 double deltaT = this->ComputeTimeStep(surface);
101
102 for (int i=0; i<numberOfPoints; i++)
103 {
104 if (clampArray->GetTuple1(i) > this->ClampThreshold)
105 {
106 continue;
107 }
108
109 neighborhood->SetDataSetPointId(i);
110 neighborhood->Build();
111
112 if (neighborhood->GetIsBoundary())
113 {
114 continue;
115 }
116
117 double point[3];
118 surface->GetPoint(i,point);
119
120 double neighborPoint[3];
121 double laplace[3];
122 laplace[0] = laplace[1] = laplace[2] = 0.0;
123 int numberOfNeighborhoodPoints = neighborhood->GetNumberOfPoints();
124 double weight = 1.0 / double(numberOfNeighborhoodPoints);
125 for (int j=0; j<numberOfNeighborhoodPoints; j++)
126 {
127 surface->GetPoint(neighborhood->GetPointId(j),neighborPoint);
128 laplace[0] += weight * (neighborPoint[0] - point[0]);
129 laplace[1] += weight * (neighborPoint[1] - point[1]);
130 laplace[2] += weight * (neighborPoint[2] - point[2]);
131 }
132
133 double newPoint[3];
134 newPoint[0] = point[0];
135 newPoint[1] = point[1];
136 newPoint[2] = point[2];
137
138 newPoint[0] += deltaT * laplace[0];
139 newPoint[1] += deltaT * laplace[1];
140 newPoint[2] += deltaT * laplace[2];
141
142 newPoints->SetPoint(i,newPoint);
143 }
144
145 surface->GetPoints()->DeepCopy(newPoints);
146
147 neighborhood->Delete();
148 newPoints->Delete();
149}
150
152{
153 vtkDataArray* clampArray = surface->GetPointData()->GetArray(this->ClampArrayName);
154
155 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
156 normalsFilter->SetInputData(surface);
157 normalsFilter->FlipNormalsOff();
158 normalsFilter->ConsistencyOn();
159 normalsFilter->ComputePointNormalsOn();
160 normalsFilter->ComputeCellNormalsOn();
161 normalsFilter->Update();
162 vtkDataArray* normals = normalsFilter->GetOutput()->GetPointData()->GetNormals();
163
164 vtkCurvatures* curvaturesFilter = vtkCurvatures::New();
165 curvaturesFilter->SetInputData(surface);
166// curvaturesFilter->InvertMeanCurvatureOn();
167 curvaturesFilter->SetCurvatureTypeToMean();
168 curvaturesFilter->Update();
169 vtkDataArray* meanCurvatureArray = curvaturesFilter->GetOutput()->GetPointData()->GetScalars();
170
172 neighborhood->SetDataSet(surface);
173
174 int numberOfPoints = surface->GetNumberOfPoints();
175
176 vtkPoints* newPoints = vtkPoints::New();
177 newPoints->DeepCopy(surface->GetPoints());
178
179 double deltaT = this->ComputeTimeStep(surface);
180
181 for (int i=0; i<numberOfPoints; i++)
182 {
183 if (clampArray->GetTuple1(i) > this->ClampThreshold)
184 {
185 continue;
186 }
187
188 neighborhood->SetDataSetPointId(i);
189 neighborhood->Build();
190
191 if (neighborhood->GetIsBoundary())
192 {
193 continue;
194 }
195
196 double point[3];
197 surface->GetPoint(i,point);
198
199 double meanCurvature = meanCurvatureArray->GetTuple1(i);
200
201 double laplaceH = 0.0;
202 int numberOfNeighborhoodPoints = neighborhood->GetNumberOfPoints();
203 double weight = 1.0 / double(numberOfNeighborhoodPoints);
204 for (int j=0; j<numberOfNeighborhoodPoints; j++)
205 {
206 double neighborMeanCurvature = meanCurvatureArray->GetTuple1(neighborhood->GetPointId(j));
207 laplaceH += weight * (neighborMeanCurvature - meanCurvature);
208 }
209
210 double normal[3];
211 normals->GetTuple(i,normal);
212
213 double newPoint[3];
214 newPoint[0] = point[0];
215 newPoint[1] = point[1];
216 newPoint[2] = point[2];
217
218 newPoint[0] += deltaT * laplaceH * normal[0];
219 newPoint[1] += deltaT * laplaceH * normal[1];
220 newPoint[2] += deltaT * laplaceH * normal[2];
221
222 newPoints->SetPoint(i,newPoint);
223 }
224
225 surface->GetPoints()->DeepCopy(newPoints);
226
227 normalsFilter->Delete();
228 curvaturesFilter->Delete();
229 neighborhood->Delete();
230 newPoints->Delete();
231}
232
234 vtkInformation *vtkNotUsed(request),
235 vtkInformationVector **inputVector,
236 vtkInformationVector *outputVector)
237{
238 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
239 vtkInformation *outInfo = outputVector->GetInformationObject(0);
240
241 vtkPolyData *input = vtkPolyData::SafeDownCast(
242 inInfo->Get(vtkDataObject::DATA_OBJECT()));
243 vtkPolyData *output = vtkPolyData::SafeDownCast(
244 outInfo->Get(vtkDataObject::DATA_OBJECT()));
245
246 vtkDataArray* clampArray = NULL;
247 if (this->Clamp)
248 {
249 if (!this->ClampArrayName)
250 {
251 vtkErrorMacro(<<"Clamp is on but ClampArrayName has not been specified");
252 return 1;
253 }
254 if (this->ClampArrayName)
255 {
256 clampArray = input->GetPointData()->GetArray(this->ClampArrayName);
257 }
258 if (!clampArray)
259 {
260 vtkErrorMacro(<<"ClampArray with name specified does not exist");
261 return 1;
262 }
263 }
264
265 vtkPolyData* surface = vtkPolyData::New();
266 surface->DeepCopy(input);
267 surface->BuildCells();
268
269 for (int n=0; n<this->NumberOfIterations; n++)
270 {
271 if (this->SmoothingType == LAPLACIAN)
272 {
273 this->LaplacianIteration(surface);
274 }
275 else if (this->SmoothingType == CURVATURE_DIFFUSION)
276 {
277 this->CurvatureDiffusionIteration(surface);
278 }
279 }
280
281 output->DeepCopy(surface);
282
283 surface->Delete();
284
285 return 1;
286}
287
288void vtkvmtkPolyDataClampedSmoothingFilter::PrintSelf(std::ostream& os, vtkIndent indent)
289{
290 this->Superclass::PrintSelf(os,indent);
291}
292
virtual void SetDataSetPointId(vtkIdType)
void SetDataSet(vtkDataSet *dataSet)
static double TriangleArea(double point0[3], double point1[3], double point2[3])
vtkIdType GetPointId(vtkIdType i)
virtual bool GetIsBoundary()
Apply a laplacian or curvature based smoothing filter to a surface with particular points fixed in pl...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
Apply a neighborhood to the points of a manifold surface.
static vtkvmtkPolyDataManifoldNeighborhood * New()
vtkStandardNewMacro(vtkvmtkPolyDataClampedSmoothingFilter)