13 #include "vtkAreaSimplificationMetric.h" 18 #include <vtkTriangle.h> 22 double vtkAreaSimplificationMetric::ComputeMetric(vtkDataSet *mesh,
23 vtkDataArray *scalarField, vtkIdType startCriticalPoint,
24 vtkAbstractArray* vertexList, vtkIdType endCriticalPoint)
33 double fieldLowerBound = scalarField->GetComponent(startCriticalPoint,0),
34 fieldUpperBound = scalarField->GetComponent(endCriticalPoint,0);
36 double cumulativeArea = 0;
38 std::map<vtkIdType, bool> visitedTriangles;
40 for(
int i = 0; i < vertexList->GetNumberOfTuples(); i++)
42 int vId = vertexList->GetVariantValue(i).ToInt();
43 vtkIdList *starTriangleList = vtkIdList::New();
45 mesh->GetPointCells(vId, starTriangleList);
47 for(
int j = 0; j < starTriangleList->GetNumberOfIds(); j++)
49 vtkIdType tId = starTriangleList->GetId(j);
50 vtkTriangle *t = vtkTriangle::SafeDownCast(mesh->GetCell(tId));
51 std::map<vtkIdType, bool>::iterator tIt = visitedTriangles.find(tId);
52 if(tIt == visitedTriangles.end())
54 if((scalarField->GetComponent(t->GetPointIds()->GetId(0), 0)
56 &&(scalarField->GetComponent(t->GetPointIds()->GetId(1), 0)
58 &&(scalarField->GetComponent(t->GetPointIds()->GetId(2), 0)
60 &&(scalarField->GetComponent(t->GetPointIds()->GetId(0), 0)
62 &&(scalarField->GetComponent(t->GetPointIds()->GetId(1), 0)
64 &&(scalarField->GetComponent(t->GetPointIds()->GetId(2), 0)
68 cumulativeArea += t->ComputeArea();
70 visitedTriangles[tId] =
true;
74 starTriangleList->Delete();
77 return cumulativeArea/(this->UpperBound - this->LowerBound);