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
98 {
100 for (i=0; i<numberOfConstrainedPoints; i++)
101 {
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
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 {
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
195 {
196 break;
197 }
198 }
199
200 neighborhoods->Delete();
201 newPoints->Delete();
202 constrainedStatusArray->Delete();
203}