1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkPlanesIntersection.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*----------------------------------------------------------------------------
16  Copyright (c) Sandia Corporation
17  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
18 ----------------------------------------------------------------------------*/
19 
20 /**
21  * @class   vtkPlanesIntersection
22  * @brief   A vtkPlanesIntersection object is a
23  *    vtkPlanes object that can compute whether the arbitrary convex region
24  *    bounded by it's planes intersects an axis-aligned box.
25  *
26  *
27  *    A subclass of vtkPlanes, this class determines whether it
28  *    intersects an axis aligned box.   This is motivated by the
29  *    need to intersect the axis aligned region of a spacial
30  *    decomposition of volume data with various other regions.
31  *    It uses the algorithm from Graphics Gems IV, page 81.
32  *
33  * @par Caveat:
34  *    An instance of vtkPlanes can be redefined by changing the planes,
35  *    but this subclass then will not know if the region vertices are
36  *    up to date.  (Region vertices can be specified in SetRegionVertices
37  *    or computed by the subclass.)  So Delete and recreate if you want
38  *    to change the set of planes.
39  *
40  */
41 
42 #ifndef vtkPlanesIntersection_h
43 #define vtkPlanesIntersection_h
44 
45 #include "vtkCommonDataModelModule.h" // For export macro
46 #include "vtkPlanes.h"
47 
48 class vtkPoints;
49 class vtkPointsProjectedHull;
50 class vtkCell;
51 
52 class VTKCOMMONDATAMODEL_EXPORT vtkPlanesIntersection : public vtkPlanes
53 {
54   vtkTypeMacro(vtkPlanesIntersection, vtkPlanes);
55 
56 public:
57   void PrintSelf(ostream& os, vtkIndent indent) override;
58 
59   static vtkPlanesIntersection* New();
60 
61   /**
62    * It helps if you know the vertices of the convex region.
63    * If you don't, we will calculate them.  Region vertices
64    * are 3-tuples.
65    */
66 
67   void SetRegionVertices(vtkPoints* pts);
68   void SetRegionVertices(double* v, int nvertices);
69   int GetNumberOfRegionVertices();
70   // Retained for backward compatibility
GetNumRegionVertices()71   int GetNumRegionVertices() { return this->GetNumberOfRegionVertices(); }
72   int GetRegionVertices(double* v, int nvertices);
73 
74   /**
75    * Return 1 if the axis aligned box defined by R intersects
76    * the region defined by the planes, or 0 otherwise.
77    */
78 
79   int IntersectsRegion(vtkPoints* R);
80 
81   /**
82    * A convenience function provided by this class, returns
83    * 1 if the polygon defined in pts intersects the bounding
84    * box defined in bounds, 0 otherwise.
85 
86    * The points must define a planar polygon.
87    */
88 
89   static int PolygonIntersectsBBox(double bounds[6], vtkPoints* pts);
90 
91   /**
92    * Another convenience function provided by this class, returns
93    * the vtkPlanesIntersection object representing a 3D
94    * cell.  The point IDs for each face must be given in
95    * counter-clockwise order from the outside of the cell.
96    */
97 
98   static vtkPlanesIntersection* Convert3DCell(vtkCell* cell);
99 
100 protected:
101   static void ComputeNormal(double* p1, double* p2, double* p3, double normal[3]);
102   static double EvaluatePlaneEquation(double* x, double* p);
103   static void PlaneEquation(double* n, double* x, double* p);
104   static int GoodNormal(double* n);
105   static int Invert3x3(double M[3][3]);
106 
107   vtkPlanesIntersection();
108   ~vtkPlanesIntersection() override;
109 
110 private:
111   int IntersectsBoundingBox(vtkPoints* R);
112   int EnclosesBoundingBox(vtkPoints* R);
113   int EvaluateFacePlane(int plane, vtkPoints* R);
114   int IntersectsProjection(vtkPoints* R, int direction);
115 
116   void SetPlaneEquations();
117   void ComputeRegionVertices();
118 
119   void planesMatrix(int p1, int p2, int p3, double M[3][3]) const;
120   int duplicate(double testv[3]) const;
121   void planesRHS(int p1, int p2, int p3, double r[3]) const;
122   int outsideRegion(double v[3]);
123 
124   // plane equations
125   double* Planes;
126 
127   // vertices of convex regions enclosed by the planes, also
128   //    the ccw hull of that region projected in 3 orthog. directions
129   vtkPointsProjectedHull* RegionPts;
130 
131   vtkPlanesIntersection(const vtkPlanesIntersection&) = delete;
132   void operator=(const vtkPlanesIntersection&) = delete;
133 };
134 #endif
135