VTK
vtkIntersectionCounter.h
Go to the documentation of this file.
1 
19 #ifndef vtkIntersectionCounter_h
20 #define vtkIntersectionCounter_h
21 
22 #include "vtkCommonDataModelModule.h" // For export macro
23 #include "vtkSystemIncludes.h"
24 #include <vector> // for implementation
25 #include <algorithm> // for sorting
26 
27 //class VTKCOMMONDATAMODEL_EXPORT vtkIntersectionCounter
28 
30 {
31 public:
33 
38  vtkIntersectionCounter(double tol, double length)
39  {
40  this->Tolerance = ( length > 0.0 ? (tol/length) : 0.0 );
41  }
43 
47  void SetTolerance(double tol)
48  { this->Tolerance = (tol < 0.0 ? 0.0001 : tol);}
49  double GetTolerance() {return this->Tolerance;}
50 
54  void AddIntersection(double t) {IntsArray.push_back(t);}
55 
59  void Reset() {IntsArray.clear();}
60 
67  {
68  int size = static_cast<int>(IntsArray.size());
69 
70  // Fast check for trivial cases
71  if ( size <= 1 )
72  {
73  return size; //0 or 1
74  }
75 
76  // Need to work harder: sort and then count the intersections
77  std::sort(IntsArray.begin(),IntsArray.end());
78 
79  // If here, there is at least one intersection, and two inserted
80  // intersection points
81  int numInts = 1;
82  std::vector<double>::iterator i0 = IntsArray.begin();
83  std::vector<double>::iterator i1 = i0 + 1;
84 
85  // Now march through sorted array counting "separated" intersections
86  while ( i1 != IntsArray.end() )
87  {
88  if ( (*i1 - *i0) > this->Tolerance )
89  {
90  numInts++;
91  i0 = i1;
92  }
93  i1++;
94  }
95 
96  return numInts;
97  }
98 
99 protected:
100  double Tolerance;
101  std::vector<double> IntsArray;
102 
103 }; // vtkIntersectionCounter
104 
105 #endif
106 // VTK-HeaderTest-Exclude: vtkIntersectionCounter.h
void Reset()
Reset the intersection process.
std::vector< double > IntsArray
vtkIntersectionCounter()
This tolerance must be converted to parametric space.
int CountIntersections()
Returns number of intersections (even number of intersections, outside or odd number of intersections...
Fast simple class for dealing with ray intersections.
vtkIntersectionCounter(double tol, double length)
This tolerance must be converted to parametric space.
void AddIntersection(double t)
Add an intersection given by parametric coordinate t.
void SetTolerance(double tol)
Set/Get the intersection tolerance.