vtkConnectivityFilter.h 9.33 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkConnectivityFilter.h
Will Schroeder's avatar
Will Schroeder committed
5

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Ken Martin's avatar
Ken Martin committed
9

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
Will Schroeder's avatar
Will Schroeder committed
13
14

=========================================================================*/
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * @class   vtkConnectivityFilter
 * @brief   extract data based on geometric connectivity
 *
 * vtkConnectivityFilter is a filter that extracts cells that share common
 * points and/or meet other connectivity criterion. (Cells that share
 * vertices and meet other connectivity criterion such as scalar range are
 * known as a region.)  The filter works in one of six ways: 1) extract the
 * largest connected region in the dataset; 2) extract specified region
 * numbers; 3) extract all regions sharing specified point ids; 4) extract
 * all regions sharing specified cell ids; 5) extract the region closest to
 * the specified point; or 6) extract all regions (used to color the data by
 * region).
 *
 * vtkConnectivityFilter is generalized to handle any type of input dataset.
30
31
 * If the input to this filter is a vtkPolyData, the output will be a vtkPolyData.
 * For all other input types, it generates output data of type vtkUnstructuredGrid.
32
33
34
 * Note that the only Get*Output() methods that will return a non-null pointer
 * are GetUnstructuredGridOutput() and GetPolyDataOutput() when the output of the
 * filter is a vtkUnstructuredGrid or vtkPolyData, respectively.
35
36
37
38
39
40
41
42
43
44
45
46
47
 *
 * The behavior of vtkConnectivityFilter can be modified by turning on the
 * boolean ivar ScalarConnectivity. If this flag is on, the connectivity
 * algorithm is modified so that cells are considered connected only if 1)
 * they are geometrically connected (share a point) and 2) the scalar values
 * of one of the cell's points falls in the scalar range specified. This use
 * of ScalarConnectivity is particularly useful for volume datasets: it can
 * be used as a simple "connected segmentation" algorithm. For example, by
 * using a seed voxel (i.e., cell) on a known anatomical structure,
 * connectivity will pull out all voxels "containing" the anatomical
 * structure. These voxels can then be contoured or processed by other
 * visualization filters.
 *
48
49
50
51
52
 * If the extraction mode is set to all regions and ColorRegions is enabled,
 * The RegionIds are assigned to each region by the order in which the region
 * was processed and has no other significance with respect to the size of
 * or number of cells.
 *
53
54
55
 * @sa
 * vtkPolyDataConnectivityFilter
*/
Will Schroeder's avatar
Will Schroeder committed
56

57
58
#ifndef vtkConnectivityFilter_h
#define vtkConnectivityFilter_h
Will Schroeder's avatar
Will Schroeder committed
59

60
#include "vtkFiltersCoreModule.h" // For export macro
61
#include "vtkPointSetAlgorithm.h"
Will Schroeder's avatar
Will Schroeder committed
62

Will Schroeder's avatar
Will Schroeder committed
63
64
65
66
#define VTK_EXTRACT_POINT_SEEDED_REGIONS 1
#define VTK_EXTRACT_CELL_SEEDED_REGIONS 2
#define VTK_EXTRACT_SPECIFIED_REGIONS 3
#define VTK_EXTRACT_LARGEST_REGION 4
Bill Lorensen's avatar
Bill Lorensen committed
67
#define VTK_EXTRACT_ALL_REGIONS 5
68
#define VTK_EXTRACT_CLOSEST_POINT_REGION 6
Will Schroeder's avatar
Will Schroeder committed
69

70
class vtkDataArray;
71
class vtkDataSet;
72
class vtkFloatArray;
73
class vtkIdList;
74
class vtkIdTypeArray;
75
class vtkIntArray;
76
class vtkPolyData;
77

78
class VTKFILTERSCORE_EXPORT vtkConnectivityFilter : public vtkPointSetAlgorithm
Will Schroeder's avatar
Will Schroeder committed
79
80
{
public:
81
  vtkTypeMacro(vtkConnectivityFilter,vtkPointSetAlgorithm);
82
  void PrintSelf(ostream& os, vtkIndent indent) override;
83

84
85
86
  /**
   * Construct with default extraction mode to extract largest regions.
   */
87
  static vtkConnectivityFilter *New();
88

89
90
91
92
93
94
  //@{
  /**
   * Turn on/off connectivity based on scalar value. If on, cells are connected
   * only if they share points AND one of the cells scalar values falls in the
   * scalar range specified.
   */
95
96
97
  vtkSetMacro(ScalarConnectivity,vtkTypeBool);
  vtkGetMacro(ScalarConnectivity,vtkTypeBool);
  vtkBooleanMacro(ScalarConnectivity,vtkTypeBool);
98
  //@}
99

100
101
102
103
  //@{
  /**
   * Set the scalar range to use to extract cells based on scalar connectivity.
   */
Ken Martin's avatar
Ken Martin committed
104
105
  vtkSetVector2Macro(ScalarRange,double);
  vtkGetVector2Macro(ScalarRange,double);
106
  //@}
107

108
109
110
111
  //@{
  /**
   * Control the extraction of connected surfaces.
   */
Will Schroeder's avatar
Will Schroeder committed
112
  vtkSetClampMacro(ExtractionMode,int,
113
            VTK_EXTRACT_POINT_SEEDED_REGIONS,VTK_EXTRACT_CLOSEST_POINT_REGION);
Will Schroeder's avatar
Will Schroeder committed
114
115
116
117
118
119
120
121
122
  vtkGetMacro(ExtractionMode,int);
  void SetExtractionModeToPointSeededRegions()
    {this->SetExtractionMode(VTK_EXTRACT_POINT_SEEDED_REGIONS);};
  void SetExtractionModeToCellSeededRegions()
    {this->SetExtractionMode(VTK_EXTRACT_CELL_SEEDED_REGIONS);};
  void SetExtractionModeToLargestRegion()
    {this->SetExtractionMode(VTK_EXTRACT_LARGEST_REGION);};
  void SetExtractionModeToSpecifiedRegions()
    {this->SetExtractionMode(VTK_EXTRACT_SPECIFIED_REGIONS);};
123
124
  void SetExtractionModeToClosestPointRegion()
    {this->SetExtractionMode(VTK_EXTRACT_CLOSEST_POINT_REGION);};
Bill Lorensen's avatar
Bill Lorensen committed
125
126
  void SetExtractionModeToAllRegions()
    {this->SetExtractionMode(VTK_EXTRACT_ALL_REGIONS);};
127
  const char *GetExtractionModeAsString();
128
  //@}
Will Schroeder's avatar
Will Schroeder committed
129

130
131
132
  /**
   * Initialize list of point ids/cell ids used to seed regions.
   */
Will Schroeder's avatar
Will Schroeder committed
133
  void InitializeSeedList();
134

135
136
137
  /**
   * Add a seed id (point or cell id). Note: ids are 0-offset.
   */
Amy Squillacote's avatar
Amy Squillacote committed
138
  void AddSeed(vtkIdType id);
139

140
141
142
  /**
   * Delete a seed id (point or cell id). Note: ids are 0-offset.
   */
Amy Squillacote's avatar
Amy Squillacote committed
143
  void DeleteSeed(vtkIdType id);
Will Schroeder's avatar
Will Schroeder committed
144

145
146
147
  /**
   * Initialize list of region ids to extract.
   */
Will Schroeder's avatar
Will Schroeder committed
148
  void InitializeSpecifiedRegionList();
149

150
151
152
  /**
   * Add a region id to extract. Note: ids are 0-offset.
   */
Will Schroeder's avatar
Will Schroeder committed
153
  void AddSpecifiedRegion(int id);
154

155
156
157
  /**
   * Delete a region id to extract. Note: ids are 0-offset.
   */
Will Schroeder's avatar
Will Schroeder committed
158
159
  void DeleteSpecifiedRegion(int id);

160
161
162
163
164
  //@{
  /**
   * Use to specify x-y-z point coordinates when extracting the region
   * closest to a specified point.
   */
Ken Martin's avatar
Ken Martin committed
165
166
  vtkSetVector3Macro(ClosestPoint,double);
  vtkGetVectorMacro(ClosestPoint,double,3);
167
  //@}
168

169
170
171
  /**
   * Obtain the number of connected regions.
   */
Will Schroeder's avatar
Will Schroeder committed
172
173
  int GetNumberOfExtractedRegions();

174
175
176
177
  //@{
  /**
   * Turn on/off the coloring of connected regions.
   */
Sean McBride's avatar
Sean McBride committed
178
179
180
  vtkSetMacro(ColorRegions,vtkTypeBool);
  vtkGetMacro(ColorRegions,vtkTypeBool);
  vtkBooleanMacro(ColorRegions,vtkTypeBool);
181
182
  //@}

Cory Quammen's avatar
Cory Quammen committed
183
184
185
186
187
188
  /**
   * Enumeration of the various ways to assign RegionIds when
   * the ColorRegions option is on.
   */
  enum RegionIdAssignment {
    UNSPECIFIED,
189
190
    CELL_COUNT_DESCENDING,
    CELL_COUNT_ASCENDING
Cory Quammen's avatar
Cory Quammen committed
191
192
193
194
195
196
197
198
199
200
  };

  //@{
  /**
   * Set/get mode controlling how RegionIds are assigned.
   */
  //@}
  vtkSetMacro(RegionIdAssignmentMode, int);
  vtkGetMacro(RegionIdAssignmentMode, int);

201
202
203
204
205
206
  //@{
  /**
   * Set/get the desired precision for the output types. See the documentation
   * for the vtkAlgorithm::DesiredOutputPrecision enum for an explanation of
   * the available precision settings.
   */
207
208
  vtkSetMacro(OutputPointsPrecision,int);
  vtkGetMacro(OutputPointsPrecision,int);
209
  //@}
210

211
212
  int ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;

Will Schroeder's avatar
Will Schroeder committed
213
protected:
214
  vtkConnectivityFilter();
215
  ~vtkConnectivityFilter() override;
216

Will Schroeder's avatar
Will Schroeder committed
217
  // Usual data generation method
218
  int RequestDataObject(vtkInformation* request, vtkInformationVector** inputVector,
219
    vtkInformationVector* outputVector) override;
220
221
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
  int FillInputPortInformation(int port, vtkInformation *info) override;
222
  int FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info) override;
Will Schroeder's avatar
Will Schroeder committed
223

Sean McBride's avatar
Sean McBride committed
224
  vtkTypeBool ColorRegions; //boolean turns on/off scalar gen for separate regions
Will Schroeder's avatar
Will Schroeder committed
225
  int ExtractionMode; //how to extract regions
226
  int OutputPointsPrecision;
227
228
  vtkIdList *Seeds; //id's of points or cells used to seed regions
  vtkIdList *SpecifiedRegionIds; //regions specified for extraction
229
  vtkIdTypeArray *RegionSizes; //size (in cells) of each region extracted
Will Schroeder's avatar
Will Schroeder committed
230

Ken Martin's avatar
Ken Martin committed
231
  double ClosestPoint[3];
232

233
  vtkTypeBool ScalarConnectivity;
Ken Martin's avatar
Ken Martin committed
234
  double ScalarRange[2];
235

Cory Quammen's avatar
Cory Quammen committed
236
237
  int RegionIdAssignmentMode;

238
  void TraverseAndMark(vtkDataSet *input);
Will Schroeder's avatar
Will Schroeder committed
239

Cory Quammen's avatar
Cory Quammen committed
240
241
  void OrderRegionIds(vtkIdTypeArray* pointRegionIds, vtkIdTypeArray* cellRegionIds);

Will Schroeder's avatar
Will Schroeder committed
242
private:
243
  // used to support algorithm execution
244
  vtkFloatArray *CellScalars;
Will Schroeder's avatar
Will Schroeder committed
245
  vtkIdList *NeighborCellPointIds;
Amy Squillacote's avatar
Amy Squillacote committed
246
247
  vtkIdType *Visited;
  vtkIdType *PointMap;
248
  vtkIdTypeArray *NewScalars;
249
  vtkIdTypeArray *NewCellScalars;
250
  vtkIdType RegionNumber;
251
  vtkIdType PointNumber;
252
  vtkIdType NumCellsInRegion;
253
  vtkDataArray *InScalars;
254
255
256
257
  vtkIdList *Wave;
  vtkIdList *Wave2;
  vtkIdList *PointIds;
  vtkIdList *CellIds;
258
private:
259
260
  vtkConnectivityFilter(const vtkConnectivityFilter&) = delete;
  void operator=(const vtkConnectivityFilter&) = delete;
Will Schroeder's avatar
Will Schroeder committed
261
262
};

263
264
265
266
//@{
/**
 * Return the method of extraction as a string.
 */
267
inline const char *vtkConnectivityFilter::GetExtractionModeAsString(void)
Will Schroeder's avatar
Will Schroeder committed
268
{
269
  if ( this->ExtractionMode == VTK_EXTRACT_POINT_SEEDED_REGIONS )
270
  {
Will Schroeder's avatar
Will Schroeder committed
271
    return "ExtractPointSeededRegions";
272
  }
273
  else if ( this->ExtractionMode == VTK_EXTRACT_CELL_SEEDED_REGIONS )
274
  {
Will Schroeder's avatar
Will Schroeder committed
275
    return "ExtractCellSeededRegions";
276
  }
277
  else if ( this->ExtractionMode == VTK_EXTRACT_SPECIFIED_REGIONS )
278
  {
Will Schroeder's avatar
Will Schroeder committed
279
    return "ExtractSpecifiedRegions";
280
  }
281
  else if ( this->ExtractionMode == VTK_EXTRACT_ALL_REGIONS )
282
  {
Bill Lorensen's avatar
Bill Lorensen committed
283
    return "ExtractAllRegions";
284
  }
285
  else if ( this->ExtractionMode == VTK_EXTRACT_CLOSEST_POINT_REGION )
286
  {
287
    return "ExtractClosestPointRegion";
288
  }
289
  else
290
  {
Will Schroeder's avatar
Will Schroeder committed
291
    return "ExtractLargestRegion";
292
  }
Will Schroeder's avatar
Will Schroeder committed
293
}
294
//@}
Will Schroeder's avatar
Will Schroeder committed
295

Will Schroeder's avatar
Will Schroeder committed
296
#endif