1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkDiscreteFlyingEdgesClipper2D.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 vtkDiscreteFlyingEdgesClipper2D 17 * @brief generate filled regions from segmented 2D image data 18 * 19 * vtkDiscreteFlyingEdgesClipper2D creates filled polygons from a label map 20 * (e.g., segmented image) using a variation of the flying edges algorithm 21 * adapted for 2D clipping. The input is a 2D image where each pixel is 22 * labeled (integer labels are preferred to real values), and the output data 23 * is polygonal data representing labeled regions. (Note that on output each 24 * region [corresponding to a different contour value] may share points on a 25 * shared boundary.) 26 * 27 * While this filter is similar to a contouring operation, label maps do not 28 * provide continuous function values meaning that usual interpolation along 29 * edges is not possible. Instead, when the edge endpoints are labeled in 30 * differing regions, the edge is split at its midpoint. In addition, besides 31 * producing intersection points at the mid-point of edges, the filter may 32 * also generate points interior to the pixel cells. For example, if the four 33 * vertices of a pixel cell are labeled with different regions, then an 34 * interior point is created and four rectangular "regions" are produced. 35 * 36 * Note that one nice feature of this filter is that algorithm execution 37 * occurs only one time no matter the number of contour values. In many 38 * contouring-like algorithms, each separate contour value requires an 39 * additional algorithm execution with a new contour value. So in this filter 40 * large numbers of contour values do not significantly affect overall speed. 41 * 42 * @warning This filter is specialized to 2D images. 43 * 44 * @warning 45 * This class has been threaded with vtkSMPTools. Using TBB or other 46 * non-sequential type (set in the CMake variable 47 * VTK_SMP_IMPLEMENTATION_TYPE) may improve performance significantly. 48 * 49 * @sa 50 * vtkDiscreteFlyingEdges2D vtkDiscreteMarchingCubes vtkContourLoopExtraction 51 * vtkFlyingEdges2D vtkFlyingEdges3D 52 */ 53 54 #ifndef vtkDiscreteFlyingEdgesClipper2D_h 55 #define vtkDiscreteFlyingEdgesClipper2D_h 56 57 #include "vtkFiltersGeneralModule.h" // For export macro 58 #include "vtkPolyDataAlgorithm.h" 59 #include "vtkContourValues.h" // Needed for direct access to ContourValues 60 61 class vtkImageData; 62 63 class VTKFILTERSGENERAL_EXPORT vtkDiscreteFlyingEdgesClipper2D : public vtkPolyDataAlgorithm 64 { 65 public: 66 //@{ 67 /** 68 * Standard methods for instantiation, printing, and type information. 69 */ 70 static vtkDiscreteFlyingEdgesClipper2D *New(); 71 vtkTypeMacro(vtkDiscreteFlyingEdgesClipper2D,vtkPolyDataAlgorithm); 72 void PrintSelf(ostream& os, vtkIndent indent) override; 73 //@} 74 75 /** 76 * The modified time is a function of the contour values because we delegate to 77 * vtkContourValues. 78 */ 79 vtkMTimeType GetMTime() override; 80 81 /** 82 * Set a particular contour value at contour number i. The index i ranges 83 * between 0 <= i <NumberOfContours. (Note: while contour values are 84 * expressed as doubles, the underlying scalar data may be a different 85 * type. During execution the contour values are static cast to the type of 86 * the scalar values.) 87 */ SetValue(int i,double value)88 void SetValue(int i, double value) 89 {this->ContourValues->SetValue(i,value);} 90 91 /** 92 * Get the ith contour value. 93 */ GetValue(int i)94 double GetValue(int i) 95 {return this->ContourValues->GetValue(i);} 96 97 /** 98 * Get a pointer to an array of contour values. There will be 99 * GetNumberOfContours() values in the list. 100 */ GetValues()101 double *GetValues() 102 {return this->ContourValues->GetValues();} 103 104 /** 105 * Fill a supplied list with contour values. There will be 106 * GetNumberOfContours() values in the list. Make sure you allocate 107 * enough memory to hold the list. 108 */ GetValues(double * contourValues)109 void GetValues(double *contourValues) 110 {this->ContourValues->GetValues(contourValues);} 111 112 /** 113 * Set the number of contours to place into the list. You only really 114 * need to use this method to reduce list size. The method SetValue() 115 * will automatically increase list size as needed. 116 */ SetNumberOfContours(int number)117 void SetNumberOfContours(int number) 118 {this->ContourValues->SetNumberOfContours(number);} 119 120 /** 121 * Get the number of contours in the list of contour values. 122 */ GetNumberOfContours()123 int GetNumberOfContours() 124 {return this->ContourValues->GetNumberOfContours();} 125 126 //@{ 127 /** 128 * Generate numContours equally spaced contour values between the specified 129 * range. Contour values will include min/max range values. 130 */ GenerateValues(int numContours,double range[2])131 void GenerateValues(int numContours, double range[2]) 132 {this->ContourValues->GenerateValues(numContours, range);} GenerateValues(int numContours,double rangeStart,double rangeEnd)133 void GenerateValues(int numContours, double rangeStart, double rangeEnd) 134 {this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);} 135 //@} 136 137 //@{ 138 /** 139 * Option to set the cell scalars of the output. The scalars will be the 140 * contour values. By default this flag is on. 141 */ 142 vtkSetMacro(ComputeScalars,int); 143 vtkGetMacro(ComputeScalars,int); 144 vtkBooleanMacro(ComputeScalars,int); 145 //@} 146 147 //@{ 148 /** 149 * Set/get which component of a multi-component scalar array to contour on; 150 * defaults to 0. 151 */ 152 vtkSetMacro(ArrayComponent, int); 153 vtkGetMacro(ArrayComponent, int); 154 //@} 155 156 protected: 157 vtkDiscreteFlyingEdgesClipper2D(); 158 ~vtkDiscreteFlyingEdgesClipper2D() override; 159 160 int RequestData(vtkInformation *, vtkInformationVector **, 161 vtkInformationVector *) override; 162 int FillInputPortInformation(int port, vtkInformation *info) override; 163 164 vtkContourValues *ContourValues; 165 int ComputeScalars; 166 int ArrayComponent; 167 168 private: 169 vtkDiscreteFlyingEdgesClipper2D(const vtkDiscreteFlyingEdgesClipper2D&) = delete; 170 void operator=(const vtkDiscreteFlyingEdgesClipper2D&) = delete; 171 }; 172 173 174 #endif 175