VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataStencilFlowFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataStencilFlowFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2005/11/15 17:39:25 $
7 Version: $Revision: 1.1 $
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 "vtkvmtkStencils.h"
24#include "vtkvmtkStencil.h"
25#include "vtkIdList.h"
26#include "vtkCell.h"
27#include "vtkCellLocator.h"
28#include "vtkPolyData.h"
29#include "vtkPointData.h"
30#include "vtkCellData.h"
31#include "vtkFieldData.h"
32#include "vtkMath.h"
33#include "vtkInformation.h"
34#include "vtkInformationVector.h"
35#include "vtkObjectFactory.h"
36
37
39
51
56
58{
59 if (this->Stencils)
60 {
61 this->Stencils->UnRegister(this);
62 this->Stencils = NULL;
63 }
64}
65
67 vtkInformation *vtkNotUsed(request),
68 vtkInformationVector **inputVector,
69 vtkInformationVector *outputVector)
70{
71 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
72 vtkInformation *outInfo = outputVector->GetInformationObject(0);
73
74 vtkPolyData *input = vtkPolyData::SafeDownCast(
75 inInfo->Get(vtkDataObject::DATA_OBJECT()));
76 vtkPolyData *output = vtkPolyData::SafeDownCast(
77 outInfo->Get(vtkDataObject::DATA_OBJECT()));
78
79 output->CopyStructure(input);
80 output->GetPointData()->PassData(input->GetPointData());
81 output->GetCellData()->PassData(input->GetCellData());
82 output->GetFieldData()->PassData(input->GetFieldData());
83
84 if (this->Stencils)
85 {
86 this->ReleaseStencils();
87 }
88
90 this->Stencils->SetItemType(this->StencilType);
91 this->Stencils->SetDataSet(input);
92 this->Stencils->ReallocateOnBuildOff();
93 this->Stencils->WeightScalingOn();
94
95 vtkCellLocator *cellLocator = NULL;
96 double* weights = NULL;
97 if (this->ConstrainOnSurface)
98 {
99 weights = new double[input->GetMaxCellSize()];
100 cellLocator = vtkCellLocator::New();
101 cellLocator->SetDataSet(input);
102 cellLocator->BuildLocator();
103 }
104
105 vtkIdType numberOfPoints = input->GetNumberOfPoints();
106
107 double displacement[3], stencilPoint[3], weight;
108 double point[3], newPoint[3];
109
110 vtkIdList* constrainCellIds = vtkIdList::New();
111 constrainCellIds->SetNumberOfIds(input->GetNumberOfPoints());
112 for (vtkIdType pointId=0; pointId<numberOfPoints; pointId++)
113 {
114 constrainCellIds->SetId(pointId,0);
115 }
116
117 for (int iteration=0; iteration<this->NumberOfIterations; iteration++)
118 {
119 this->Stencils->Build();
120 for (vtkIdType pointId=0; pointId<numberOfPoints; pointId++)
121 {
122 vtkvmtkStencil* stencil = this->Stencils->GetStencil(pointId);
123 if (stencil->GetIsBoundary() && (!this->ProcessBoundary))
124 {
125 continue;
126 }
127 displacement[0] = displacement[1] = displacement[2] = 0.0;
128 int numberOfStencilPoints = stencil->GetNumberOfPoints();
129 for (int j=0; j<numberOfStencilPoints; j++)
130 {
131 output->GetPoint(stencil->GetPointId(j),stencilPoint);
132 weight = stencil->GetWeight(j);
133 displacement[0] += weight * stencilPoint[0];
134 displacement[1] += weight * stencilPoint[1];
135 displacement[2] += weight * stencilPoint[2];
136 }
137 weight = stencil->GetCenterWeight();
138 output->GetPoint(pointId,point);
139 displacement[0] -= weight * point[0];
140 displacement[1] -= weight * point[1];
141 displacement[2] -= weight * point[2];
142
143 if (vtkMath::Norm(displacement) > this->MaximumDisplacement)
144 {
145 vtkMath::Normalize(displacement);
146 displacement[0] *= this->MaximumDisplacement;
147 displacement[1] *= this->MaximumDisplacement;
148 displacement[2] *= this->MaximumDisplacement;
149 }
150
151 newPoint[0] = point[0] + this->RelaxationFactor * displacement[0];
152 newPoint[1] = point[1] + this->RelaxationFactor * displacement[1];
153 newPoint[2] = point[2] + this->RelaxationFactor * displacement[2];
154
155 if (this->ConstrainOnSurface)
156 {
157 double closestPoint[3];
158 vtkIdType cellId;
159 int subId;
160 double dist2, pcoords[3];
161 if (input->GetCell(constrainCellIds->GetId(pointId))->EvaluatePosition(newPoint,closestPoint,subId,pcoords,dist2,weights)==0)
162 {
163 cellLocator->FindClosestPoint(newPoint,closestPoint,cellId,subId,dist2);
164 constrainCellIds->SetId(pointId,cellId);
165 }
166 newPoint[0] = closestPoint[0];
167 newPoint[1] = closestPoint[1];
168 newPoint[2] = closestPoint[2];
169 }
170
171 output->GetPoints()->SetPoint(pointId,newPoint);
172 }
173 }
174
175 constrainCellIds->Delete();
176
177 if (weights)
178 {
179 delete[] weights;
180 weights = NULL;
181 }
182
183 if (cellLocator)
184 {
185 cellLocator->Delete();
186 cellLocator = NULL;
187 }
188
189 return 1;
190}
vtkIdType GetPointId(vtkIdType i)
virtual bool GetIsBoundary()
Displace points of a surface with an iterative algorithm based on stencil weighting.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Serves as an abstract base for a weighting scheme applied to a single point's neighborhood of a data ...
double GetCenterWeight()
double GetWeight(vtkIdType i)
static vtkvmtkStencils * New()
@ VTK_VMTK_UMBRELLA_STENCIL
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkPolyDataStencilFlowFilter)