1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkExtractPolyDataGeometry.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   vtkExtractPolyDataGeometry
17  * @brief   extract vtkPolyData cells that lies either entirely inside or outside of a specified implicit function
18  *
19  *
20  * vtkExtractPolyDataGeometry extracts from its input vtkPolyData all cells
21  * that are either completely inside or outside of a specified implicit
22  * function. This filter is specialized to vtkPolyData. On output the
23  * filter generates vtkPolyData.
24  *
25  * To use this filter you must specify an implicit function. You must also
26  * specify whether to extract cells laying inside or outside of the implicit
27  * function. (The inside of an implicit function is the negative values
28  * region.) An option exists to extract cells that are neither inside nor
29  * outside (i.e., boundary).
30  *
31  * Note that this filter also has the option to directly pass all points or cull
32  * the points that do not satisfy the implicit function test. Passing all points
33  * is a tad faster, but then points remain that do not pass the test and may mess
34  * up subsequent glyphing operations and so on. By default points are culled.
35  *
36  * A more general version of this filter is available for arbitrary
37  * vtkDataSet input (see vtkExtractGeometry).
38  *
39  * @sa
40  * vtkExtractGeometry vtkClipPolyData
41 */
42 
43 #ifndef vtkExtractPolyDataGeometry_h
44 #define vtkExtractPolyDataGeometry_h
45 
46 #include "vtkFiltersExtractionModule.h" // For export macro
47 #include "vtkPolyDataAlgorithm.h"
48 
49 class vtkImplicitFunction;
50 
51 class VTKFILTERSEXTRACTION_EXPORT vtkExtractPolyDataGeometry : public vtkPolyDataAlgorithm
52 {
53 public:
54   vtkTypeMacro(vtkExtractPolyDataGeometry,vtkPolyDataAlgorithm);
55   void PrintSelf(ostream& os, vtkIndent indent) override;
56 
57   /**
58    * Construct object with ExtractInside turned on.
59    */
60   static vtkExtractPolyDataGeometry *New();
61 
62   /**
63    * Return the MTime taking into account changes to the implicit function
64    */
65   vtkMTimeType GetMTime() override;
66 
67   //@{
68   /**
69    * Specify the implicit function for inside/outside checks.
70    */
71   virtual void SetImplicitFunction(vtkImplicitFunction*);
72   vtkGetObjectMacro(ImplicitFunction,vtkImplicitFunction);
73   //@}
74 
75   //@{
76   /**
77    * Boolean controls whether to extract cells that are inside of implicit
78    * function (ExtractInside == 1) or outside of implicit function
79    * (ExtractInside == 0).
80    */
81   vtkSetMacro(ExtractInside,vtkTypeBool);
82   vtkGetMacro(ExtractInside,vtkTypeBool);
83   vtkBooleanMacro(ExtractInside,vtkTypeBool);
84   //@}
85 
86   //@{
87   /**
88    * Boolean controls whether to extract cells that are partially inside.
89    * By default, ExtractBoundaryCells is off.
90    */
91   vtkSetMacro(ExtractBoundaryCells,vtkTypeBool);
92   vtkGetMacro(ExtractBoundaryCells,vtkTypeBool);
93   vtkBooleanMacro(ExtractBoundaryCells,vtkTypeBool);
94   //@}
95 
96   //@{
97   /**
98    * Boolean controls whether points are culled or simply passed through
99    * to the output.
100    */
101   vtkSetMacro(PassPoints,vtkTypeBool);
102   vtkGetMacro(PassPoints,vtkTypeBool);
103   vtkBooleanMacro(PassPoints,vtkTypeBool);
104   //@}
105 
106 protected:
107   vtkExtractPolyDataGeometry(vtkImplicitFunction *f=nullptr);
108   ~vtkExtractPolyDataGeometry() override;
109 
110   // Usual data generation method
111   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
112 
113   vtkImplicitFunction *ImplicitFunction;
114   vtkTypeBool ExtractInside;
115   vtkTypeBool ExtractBoundaryCells;
116   vtkTypeBool PassPoints;
117 
118   vtkIdType InsertPointInMap(vtkIdType i, vtkPoints *inPts, vtkPoints *newPts, vtkIdType *pointMap);
119 
120 private:
121   vtkExtractPolyDataGeometry(const vtkExtractPolyDataGeometry&) = delete;
122   void operator=(const vtkExtractPolyDataGeometry&) = delete;
123 };
124 
125 //@{
126 /**
127  * When not passing points, have to use a point map to keep track of things.
128  */
InsertPointInMap(vtkIdType i,vtkPoints * inPts,vtkPoints * newPts,vtkIdType * pointMap)129 inline vtkIdType vtkExtractPolyDataGeometry::InsertPointInMap(vtkIdType i, vtkPoints *inPts,
130                                                               vtkPoints *newPts, vtkIdType *pointMap)
131 {
132   double x[3];
133   inPts->GetPoint(i, x);
134   pointMap[i] = newPts->InsertNextPoint(x);
135   return pointMap[i];
136 }
137 //@}
138 
139 
140 #endif
141