VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataClampedSmoothingFilter Class Reference

Apply a laplacian or curvature based smoothing filter to a surface with particular points fixed in place. More...

#include <vtkvmtkPolyDataClampedSmoothingFilter.h>

Inheritance diagram for vtkvmtkPolyDataClampedSmoothingFilter:
[legend]
Collaboration diagram for vtkvmtkPolyDataClampedSmoothingFilter:
[legend]

Public Types

enum  { LAPLACIAN , CURVATURE_DIFFUSION }
typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataClampedSmoothingFilter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetSmoothingType (int)
virtual int GetSmoothingType ()
void SetSmoothingTypeToLaplacian ()
void SetSmoothingTypeToCurvatureDiffusion ()
virtual void SetNumberOfIterations (int)
virtual int GetNumberOfIterations ()
virtual void SetClamp (int)
virtual int GetClamp ()
virtual void ClampOn ()
virtual void ClampOff ()
virtual void SetClampThreshold (double)
virtual double GetClampThreshold ()
virtual void SetClampArrayName (const char *)
virtual char * GetClampArrayName ()
virtual void SetTimeStepFactor (double)
virtual double GetTimeStepFactor ()

Static Public Member Functions

static vtkvmtkPolyDataClampedSmoothingFilter * New ()
static int IsTypeOf (const char *type)
static vtkvmtkPolyDataClampedSmoothingFilter * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataClampedSmoothingFilter ()
 ~vtkvmtkPolyDataClampedSmoothingFilter ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void LaplacianIteration (vtkPolyData *surface)
void CurvatureDiffusionIteration (vtkPolyData *surface)
double ComputeTimeStep (vtkPolyData *surface)

Protected Attributes

int SmoothingType
int NumberOfIterations
int Clamp
double ClampThreshold
double TimeStepFactor
char * ClampArrayName

Detailed Description

Apply a laplacian or curvature based smoothing filter to a surface with particular points fixed in place.

vtkvmtkPolyDataClampedSmoothingFilter iteratively displaces the points of an input triangulated surface, either along the discrete Laplacian (umbrella) direction (SmoothingType == LAPLACIAN) or along the surface normal scaled by the local mean curvature (SmoothingType == CURVATURE_DIFFUSION, using vtkCurvatures and vtkPolyDataNormals internally), for NumberOfIterations iterations. At each iteration the (explicit-Euler) time step is computed from the smallest triangle area in the mesh (see ComputeTimeStep) scaled by TimeStepFactor, so that the scheme stays stable. Points whose value in the point data array named ClampArrayName exceeds ClampThreshold are left untouched when Clamp is on, which lets the caller pin down selected regions (e.g. inlet/outlet rings) while the rest of the surface is smoothed; points found to be on a mesh boundary are always left untouched. This is a lower-level building block used where surface smoothing must not move certain fixed points, unlike filters that smooth the whole surface uniformly.

See also
vtkvmtkPolyDataManifoldNeighborhood

Definition at line 45 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

Member Typedef Documentation

◆ Superclass

Definition at line 50 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

Member Enumeration Documentation

◆ anonymous enum

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataClampedSmoothingFilter()

◆ ~vtkvmtkPolyDataClampedSmoothingFilter()

vtkvmtkPolyDataClampedSmoothingFilter::~vtkvmtkPolyDataClampedSmoothingFilter ( )
protected

Definition at line 47 of file vtkvmtkPolyDataClampedSmoothingFilter.cxx.

48{
49 if (this->ClampArrayName)
50 {
51 delete[] this->ClampArrayName;
52 this->ClampArrayName = NULL;
53 }
54}

Member Function Documentation

◆ New()

vtkvmtkPolyDataClampedSmoothingFilter * vtkvmtkPolyDataClampedSmoothingFilter::New ( )
static

◆ IsTypeOf()

int vtkvmtkPolyDataClampedSmoothingFilter::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkPolyDataClampedSmoothingFilter::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkPolyDataClampedSmoothingFilter * vtkvmtkPolyDataClampedSmoothingFilter::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataClampedSmoothingFilter::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataClampedSmoothingFilter * vtkvmtkPolyDataClampedSmoothingFilter::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkPolyDataClampedSmoothingFilter::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 288 of file vtkvmtkPolyDataClampedSmoothingFilter.cxx.

289{
290 this->Superclass::PrintSelf(os,indent);
291}

◆ SetSmoothingType()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::SetSmoothingType ( int )
virtual

Set/get the smoothing scheme applied at each iteration: LAPLACIAN (the default) displaces each free point towards the unweighted average of its one-ring neighbors; CURVATURE_DIFFUSION displaces each free point along its surface normal, driven by the local variation of the mean curvature (a curvature-diffusion / mean-curvature-flow-like scheme).

◆ GetSmoothingType()

virtual int vtkvmtkPolyDataClampedSmoothingFilter::GetSmoothingType ( )
virtual

Set/get the smoothing scheme applied at each iteration: LAPLACIAN (the default) displaces each free point towards the unweighted average of its one-ring neighbors; CURVATURE_DIFFUSION displaces each free point along its surface normal, driven by the local variation of the mean curvature (a curvature-diffusion / mean-curvature-flow-like scheme).

◆ SetSmoothingTypeToLaplacian()

void vtkvmtkPolyDataClampedSmoothingFilter::SetSmoothingTypeToLaplacian ( )
inline

Set/get the smoothing scheme applied at each iteration: LAPLACIAN (the default) displaces each free point towards the unweighted average of its one-ring neighbors; CURVATURE_DIFFUSION displaces each free point along its surface normal, driven by the local variation of the mean curvature (a curvature-diffusion / mean-curvature-flow-like scheme).

Definition at line 62 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ SetSmoothingTypeToCurvatureDiffusion()

void vtkvmtkPolyDataClampedSmoothingFilter::SetSmoothingTypeToCurvatureDiffusion ( )
inline

Set/get the smoothing scheme applied at each iteration: LAPLACIAN (the default) displaces each free point towards the unweighted average of its one-ring neighbors; CURVATURE_DIFFUSION displaces each free point along its surface normal, driven by the local variation of the mean curvature (a curvature-diffusion / mean-curvature-flow-like scheme).

Definition at line 64 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ SetNumberOfIterations()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::SetNumberOfIterations ( int )
virtual

Set/get the number of smoothing iterations to perform. Default: 100.

◆ GetNumberOfIterations()

virtual int vtkvmtkPolyDataClampedSmoothingFilter::GetNumberOfIterations ( )
virtual

Set/get the number of smoothing iterations to perform. Default: 100.

◆ SetClamp()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::SetClamp ( int )
virtual

Toggle whether points are clamped (excluded from smoothing) based on ClampArrayName / ClampThreshold. When off (default), every non-boundary point is free to move.

◆ GetClamp()

virtual int vtkvmtkPolyDataClampedSmoothingFilter::GetClamp ( )
virtual

Toggle whether points are clamped (excluded from smoothing) based on ClampArrayName / ClampThreshold. When off (default), every non-boundary point is free to move.

◆ ClampOn()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::ClampOn ( )
virtual

Toggle whether points are clamped (excluded from smoothing) based on ClampArrayName / ClampThreshold. When off (default), every non-boundary point is free to move.

◆ ClampOff()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::ClampOff ( )
virtual

Toggle whether points are clamped (excluded from smoothing) based on ClampArrayName / ClampThreshold. When off (default), every non-boundary point is free to move.

◆ SetClampThreshold()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::SetClampThreshold ( double )
virtual

Set/get the threshold applied to the ClampArrayName point data array: points whose value in that array is greater than ClampThreshold are held fixed when Clamp is on. Default: 0.0.

◆ GetClampThreshold()

virtual double vtkvmtkPolyDataClampedSmoothingFilter::GetClampThreshold ( )
virtual

Set/get the threshold applied to the ClampArrayName point data array: points whose value in that array is greater than ClampThreshold are held fixed when Clamp is on. Default: 0.0.

◆ SetClampArrayName()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::SetClampArrayName ( const char * )
virtual

Set/get the name of the point data scalar array read to decide, together with ClampThreshold, which points are held fixed while Clamp is on. Required (and must exist on the input) whenever Clamp is on. Default: NULL.

◆ GetClampArrayName()

virtual char * vtkvmtkPolyDataClampedSmoothingFilter::GetClampArrayName ( )
virtual

Set/get the name of the point data scalar array read to decide, together with ClampThreshold, which points are held fixed while Clamp is on. Required (and must exist on the input) whenever Clamp is on. Default: NULL.

◆ SetTimeStepFactor()

virtual void vtkvmtkPolyDataClampedSmoothingFilter::SetTimeStepFactor ( double )
virtual

Set/get the factor multiplying the per-iteration time step (itself derived from the smallest triangle area in the mesh, see ComputeTimeStep) used to advance point positions. Larger values smooth faster but risk instability/mesh folding; smaller values are safer but slower. Default: 1E-1.

◆ GetTimeStepFactor()

virtual double vtkvmtkPolyDataClampedSmoothingFilter::GetTimeStepFactor ( )
virtual

Set/get the factor multiplying the per-iteration time step (itself derived from the smallest triangle area in the mesh, see ComputeTimeStep) used to advance point positions. Larger values smooth faster but risk instability/mesh folding; smaller values are safer but slower. Default: 1E-1.

◆ RequestData()

int vtkvmtkPolyDataClampedSmoothingFilter::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotectedvirtual

Definition at line 233 of file vtkvmtkPolyDataClampedSmoothingFilter.cxx.

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}

◆ LaplacianIteration()

void vtkvmtkPolyDataClampedSmoothingFilter::LaplacianIteration ( vtkPolyData * surface)
protected

Definition at line 88 of file vtkvmtkPolyDataClampedSmoothingFilter.cxx.

89{
90 vtkDataArray* clampArray = surface->GetPointData()->GetArray(this->ClampArrayName);
91
92 vtkvmtkPolyDataManifoldNeighborhood* neighborhood = vtkvmtkPolyDataManifoldNeighborhood::New();
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}
virtual void SetDataSetPointId(vtkIdType)
void SetDataSet(vtkDataSet *dataSet)
vtkIdType GetPointId(vtkIdType i)
virtual bool GetIsBoundary()
static vtkvmtkPolyDataManifoldNeighborhood * New()

◆ CurvatureDiffusionIteration()

void vtkvmtkPolyDataClampedSmoothingFilter::CurvatureDiffusionIteration ( vtkPolyData * surface)
protected

Definition at line 151 of file vtkvmtkPolyDataClampedSmoothingFilter.cxx.

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
171 vtkvmtkPolyDataManifoldNeighborhood* neighborhood = vtkvmtkPolyDataManifoldNeighborhood::New();
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}

◆ ComputeTimeStep()

double vtkvmtkPolyDataClampedSmoothingFilter::ComputeTimeStep ( vtkPolyData * surface)
protected

Definition at line 56 of file vtkvmtkPolyDataClampedSmoothingFilter.cxx.

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}
static double TriangleArea(double point0[3], double point1[3], double point2[3])

Member Data Documentation

◆ SmoothingType

int vtkvmtkPolyDataClampedSmoothingFilter::SmoothingType
protected

Definition at line 132 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ NumberOfIterations

int vtkvmtkPolyDataClampedSmoothingFilter::NumberOfIterations
protected

Definition at line 133 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ Clamp

int vtkvmtkPolyDataClampedSmoothingFilter::Clamp
protected

Definition at line 134 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ ClampThreshold

double vtkvmtkPolyDataClampedSmoothingFilter::ClampThreshold
protected

Definition at line 135 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ TimeStepFactor

double vtkvmtkPolyDataClampedSmoothingFilter::TimeStepFactor
protected

Definition at line 136 of file vtkvmtkPolyDataClampedSmoothingFilter.h.

◆ ClampArrayName

char* vtkvmtkPolyDataClampedSmoothingFilter::ClampArrayName
protected

Definition at line 138 of file vtkvmtkPolyDataClampedSmoothingFilter.h.


The documentation for this class was generated from the following files: