VTK  9.1.0
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 <algorithm> // for sorting
25#include <vector> // for implementation
26
27// class VTKCOMMONDATAMODEL_EXPORT vtkIntersectionCounter
28
30{
31public:
33
38 : Tolerance(0.0001)
39 {
40 }
41 vtkIntersectionCounter(double tol, double length)
42 {
43 this->Tolerance = (length > 0.0 ? (tol / length) : 0.0);
44 }
46
50 void SetTolerance(double tol) { this->Tolerance = (tol < 0.0 ? 0.0001 : tol); }
51 double GetTolerance() { return this->Tolerance; }
52
56 void AddIntersection(double t) { IntsArray.push_back(t); }
57
61 void Reset() { IntsArray.clear(); }
62
69 {
70 int size = static_cast<int>(IntsArray.size());
71
72 // Fast check for trivial cases
73 if (size <= 1)
74 {
75 return size; // 0 or 1
76 }
77
78 // Need to work harder: sort and then count the intersections
79 std::sort(IntsArray.begin(), IntsArray.end());
80
81 // If here, there is at least one intersection, and two inserted
82 // intersection points
83 int numInts = 1;
84 std::vector<double>::iterator i0 = IntsArray.begin();
85 std::vector<double>::iterator i1 = i0 + 1;
86
87 // Now march through sorted array counting "separated" intersections
88 while (i1 != IntsArray.end())
89 {
90 if ((*i1 - *i0) > this->Tolerance)
91 {
92 numInts++;
93 i0 = i1;
94 }
95 i1++;
96 }
97
98 return numInts;
99 }
100
101protected:
102 double Tolerance;
103 std::vector<double> IntsArray;
104
105}; // vtkIntersectionCounter
106
107#endif
108// VTK-HeaderTest-Exclude: vtkIntersectionCounter.h
Fast simple class for dealing with ray intersections.
void AddIntersection(double t)
Add an intersection given by parametric coordinate t.
void Reset()
Reset the intersection process.
vtkIntersectionCounter(double tol, double length)
This tolerance must be converted to parametric space.
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...
void SetTolerance(double tol)
Set/Get the intersection tolerance.
@ length
Definition: vtkX3D.h:399
@ size
Definition: vtkX3D.h:259