File: vtkIntersectionCounter.h

package info (click to toggle)
paraview 5.11.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 497,236 kB
  • sloc: cpp: 3,171,290; ansic: 1,315,072; python: 134,290; xml: 103,324; sql: 65,887; sh: 5,286; javascript: 4,901; yacc: 4,383; java: 3,977; perl: 2,363; lex: 1,909; f90: 1,255; objc: 143; makefile: 119; tcl: 59; pascal: 50; fortran: 29
file content (110 lines) | stat: -rw-r--r-- 2,954 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 * @class   vtkIntersectionCounter
 * @brief   Fast simple class for dealing with ray intersections
 *
 * vtkIntersectionCounter is used to intersect data and merge coincident
 * points along the intersect ray. It is light-weight and many of the member
 * functions are in-lined so its very fast. It is not derived from vtkObject
 * so it can be allocated on the stack.
 *
 * This class makes the finite ray intersection process more robust. It
 * merges intersections that are very close to one another (within a
 * tolerance). Such situations are common when intersection rays pass through
 * the edge or vertex of a mesh.
 *
 * @sa
 * vtkBoundingBox
 */

#ifndef vtkIntersectionCounter_h
#define vtkIntersectionCounter_h

#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkSystemIncludes.h"
#include <algorithm> // for sorting
#include <vector>    // for implementation

// class VTKCOMMONDATAMODEL_EXPORT vtkIntersectionCounter

VTK_ABI_NAMESPACE_BEGIN
class vtkIntersectionCounter
{
public:
  ///@{
  /**
   * This tolerance must be converted to parametric space. Here tol is the
   * tolerance in world coordinates; length is the ray length.
   */
  vtkIntersectionCounter()
    : Tolerance(0.0001)
  {
  }
  vtkIntersectionCounter(double tol, double length)
  {
    this->Tolerance = (length > 0.0 ? (tol / length) : 0.0);
  }
  ///@}

  /**
   * Set/Get the intersection tolerance.
   */
  void SetTolerance(double tol) { this->Tolerance = (tol < 0.0 ? 0.0001 : tol); }
  double GetTolerance() { return this->Tolerance; }

  /**
   * Add an intersection given by parametric coordinate t.
   */
  void AddIntersection(double t) { IntsArray.push_back(t); }

  /**
   * Reset the intersection process.
   */
  void Reset() { IntsArray.clear(); }

  /**
   * Returns number of intersections (even number of intersections, outside
   * or odd number of intersections, inside). This is done by considering
   * close intersections (within Tolerance) as being the same point.
   */
  int CountIntersections()
  {
    int size = static_cast<int>(IntsArray.size());

    // Fast check for trivial cases
    if (size <= 1)
    {
      return size; // 0 or 1
    }

    // Need to work harder: sort and then count the intersections
    std::sort(IntsArray.begin(), IntsArray.end());

    // If here, there is at least one intersection, and two inserted
    // intersection points
    int numInts = 1;
    std::vector<double>::iterator i0 = IntsArray.begin();
    std::vector<double>::iterator i1 = i0 + 1;

    // Now march through sorted array counting "separated" intersections
    while (i1 != IntsArray.end())
    {
      if ((*i1 - *i0) > this->Tolerance)
      {
        numInts++;
        i0 = i1;
      }
      i1++;
    }

    return numInts;
  }

protected:
  double Tolerance;
  std::vector<double> IntsArray;

}; // vtkIntersectionCounter

VTK_ABI_NAMESPACE_END
#endif
// VTK-HeaderTest-Exclude: vtkIntersectionCounter.h