204{
205 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
206 vtkInformation *outInfo = outputVector->GetInformationObject(0);
207
208 vtkPolyData *input = vtkPolyData::SafeDownCast(
209 inInfo->Get(vtkDataObject::DATA_OBJECT()));
210 vtkPolyData *output = vtkPolyData::SafeDownCast(
211 outInfo->Get(vtkDataObject::DATA_OBJECT()));
212
213 vtkPolyData* surface = vtkPolyData::New();
214 surface->DeepCopy(input);
215
216 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
217 normalsFilter->SetInputData(surface);
218 normalsFilter->FlipNormalsOff();
219 normalsFilter->ConsistencyOn();
220 normalsFilter->ComputePointNormalsOn();
221 normalsFilter->ComputeCellNormalsOn();
222
223 vtkCurvatures* curvaturesFilter = vtkCurvatures::New();
224 curvaturesFilter->SetInputData(surface);
225
226
229
230 int numberOfPoints = surface->GetNumberOfPoints();
231
232 vtkPoints* newPoints = vtkPoints::New();
233 newPoints->SetNumberOfPoints(numberOfPoints);
234
235 vtkDoubleArray* meanCurvatureArray = vtkDoubleArray::New();
236
237 double deltaT = 1.0;
238
239 int numberOfIterations = 100;
240
241 for (int n=0; n<numberOfIterations; n++)
242 {
243 surface->Modified();
244 curvaturesFilter->SetCurvatureTypeToMean();
245 curvaturesFilter->Update();
246 meanCurvatureArray->DeepCopy(curvaturesFilter->GetOutput()->GetPointData()->GetScalars());
247 normalsFilter->Update();
248 vtkDataArray* normals = normalsFilter->GetOutput()->GetPointData()->GetNormals();
249
250 newPoints->DeepCopy(surface->GetPoints());
251
252 double minTriangleArea = 1E8;
253
254 for (int i=0; i<numberOfPoints; i++)
255 {
257 neighborhood->
Build();
258
260 {
261 continue;
262 }
263
264 double point[3];
265 surface->GetPoint(i,point);
266
267 if (surface->GetPointData()->GetArray("Clamp")->GetTuple1(i) > 0.5)
268 {
269 newPoints->SetPoint(i,point);
270 continue;
271 }
272
273 double meanCurvature = meanCurvatureArray->GetTuple1(i);
274
275 double laplaceH = 0.0;
276
277 double neighborPoint[3];
278 double laplace[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++)
283 {
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]);
290 }
291
292 double point1[3], point2[3];
293 double area = 0.0;
294 double triangleArea;
295 for (int j=0; j<numberOfNeighborhoodPoints; j++)
296 {
297 surface->GetPoint(neighborhood->
GetPointId(j),point1);
298 surface->GetPoint(neighborhood->
GetPointId((j+1)%numberOfNeighborhoodPoints),point2);
300 area += triangleArea;
301 if (triangleArea < minTriangleArea)
302 {
303 minTriangleArea = triangleArea;
304 }
305 }
306
307 double normal[3];
308 normals->GetTuple(i,normal);
309
310 double newPoint[3];
311 newPoint[0] = point[0];
312 newPoint[1] = point[1];
313 newPoint[2] = point[2];
314
315 deltaT = minTriangleArea / 10.0;
316
317
318
319
320
321
322 double alpha = 1.0;
323 double beta = 0.0;
324
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]);
328
329 newPoints->SetPoint(i,newPoint);
330 }
331
332 std::cout<<deltaT<<endl;
333
334 surface->GetPoints()->DeepCopy(newPoints);
335 }
336
337 output->DeepCopy(surface);
338
339 curvaturesFilter->Delete();
340 normalsFilter->Delete();
341 neighborhood->Delete();
342 meanCurvatureArray->Delete();
343 surface->Delete();
344 newPoints->Delete();
345
346 return 1;
347}
virtual void SetDataSetPointId(vtkIdType)
void SetDataSet(vtkDataSet *dataSet)
static double TriangleArea(double point0[3], double point1[3], double point2[3])
vtkIdType GetPointId(vtkIdType i)
virtual bool GetIsBoundary()
vtkIdType GetNumberOfPoints()
virtual void Build() override
static vtkvmtkPolyDataManifoldNeighborhood * New()