1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkImplicitSelectionLoop.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  * @class   vtkImplicitSelectionLoop
17  * @brief   implicit function for a selection loop
18  *
19  * vtkImplicitSelectionLoop computes the implicit function value and
20  * function gradient for an irregular, cylinder-like object whose cross
21  * section is defined by a set of points forming a loop. The loop need
22  * not be convex nor its points coplanar. However, the loop must be
23  * non-self-intersecting when projected onto the plane defined by the
24  * accumulated cross product around the loop (i.e., the axis of the
25  * loop). (Alternatively, you can specify the normal to use.)
26  *
27  * The following procedure is used to compute the implicit function
28  * value for a point x. Each point of the loop is first projected onto
29  * the plane defined by the loop normal. This forms a polygon. Then,
30  * to evaluate the implicit function value, inside/outside tests are
31  * used to determine if x is inside the polygon, and the distance to
32  * the loop boundary is computed (negative values are inside the
33  * loop).
34  *
35  * One example application of this implicit function class is to draw a
36  * loop on the surface of a mesh, and use the loop to clip or extract
37  * cells from within the loop. Remember, the selection loop is "infinite"
38  * in length, you can use a plane (in boolean combination) to cap the extent
39  * of the selection loop. Another trick is to use a connectivity filter to
40  * extract the closest region to a given point (i.e., one of the points used
41  * to define the selection loop).
42  *
43  * @sa
44  * vtkImplicitFunction vtkImplicitBoolean vtkExtractGeometry vtkClipPolyData
45  * vtkConnectivityFilter vtkPolyDataConnectivityFilter
46  */
47 
48 #ifndef vtkImplicitSelectionLoop_h
49 #define vtkImplicitSelectionLoop_h
50 
51 #include "vtkCommonDataModelModule.h" // For export macro
52 #include "vtkImplicitFunction.h"
53 
54 class vtkPoints;
55 class vtkPolygon;
56 
57 class VTKCOMMONDATAMODEL_EXPORT vtkImplicitSelectionLoop : public vtkImplicitFunction
58 {
59 public:
60   ///@{
61   /**
62    * Standard VTK methods for printing and type information.
63    */
64   vtkTypeMacro(vtkImplicitSelectionLoop, vtkImplicitFunction);
65   void PrintSelf(ostream& os, vtkIndent indent) override;
66   ///@}
67 
68   /**
69    * Instantiate object with no initial loop.
70    */
71   static vtkImplicitSelectionLoop* New();
72 
73   ///@{
74   /**
75    * Evaluate selection loop returning a signed distance.
76    */
77   using vtkImplicitFunction::EvaluateFunction;
78   double EvaluateFunction(double x[3]) override;
79   ///@}
80 
81   /**
82    * Evaluate selection loop returning the gradient.
83    */
84   void EvaluateGradient(double x[3], double n[3]) override;
85 
86   ///@{
87   /**
88    * Set/Get the array of point coordinates defining the loop. There must
89    * be at least three points used to define a loop.
90    */
91   virtual void SetLoop(vtkPoints*);
92   vtkGetObjectMacro(Loop, vtkPoints);
93   ///@}
94 
95   ///@{
96   /**
97    * Turn on/off automatic normal generation. By default, the normal is
98    * computed from the accumulated cross product of the edges. You can also
99    * specify the normal to use.
100    */
101   vtkSetMacro(AutomaticNormalGeneration, vtkTypeBool);
102   vtkGetMacro(AutomaticNormalGeneration, vtkTypeBool);
103   vtkBooleanMacro(AutomaticNormalGeneration, vtkTypeBool);
104   ///@}
105 
106   ///@{
107   /**
108    * Set / get the normal used to determine whether a point is inside or outside
109    * the selection loop.
110    */
111   vtkSetVector3Macro(Normal, double);
112   vtkGetVectorMacro(Normal, double, 3);
113   ///@}
114 
115   /**
116    * Overload GetMTime() because we depend on the Loop
117    */
118   vtkMTimeType GetMTime() override;
119 
120 protected:
121   vtkImplicitSelectionLoop();
122   ~vtkImplicitSelectionLoop() override;
123 
124   vtkPoints* Loop;
125   double Normal[3];
126   vtkTypeBool AutomaticNormalGeneration;
127 
128 private:
129   void Initialize();
130   vtkPolygon* Polygon;
131 
132   double Origin[3];
133   double Bounds[6]; // bounds of the projected polyon
134   double DeltaX;
135   double DeltaY;
136   double DeltaZ;
137 
138   vtkTimeStamp InitializationTime;
139 
140 private:
141   vtkImplicitSelectionLoop(const vtkImplicitSelectionLoop&) = delete;
142   void operator=(const vtkImplicitSelectionLoop&) = delete;
143 };
144 
145 #endif
146