24#include "vtkPolyDataNormals.h"
25#include "vtkPointData.h"
26#include "vtkDoubleArray.h"
28#include "vtkInformation.h"
29#include "vtkInformationVector.h"
30#include "vtkObjectFactory.h"
31#include "vtkVersion.h"
46#include "vtkCurvatures.h"
49 vtkInformation *vtkNotUsed(request),
50 vtkInformationVector **inputVector,
51 vtkInformationVector *outputVector)
53 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
54 vtkInformation *outInfo = outputVector->GetInformationObject(0);
56 vtkPolyData *input = vtkPolyData::SafeDownCast(
57 inInfo->Get(vtkDataObject::DATA_OBJECT()));
58 vtkPolyData *output = vtkPolyData::SafeDownCast(
59 outInfo->Get(vtkDataObject::DATA_OBJECT()));
61 vtkPolyData* surface = vtkPolyData::New();
62 surface->DeepCopy(input);
64 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
65 normalsFilter->SetInput(surface);
66 normalsFilter->FlipNormalsOff();
67 normalsFilter->ConsistencyOn();
68 normalsFilter->ComputePointNormalsOn();
69 normalsFilter->ComputeCellNormalsOn();
71 vtkCurvatures* curvaturesFilter = vtkCurvatures::New();
72 curvaturesFilter->SetInput(surface);
78 int numberOfPoints = surface->GetNumberOfPoints();
80 vtkPoints* newPoints = vtkPoints::New();
81 newPoints->SetNumberOfPoints(numberOfPoints);
83 vtkDoubleArray* meanCurvatureArray = vtkDoubleArray::New();
84 vtkDoubleArray* gaussianCurvatureArray = vtkDoubleArray::New();
88 int numberOfIterations = 1000;
90 for (
int n=0; n<numberOfIterations; n++)
93 curvaturesFilter->SetCurvatureTypeToMean();
94 curvaturesFilter->Update();
95 meanCurvatureArray->DeepCopy(curvaturesFilter->GetOutput()->GetPointData()->GetScalars());
96 curvaturesFilter->SetCurvatureTypeToGaussian();
97 curvaturesFilter->Update();
98 gaussianCurvatureArray->DeepCopy(curvaturesFilter->GetOutput()->GetPointData()->GetScalars());
99 normalsFilter->Update();
100 vtkDataArray* normals = normalsFilter->GetOutput()->GetPointData()->GetNormals();
102 newPoints->DeepCopy(surface->GetPoints());
104 double minTriangleArea = 1E8;
106 for (
int i=0; i<numberOfPoints; i++)
109 neighborhood->
Build();
117 surface->GetPoint(i,point);
119 if (surface->GetPointData()->GetArray(
"Clamp")->GetTuple1(i) > 0.5)
121 newPoints->SetPoint(i,point);
125 double meanCurvature = meanCurvatureArray->GetTuple1(i);
126 double gaussianCurvature = gaussianCurvatureArray->GetTuple1(i);
128 double laplaceBeltramiH = 0.0;
131 double weight = 1.0 / double(numberOfNeighborhoodPoints);
132 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
134 double neighborMeanCurvature = meanCurvatureArray->GetTuple1(neighborhood->
GetPointId(j));
135 laplaceBeltramiH += weight * (neighborMeanCurvature - meanCurvature);
138 double point1[3], point2[3];
141 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
143 surface->GetPoint(neighborhood->
GetPointId(j),point1);
144 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
146 area += triangleArea;
147 if (triangleArea < minTriangleArea)
149 minTriangleArea = triangleArea;
154 normals->GetTuple(i,normal);
157 newPoint[0] = point[0];
158 newPoint[1] = point[1];
159 newPoint[2] = point[2];
161 double f = laplaceBeltramiH - 2.0 * meanCurvature * (meanCurvature*meanCurvature - gaussianCurvature);
163 if (meanCurvature*meanCurvature - gaussianCurvature < 0.0)
165 f = laplaceBeltramiH;
172 deltaT = minTriangleArea*minTriangleArea / 1.0;
175 newPoint[0] += deltaT * f * normal[0];
176 newPoint[1] += deltaT * f * normal[1];
177 newPoint[2] += deltaT * f * normal[2];
179 newPoints->SetPoint(i,newPoint);
182 std::cout<<deltaT<<endl;
184 surface->GetPoints()->DeepCopy(newPoints);
187 output->DeepCopy(surface);
189 curvaturesFilter->Delete();
190 normalsFilter->Delete();
191 neighborhood->Delete();
192 meanCurvatureArray->Delete();
193 gaussianCurvatureArray->Delete();
201 vtkInformation *vtkNotUsed(request),
202 vtkInformationVector **inputVector,
203 vtkInformationVector *outputVector)
205 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
206 vtkInformation *outInfo = outputVector->GetInformationObject(0);
208 vtkPolyData *input = vtkPolyData::SafeDownCast(
209 inInfo->Get(vtkDataObject::DATA_OBJECT()));
210 vtkPolyData *output = vtkPolyData::SafeDownCast(
211 outInfo->Get(vtkDataObject::DATA_OBJECT()));
213 vtkPolyData* surface = vtkPolyData::New();
214 surface->DeepCopy(input);
216 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
217 normalsFilter->SetInputData(surface);
218 normalsFilter->FlipNormalsOff();
219 normalsFilter->ConsistencyOn();
220 normalsFilter->ComputePointNormalsOn();
221 normalsFilter->ComputeCellNormalsOn();
223 vtkCurvatures* curvaturesFilter = vtkCurvatures::New();
224 curvaturesFilter->SetInputData(surface);
230 int numberOfPoints = surface->GetNumberOfPoints();
232 vtkPoints* newPoints = vtkPoints::New();
233 newPoints->SetNumberOfPoints(numberOfPoints);
235 vtkDoubleArray* meanCurvatureArray = vtkDoubleArray::New();
239 int numberOfIterations = 100;
241 for (
int n=0; n<numberOfIterations; n++)
244 curvaturesFilter->SetCurvatureTypeToMean();
245 curvaturesFilter->Update();
246 meanCurvatureArray->DeepCopy(curvaturesFilter->GetOutput()->GetPointData()->GetScalars());
247 normalsFilter->Update();
248 vtkDataArray* normals = normalsFilter->GetOutput()->GetPointData()->GetNormals();
250 newPoints->DeepCopy(surface->GetPoints());
252 double minTriangleArea = 1E8;
254 for (
int i=0; i<numberOfPoints; i++)
257 neighborhood->
Build();
265 surface->GetPoint(i,point);
267 if (surface->GetPointData()->GetArray(
"Clamp")->GetTuple1(i) > 0.5)
269 newPoints->SetPoint(i,point);
273 double meanCurvature = meanCurvatureArray->GetTuple1(i);
275 double laplaceH = 0.0;
277 double neighborPoint[3];
279 laplace[0] = laplace[1] = laplace[2] = 0.0;
281 double weight = 1.0 / double(numberOfNeighborhoodPoints);
282 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
284 double neighborMeanCurvature = meanCurvatureArray->GetTuple1(neighborhood->
GetPointId(j));
285 laplaceH += weight * (neighborMeanCurvature - meanCurvature);
286 surface->GetPoint(neighborhood->
GetPointId(j),neighborPoint);
287 laplace[0] += weight * (neighborPoint[0] - point[0]);
288 laplace[1] += weight * (neighborPoint[1] - point[1]);
289 laplace[2] += weight * (neighborPoint[2] - point[2]);
292 double point1[3], point2[3];
295 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
297 surface->GetPoint(neighborhood->
GetPointId(j),point1);
298 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
300 area += triangleArea;
301 if (triangleArea < minTriangleArea)
303 minTriangleArea = triangleArea;
308 normals->GetTuple(i,normal);
311 newPoint[0] = point[0];
312 newPoint[1] = point[1];
313 newPoint[2] = point[2];
315 deltaT = minTriangleArea / 10.0;
325 newPoint[0] += deltaT * (alpha * laplaceH * normal[0] + beta * laplace[0]);
326 newPoint[1] += deltaT * (alpha * laplaceH * normal[1] + beta * laplace[1]);
327 newPoint[2] += deltaT * (alpha * laplaceH * normal[2] + beta * laplace[2]);
329 newPoints->SetPoint(i,newPoint);
332 std::cout<<deltaT<<endl;
334 surface->GetPoints()->DeepCopy(newPoints);
337 output->DeepCopy(surface);
339 curvaturesFilter->Delete();
340 normalsFilter->Delete();
341 neighborhood->Delete();
342 meanCurvatureArray->Delete();
350 vtkInformation *vtkNotUsed(request),
351 vtkInformationVector **inputVector,
352 vtkInformationVector *outputVector)
354 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
355 vtkInformation *outInfo = outputVector->GetInformationObject(0);
357 vtkPolyData *input = vtkPolyData::SafeDownCast(
358 inInfo->Get(vtkDataObject::DATA_OBJECT()));
359 vtkPolyData *output = vtkPolyData::SafeDownCast(
360 outInfo->Get(vtkDataObject::DATA_OBJECT()));
362 vtkPolyData* surface = vtkPolyData::New();
363 surface->DeepCopy(input);
365 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
366 normalsFilter->SetInput(surface);
367 normalsFilter->FlipNormalsOff();
368 normalsFilter->ConsistencyOn();
369 normalsFilter->ComputePointNormalsOn();
370 normalsFilter->ComputeCellNormalsOn();
387 int numberOfPoints = surface->GetNumberOfPoints();
389 vtkPoints* newPoints = vtkPoints::New();
390 newPoints->SetNumberOfPoints(numberOfPoints);
392 vtkDoubleArray* meanCurvatureArray = vtkDoubleArray::New();
393 meanCurvatureArray->SetNumberOfTuples(numberOfPoints);
397 int numberOfIterations = 300;
399 for (
int n=0; n<numberOfIterations; n++)
402 normalsFilter->Update();
403 vtkDataArray* normals = normalsFilter->GetOutput()->GetPointData()->GetNormals();
405 newPoints->DeepCopy(surface->GetPoints());
407 double minTriangleArea = 1E8;
409 for (
int i=0; i<numberOfPoints; i++)
412 neighborhood->
Build();
420 normals->GetTuple(i,normal);
423 surface->GetPoint(i,point);
425 double laplaceBeltrami[3];
426 laplaceBeltrami[0] = 0.0;
427 laplaceBeltrami[1] = 0.0;
428 laplaceBeltrami[2] = 0.0;
430 double point0[3], point1[3], point2[3];
432 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
434 surface->GetPoint(neighborhood->
GetPointId((j-1+numberOfNeighborhoodPoints)%numberOfNeighborhoodPoints),point0);
435 surface->GetPoint(neighborhood->
GetPointId(j),point1);
436 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
438 laplaceBeltrami[0] += weight * (point1[0] - point[0]);
439 laplaceBeltrami[1] += weight * (point1[1] - point[1]);
440 laplaceBeltrami[2] += weight * (point1[2] - point[2]);
445 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
447 surface->GetPoint(neighborhood->
GetPointId(j),point1);
448 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
450 area += triangleArea;
451 if (triangleArea < minTriangleArea)
453 minTriangleArea = triangleArea;
457 laplaceBeltrami[0] *= 3.0 / area;
458 laplaceBeltrami[1] *= 3.0 / area;
459 laplaceBeltrami[2] *= 3.0 / area;
461 double meanCurvature = 0.5 * vtkMath::Dot(normal,laplaceBeltrami);
463 meanCurvatureArray->SetTuple1(i,meanCurvature);
466 for (
int i=0; i<numberOfPoints; i++)
469 neighborhood->
Build();
477 normals->GetTuple(i,normal);
480 surface->GetPoint(i,point);
482 double meanCurvature = meanCurvatureArray->GetTuple1(i);
484 double laplaceBeltramiH = 0.0;
486 double point0[3], point1[3], point2[3];
488 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
490 surface->GetPoint(neighborhood->
GetPointId((j-1+numberOfNeighborhoodPoints)%numberOfNeighborhoodPoints),point0);
491 surface->GetPoint(neighborhood->
GetPointId(j),point1);
492 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
494 double neighborMeanCurvature = meanCurvatureArray->GetTuple1(neighborhood->
GetPointId(j));
495 laplaceBeltramiH += weight * (neighborMeanCurvature - meanCurvature);
499 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
501 surface->GetPoint(neighborhood->
GetPointId(j),point1);
502 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
506 laplaceBeltramiH *= 3.0 / area;
509 newPoint[0] = point[0];
510 newPoint[1] = point[1];
511 newPoint[2] = point[2];
513 double normal1[3], normal2[3];
514 double angleSum = 0.0;
515 for (
int j=0; j<numberOfNeighborhoodPoints; j++)
517 surface->GetPoint(neighborhood->
GetPointId(j),point1);
518 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
519 normal1[0] = point1[0] - point[0];
520 normal1[1] = point1[1] - point[1];
521 normal1[2] = point1[2] - point[2];
522 vtkMath::Normalize(normal1);
523 normal2[0] = point2[0] - point[0];
524 normal2[1] = point2[1] - point[1];
525 normal2[2] = point2[2] - point[2];
526 vtkMath::Normalize(normal2);
529 double gaussianCurvature = 3.0 / area * (2.0 * vtkMath::Pi() - angleSum);
531 double f = - laplaceBeltramiH - 2.0 * meanCurvature * (meanCurvature*meanCurvature - gaussianCurvature);
533 if (meanCurvature*meanCurvature - gaussianCurvature < 0.0)
535 f = - laplaceBeltramiH;
541 deltaT = minTriangleArea*minTriangleArea / 10.0;
543 newPoint[0] += deltaT * f * normal[0];
544 newPoint[1] += deltaT * f * normal[1];
545 newPoint[2] += deltaT * f * normal[2];
547 newPoints->SetPoint(i,newPoint);
550 std::cout<<deltaT<<endl;
552 surface->GetPoints()->DeepCopy(newPoints);
555 output->DeepCopy(surface);
557 normalsFilter->Delete();
558 neighborhood->Delete();
559 meanCurvatureArray->Delete();
568 this->Superclass::PrintSelf(os,indent);
virtual void SetDataSetPointId(vtkIdType)
void SetDataSet(vtkDataSet *dataSet)
static double AngleBetweenNormals(double normal0[3], double normal1[3])
static double Cotangent(double point0[3], double point1[3], double point2[3])
static double TriangleArea(double point0[3], double point1[3], double point2[3])
vtkIdType GetPointId(vtkIdType i)
virtual bool GetIsBoundary()
vtkIdType GetNumberOfPoints()
Not implemented; smooths a surface via an elastic-forces method.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkvmtkPolyDataDiscreteElasticaFilter()
void PrintSelf(std::ostream &os, vtkIndent indent) override
~vtkvmtkPolyDataDiscreteElasticaFilter()
Apply a neighborhood to the points of a manifold surface.
virtual void Build() override
static vtkvmtkPolyDataManifoldNeighborhood * New()
vtkStandardNewMacro(vtkvmtkPolyDataDiscreteElasticaFilter)