54{
55 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
56 vtkInformation *outInfo = outputVector->GetInformationObject(0);
57
58 vtkPolyData *input = vtkPolyData::SafeDownCast(
59 inInfo->Get(vtkDataObject::DATA_OBJECT()));
60 vtkPolyData *output = vtkPolyData::SafeDownCast(
61 outInfo->Get(vtkDataObject::DATA_OBJECT()));
62
63 if (input->GetNumberOfPoints() < 1)
64 {
65 return 1;
66 }
67
69 {
70 vtkErrorMacro(<<"No SizingFunctionArrayName specified");
71 return 1;
72 }
73
74 input->BuildCells();
75 input->BuildLinks();
76
77 int numberOfPoints = input->GetNumberOfPoints();
78
79 vtkDoubleArray* sizingFunctionArray = vtkDoubleArray::New();
81 sizingFunctionArray->SetNumberOfTuples(numberOfPoints);
82 sizingFunctionArray->FillComponent(0,0.0);
83
84 vtkIdList* pointCells = vtkIdList::New();
85
86 int i, j;
87 for (i=0; i<numberOfPoints; i++)
88 {
89 input->GetPointCells(i,pointCells);
90 int numberOfPointCells = pointCells->GetNumberOfIds();
91 double averageArea = 0.0;
92 if (numberOfPointCells == 0)
93 {
94 continue;
95 }
96 for (j=0; j<numberOfPointCells; j++)
97 {
98 vtkTriangle* triangle = vtkTriangle::SafeDownCast(input->GetCell(pointCells->GetId(j)));
99 if (!triangle)
100 {
101 vtkErrorMacro(<<"Cell not triangle: skipping cell for sizing function computation");
102 }
103 double point0[3], point1[3], point2[3];
104 triangle->GetPoints()->GetPoint(0,point0);
105 triangle->GetPoints()->GetPoint(1,point1);
106 triangle->GetPoints()->GetPoint(2,point2);
107 averageArea += vtkTriangle::TriangleArea(point0,point1,point2);
108 }
109 averageArea /= numberOfPointCells;
110
111 double sizingFunction = sqrt(averageArea) * this->
ScaleFactor;
112 sizingFunctionArray->SetValue(i,sizingFunction);
113 }
114
115 output->DeepCopy(input);
116 output->GetPointData()->AddArray(sizingFunctionArray);
117
118 sizingFunctionArray->Delete();
119 pointCells->Delete();
120
121 return 1;
122}