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
vtkIntersectionCounter::Tolerance
double Tolerance
Definition: vtkIntersectionCounter.h:100
vtkIntersectionCounter::vtkIntersectionCounter
vtkIntersectionCounter(double tol, double length)
Definition: vtkIntersectionCounter.h:38
vtkIntersectionCounter::AddIntersection
void AddIntersection(double t)
Add an intersection given by parametric coordinate t.
Definition: vtkIntersectionCounter.h:54
vtkX3D::length
Definition: vtkX3D.h:393
vtkIntersectionCounter::SetTolerance
void SetTolerance(double tol)
Set/Get the intersection tolerance.
Definition: vtkIntersectionCounter.h:47
vtkX3D::size
Definition: vtkX3D.h:253
vtkIntersectionCounter::Reset
void Reset()
Reset the intersection process.
Definition: vtkIntersectionCounter.h:59
vtkIntersectionCounter::GetTolerance
double GetTolerance()
Definition: vtkIntersectionCounter.h:49
vtkIntersectionCounter::IntsArray
std::vector< double > IntsArray
Definition: vtkIntersectionCounter.h:101
vtkIntersectionCounter::vtkIntersectionCounter
vtkIntersectionCounter()
This tolerance must be converted to parametric space.
Definition: vtkIntersectionCounter.h:37
vtkIntersectionCounter::CountIntersections
int CountIntersections()
Returns number of intersections (even number of intersections, outside or odd number of intersections...
Definition: vtkIntersectionCounter.h:66
vtkSystemIncludes.h
vtkIntersectionCounter
Fast simple class for dealing with ray intersections.
Definition: vtkIntersectionCounter.h:29