SMILX  1.01
vtkAreaSimplificationMetric.cxx
1 /*=========================================================================
2  Copyright: (c) CSIRO, Australia
3 
4  This software is protected by international copyright laws.
5  Any unauthorised copying, distribution or reverse engineering is prohibited.
6 
7  Licence:
8  All rights in this Software are reserved to CSIRO. You are only permitted
9  to have this Software in your possession and to make use of it if you have
10  agreed to a Software License with CSIRO.
11 =========================================================================*/
12 
13 #include "vtkAreaSimplificationMetric.h"
14 
15 //STL
16 #include <map>
17 //VTK
18 #include <vtkTriangle.h>
19 
20 vtkStandardNewMacro(vtkAreaSimplificationMetric);
21 
22 double vtkAreaSimplificationMetric::ComputeMetric(vtkDataSet *mesh,
23  vtkDataArray *scalarField, vtkIdType startCriticalPoint,
24  vtkAbstractArray* vertexList, vtkIdType endCriticalPoint)
25 {
26  // In this example, the metric algorithm just evaluates the area of the
27  // surface region corresponding to the arc of the Reeb graph passed as an
28  // argument.
29  // As a result, the arcs corresponding to small surface regions (below the
30  // threshold specified to the simplificatin filter) will be
31  // simplified in priority in the surface simplification algorithm.
32 
33  double fieldLowerBound = scalarField->GetComponent(startCriticalPoint,0),
34  fieldUpperBound = scalarField->GetComponent(endCriticalPoint,0);
35 
36  double cumulativeArea = 0;
37 
38  std::map<vtkIdType, bool> visitedTriangles;
39 
40  for(int i = 0; i < vertexList->GetNumberOfTuples(); i++)
41  {
42  int vId = vertexList->GetVariantValue(i).ToInt();
43  vtkIdList *starTriangleList = vtkIdList::New();
44 
45  mesh->GetPointCells(vId, starTriangleList);
46 
47  for(int j = 0; j < starTriangleList->GetNumberOfIds(); j++)
48  {
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())
53  {
54  if((scalarField->GetComponent(t->GetPointIds()->GetId(0), 0)
55  <= fieldUpperBound)
56  &&(scalarField->GetComponent(t->GetPointIds()->GetId(1), 0)
57  <= fieldUpperBound)
58  &&(scalarField->GetComponent(t->GetPointIds()->GetId(2), 0)
59  <= fieldUpperBound)
60  &&(scalarField->GetComponent(t->GetPointIds()->GetId(0), 0)
61  >= fieldLowerBound)
62  &&(scalarField->GetComponent(t->GetPointIds()->GetId(1), 0)
63  >= fieldLowerBound)
64  &&(scalarField->GetComponent(t->GetPointIds()->GetId(2), 0)
65  >= fieldLowerBound))
66  {
67  // the triangle fully maps inside the arc function interval
68  cumulativeArea += t->ComputeArea();
69  }
70  visitedTriangles[tId] = true;
71  }
72  }
73 
74  starTriangleList->Delete();
75  }
76 
77  return cumulativeArea/(this->UpperBound - this->LowerBound);
78 }