1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkFlyingEdges2D.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 vtkFlyingEdges2D 17 * @brief generate isoline(s) from a structured points (image) dataset 18 * 19 * vtkFlyingEdges2D is a reference implementation of the 2D version of the 20 * flying edges algorithm. It is designed to be highly scalable (i.e., 21 * parallelizable) for large data. It implements certain performance 22 * optimizations including computational trimming to rapidly eliminate 23 * processing of data regions, packed bit representation of case table 24 * values, single edge intersection, elimination of point merging, and 25 * elimination of any reallocs (due to dynamic data insertion). Note that 26 * computational trimming is a method to reduce total computational cost in 27 * which partial computational results can be used to eliminate future 28 * computations. 29 * 30 * This is a four-pass algorithm. The first pass processes all x-edges and 31 * builds x-edge case values (which, when the two x-edges defining a pixel 32 * are combined, are equivalent to vertex-based case table except edge-based 33 * approaches are separable to parallel computing). Next x-pixel rows are 34 * processed to gather information from y-edges (basically to count the 35 * number of edge intersections and lines generated). In the third pass a 36 * prefix sum is used to count and allocate memory for the output 37 * primitives. Finally in the fourth pass output primitives are generated into 38 * pre-allocated arrays. This implementation uses pixel cell axes (a x-y dyad 39 * located at the pixel origin) to ensure that each edge is intersected at 40 * most one time. 41 * 42 * See the paper "Flying Edges: A High-Performance Scalable Isocontouring 43 * Algorithm" by Schroeder, Maynard, Geveci. Proc. of LDAV 2015. Chicago, IL. 44 * 45 * @warning 46 * This filter is specialized to 2D images. This implementation can produce 47 * degenerate line segments (i.e., zero-length line segments). 48 * 49 * @warning 50 * If you are interested in extracting segmented regions from a label mask, 51 * consider using vtkDiscreteFlyingEdges2D. 52 * 53 * @warning 54 * This class has been threaded with vtkSMPTools. Using TBB or other 55 * non-sequential type (set in the CMake variable 56 * VTK_SMP_IMPLEMENTATION_TYPE) may improve performance significantly. 57 * 58 * @sa 59 * vtkFlyingEdges3D vtkContourFilter vtkSynchronizedTemplates2D 60 * vtkMarchingSquares vtkDiscreteFlyingEdges2D 61 */ 62 63 #ifndef vtkFlyingEdges2D_h 64 #define vtkFlyingEdges2D_h 65 66 #include "vtkFiltersCoreModule.h" // For export macro 67 #include "vtkPolyDataAlgorithm.h" 68 #include "vtkContourValues.h" // Needed for direct access to ContourValues 69 70 class vtkImageData; 71 72 class VTKFILTERSCORE_EXPORT vtkFlyingEdges2D : public vtkPolyDataAlgorithm 73 { 74 public: 75 static vtkFlyingEdges2D *New(); 76 vtkTypeMacro(vtkFlyingEdges2D,vtkPolyDataAlgorithm); 77 void PrintSelf(ostream& os, vtkIndent indent) override; 78 79 /** 80 * Because we delegate to vtkContourValues. 81 */ 82 vtkMTimeType GetMTime() override; 83 84 /** 85 * Set a particular contour value at contour number i. The index i ranges 86 * between 0<=i<NumberOfContours. 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 * Generate numContours equally spaced contour values between specified 128 * range. Contour values will include min/max range values. 129 */ GenerateValues(int numContours,double range[2])130 void GenerateValues(int numContours, double range[2]) 131 {this->ContourValues->GenerateValues(numContours, range);} 132 133 /** 134 * Generate numContours equally spaced contour values between specified 135 * range. Contour values will include min/max range values. 136 */ GenerateValues(int numContours,double rangeStart,double rangeEnd)137 void GenerateValues(int numContours, double rangeStart, double rangeEnd) 138 {this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);} 139 140 //@{ 141 /** 142 * Option to set the point scalars of the output. The scalars will be the 143 * iso value of course. By default this flag is on. 144 */ 145 vtkSetMacro(ComputeScalars,vtkTypeBool); 146 vtkGetMacro(ComputeScalars,vtkTypeBool); 147 vtkBooleanMacro(ComputeScalars,vtkTypeBool); 148 //@} 149 150 //@{ 151 /** 152 * Set/get which component of the scalar array to contour on; defaults to 0. 153 */ 154 vtkSetMacro(ArrayComponent, int); 155 vtkGetMacro(ArrayComponent, int); 156 //@} 157 158 protected: 159 vtkFlyingEdges2D(); 160 ~vtkFlyingEdges2D() override; 161 162 int RequestData(vtkInformation *, vtkInformationVector **, 163 vtkInformationVector *) override; 164 int FillInputPortInformation(int port, vtkInformation *info) override; 165 vtkContourValues *ContourValues; 166 167 vtkTypeBool ComputeScalars; 168 int ArrayComponent; 169 170 private: 171 vtkFlyingEdges2D(const vtkFlyingEdges2D&) = delete; 172 void operator=(const vtkFlyingEdges2D&) = delete; 173 }; 174 175 176 #endif 177