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;
83 newPoints = vtkPoints::New();
84 constrainedStatusArray = vtkCharArray::New();
85 constrainedStatusArray->SetNumberOfComponents(1);
87 input = this->GetInput();
88 output = this->GetOutput();
90 newPoints->DeepCopy(input->GetPoints());
92 numberOfPoints = input->GetNumberOfPoints();
94 constrainedStatusArray->SetNumberOfTuples(numberOfPoints);
95 constrainedStatusArray->FillComponent(0,0.0);
100 for (i=0; i<numberOfConstrainedPoints; i++)
103 constrainedStatusArray->SetValue(constrainedPointId,1);
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());
115 neighborhoods = vtkbvgNeighborhoods::New();
116 neighborhoods->SetDataSet(input);
117 neighborhoods->SetNeighborhoodTypeToPolyDataManifoldNeighborhood();
118 neighborhoods->Build();
122 maxDisplacementNorm = 0.0;
123 for (step=0; step<2; step++)
125 for (i=0; i<numberOfPoints; i++)
127 constrainedStatus = constrainedStatusArray->GetValue(i);
128 if (constrainedStatus == 1)
133 neighborhood = neighborhoods->GetNeighborhood(i);
135 if (neighborhood->GetIsBoundary() && !this->BoundarySmoothing)
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++)
145 newPoints->GetPoint(neighborhood->GetPointId(j),neighborhoodPoint);
146 laplacianPoint[0] += neighborhoodPoint[0];
147 laplacianPoint[1] += neighborhoodPoint[1];
148 laplacianPoint[2] += neighborhoodPoint[2];
150 laplacianPoint[0] /= (double)numberOfNeighborhoodPoints;
151 laplacianPoint[1] /= (double)numberOfNeighborhoodPoints;
152 laplacianPoint[2] /= (double)numberOfNeighborhoodPoints;
154 displacement[0] = laplacianPoint[0] - point[0];
155 displacement[1] = laplacianPoint[1] - point[1];
156 displacement[2] = laplacianPoint[2] - point[2];
158 displacementNorm = vtkMath::Norm(displacement);
159 if (displacementNorm > maxDisplacementNorm)
161 maxDisplacementNorm = displacementNorm;
169 newPoints->SetPoint(i,newPoint);
173 for (j=0; j<numberOfNeighborhoodPoints; j++)
175 neighborhoodPointId = neighborhood->GetPointId(j);
177 if ((constrainedStatusArray->GetValue(neighborhoodPointId) == 1) || neighborhoods->GetNeighborhood(neighborhoodPointId)->GetIsBoundary())
182 newPoints->GetPoint(neighborhoodPointId,neighborhoodPoint);
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;
188 newPoints->SetPoint(neighborhoodPointId,newPoint);
200 neighborhoods->Delete();
202 constrainedStatusArray->Delete();