1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkSelectPolyData.h,v $
6 Date: $Date: 2002/09/03 12:52:23 $
7 Version: $Revision: 1.22 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkSelectPolyData - select portion of polygonal mesh; generate selection scalars
19 // .SECTION Description
20 // vtkSelectPolyData is a filter that selects polygonal data based on
21 // defining a "loop" and indicating the region inside of the loop. The
22 // mesh within the loop consists of complete cells (the cells are not
23 // cut). Alternatively, this filter can be used to generate scalars.
24 // These scalar values, which are a distance measure to the loop, can
25 // be used to clip, contour. or extract data (i.e., anything that an
26 // implicit function can do).
28 // The loop is defined by an array of x-y-z point coordinates.
29 // (Coordinates should be in the same coordinate space as the input
30 // polygonal data.) The loop can be concave and non-planar, but not
31 // self-intersecting. The input to the filter is a polygonal mesh
32 // (only surface primitives such as triangle strips and polygons); the
33 // output is either a) a portion of the original mesh laying within
34 // the selection loop (GenerateSelectionScalarsOff); or b) the same
35 // polygonal mesh with the addition of scalar values
36 // (GenerateSelectionScalarsOn).
38 // The algorithm works as follows. For each point coordinate in the
39 // loop, the closest point in the mesh is found. The result is a loop
40 // of closest point ids from the mesh. Then, the edges in the mesh
41 // connecting the closest points (and laying along the lines forming
42 // the loop) are found. A greedy edge tracking procedure is used as
43 // follows. At the current point, the mesh edge oriented in the
44 // direction of and whose end point is closest to the line is
45 // chosen. The edge is followed to the new end point, and the
46 // procedure is repeated. This process continues until the entire loop
49 // To determine what portion of the mesh is inside and outside of the
50 // loop, three options are possible. 1) the smallest connected region,
51 // 2) the largest connected region, and 3) the connected region
52 // closest to a user specified point. (Set the ivar SelectionMode.)
54 // Once the loop is computed as above, the GenerateSelectionScalars
55 // controls the output of the filter. If on, then scalar values are
56 // generated based on distance to the loop lines. Otherwise, the cells
57 // laying inside the selection loop are output. By default, the mesh
58 // lying within the loop is output; however, if InsideOut is on, then
59 // the portion of the mesh lying outside of the loop is output.
61 // The filter can be configured to generate the unselected portions of
62 // the mesh as output by setting GenerateUnselectedOutput. Use the
63 // method GetUnselectedOutput to access this output. (Note: this flag
64 // is pertinent only when GenerateSelectionScalars is off.)
67 // Make sure that the points you pick are on a connected surface. If
68 // not, then the filter will generate an empty or partial result. Also,
69 // self-intersecting loops will generate unpredictable results.
71 // During processing of the data, non-triangular cells are converted to
72 // triangles if GenerateSelectionScalars is off.
75 // vtkImplicitSelectionLoop
77 #ifndef __vtkSelectPolyData_h
78 #define __vtkSelectPolyData_h
80 #include "vtkPolyDataToPolyDataFilter.h"
82 #define VTK_INSIDE_SMALLEST_REGION 0
83 #define VTK_INSIDE_LARGEST_REGION 1
84 #define VTK_INSIDE_CLOSEST_POINT_REGION 2
90 class VTK_GRAPHICS_EXPORT vtkSelectPolyData : public vtkPolyDataToPolyDataFilter
94 // Instantiate object with InsideOut turned off, and
95 // GenerateSelectionScalars turned off. The unselected output
96 // is not generated, and the inside mode is the smallest region.
97 static vtkSelectPolyData *New();
99 vtkTypeRevisionMacro(vtkSelectPolyData,vtkPolyDataToPolyDataFilter);
100 void PrintSelf(ostream& os, vtkIndent indent);
103 // Set/Get the flag to control behavior of the filter. If
104 // GenerateSelectionScalars is on, then the output of the filter
105 // is the same as the input, except that scalars are generated.
106 // If off, the filter outputs the cells laying inside the loop, and
107 // does not generate scalars.
108 vtkSetMacro(GenerateSelectionScalars,int);
109 vtkGetMacro(GenerateSelectionScalars,int);
110 vtkBooleanMacro(GenerateSelectionScalars,int);
113 // Set/Get the InsideOut flag. When off, the mesh within the loop is
114 // extracted. When on, the mesh outside the loop is extracted.
115 vtkSetMacro(InsideOut,int);
116 vtkGetMacro(InsideOut,int);
117 vtkBooleanMacro(InsideOut,int);
120 // Set/Get the array of point coordinates defining the loop. There must
121 // be at least three points used to define a loop.
122 virtual void SetLoop(vtkPoints*);
123 vtkGetObjectMacro(Loop,vtkPoints);
126 // Control how inside/outside of loop is defined.
127 vtkSetClampMacro(SelectionMode,int,
128 VTK_INSIDE_SMALLEST_REGION,VTK_INSIDE_CLOSEST_POINT_REGION);
129 vtkGetMacro(SelectionMode,int);
130 void SetSelectionModeToSmallestRegion()
131 {this->SetSelectionMode(VTK_INSIDE_SMALLEST_REGION);};
132 void SetSelectionModeToLargestRegion()
133 {this->SetSelectionMode(VTK_INSIDE_LARGEST_REGION);};
134 void SetSelectionModeToClosestPointRegion()
135 {this->SetSelectionMode(VTK_INSIDE_CLOSEST_POINT_REGION);};
136 const char *GetSelectionModeAsString();
139 // Control whether a second output is generated. The second output
140 // contains the polygonal data that's not been selected.
141 vtkSetMacro(GenerateUnselectedOutput,int);
142 vtkGetMacro(GenerateUnselectedOutput,int);
143 vtkBooleanMacro(GenerateUnselectedOutput,int);
146 // Return output that hasn't been selected (if GenreateUnselectedOutput is
148 vtkPolyData *GetUnselectedOutput() {return this->UnselectedOutput;};
151 // Return the (mesh) edges of the selection region.
152 vtkPolyData *GetSelectionEdges() {return this->SelectionEdges;};
154 // Overload GetMTime() because we depend on Loop
155 unsigned long int GetMTime();
158 // Handle the source/data loop.
159 virtual void UnRegister(vtkObjectBase *o);
162 // Test to see if this object is in a reference counting loop.
163 virtual int InRegisterLoop(vtkObject *);
167 ~vtkSelectPolyData();
171 int GenerateSelectionScalars;
175 float ClosestPoint[3];
176 int GenerateUnselectedOutput;
177 vtkPolyData *UnselectedOutput;
178 vtkPolyData *SelectionEdges;
182 void GetPointNeighbors (vtkIdType ptId, vtkIdList *nei);
184 vtkSelectPolyData(const vtkSelectPolyData&); // Not implemented.
185 void operator=(const vtkSelectPolyData&); // Not implemented.
189 // Return the method of determining in/out of loop as a string.
190 inline const char *vtkSelectPolyData::GetSelectionModeAsString(void)
192 if ( this->SelectionMode == VTK_INSIDE_SMALLEST_REGION )
194 return "InsideSmallestRegion";
196 else if ( this->SelectionMode == VTK_INSIDE_LARGEST_REGION )
198 return "InsideLargestRegion";
202 return "InsideClosestPointRegion";