vtkDiscreteFlyingEdgesClipper2D.h 6.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkDiscreteFlyingEdgesClipper2D.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/**
 * @class   vtkDiscreteFlyingEdgesClipper2D
 * @brief   generate filled regions from segmented 2D image data
 *
 * vtkDiscreteFlyingEdgesClipper2D creates filled polygons from a label map
 * (e.g., segmented image) using a variation of the flying edges algorithm
 * adapted for 2D clipping. The input is a 2D image where each pixel is
 * labeled (integer labels are preferred to real values), and the output data
 * is polygonal data representing labeled regions. (Note that on output each
 * region [corresponding to a different contour value] may share points on a
 * shared boundary.)
 *
 * While this filter is similar to a contouring operation, label maps do not
 * provide continuous function values meaning that usual interpolation along
 * edges is not possible. Instead, when the edge endpoints are labeled in
 * differing regions, the edge is split at its midpoint. In addition, besides
 * producing intersection points at the mid-point of edges, the filter may
 * also generate points interior to the pixel cells. For example, if the four
 * vertices of a pixel cell are labeled with different regions, then an
 * interior point is created and four rectangular "regions" are produced.
 *
 * Note that one nice feature of this filter is that algorithm execution
 * occurs only one time no matter the number of contour values. In many
 * contouring-like algorithms, each separate contour value requires an
 * additional algorithm execution with a new contour value. So in this filter
 * large numbers of contour values do not significantly affect overall speed.
 *
 * @warning This filter is specialized to 2D images.
 *
 * @warning
 * This class has been threaded with vtkSMPTools. Using TBB or other
 * non-sequential type (set in the CMake variable
 * VTK_SMP_IMPLEMENTATION_TYPE) may improve performance significantly.
 *
 * @sa
 * vtkDiscreteFlyingEdges2D vtkDiscreteMarchingCubes vtkContourLoopExtraction
 * vtkFlyingEdges2D vtkFlyingEdges3D
 */

#ifndef vtkDiscreteFlyingEdgesClipper2D_h
#define vtkDiscreteFlyingEdgesClipper2D_h

#include "vtkFiltersGeneralModule.h" // For export macro
#include "vtkPolyDataAlgorithm.h"
#include "vtkContourValues.h" // Needed for direct access to ContourValues

class vtkImageData;

class VTKFILTERSGENERAL_EXPORT vtkDiscreteFlyingEdgesClipper2D : public vtkPolyDataAlgorithm
{
public:
  //@{
  /**
   * Standard methods for instantiation, printing, and type information.
   */
  static vtkDiscreteFlyingEdgesClipper2D *New();
  vtkTypeMacro(vtkDiscreteFlyingEdgesClipper2D,vtkPolyDataAlgorithm);
  void PrintSelf(ostream& os, vtkIndent indent) override;
  //@}

  /**
   * The modified time is a function of the contour values because we delegate to
   * vtkContourValues.
   */
  vtkMTimeType GetMTime() override;

  /**
   * Set a particular contour value at contour number i. The index i ranges
   * between 0 <= i <NumberOfContours. (Note: while contour values are
   * expressed as doubles, the underlying scalar data may be a different
   * type. During execution the contour values are static cast to the type of
   * the scalar values.)
   */
  void SetValue(int i, double value)
    {this->ContourValues->SetValue(i,value);}

  /**
   * Get the ith contour value.
   */
  double GetValue(int i)
    {return this->ContourValues->GetValue(i);}

  /**
   * Get a pointer to an array of contour values. There will be
   * GetNumberOfContours() values in the list.
   */
  double *GetValues()
    {return this->ContourValues->GetValues();}

  /**
   * Fill a supplied list with contour values. There will be
   * GetNumberOfContours() values in the list. Make sure you allocate
   * enough memory to hold the list.
   */
  void GetValues(double *contourValues)
    {this->ContourValues->GetValues(contourValues);}

  /**
   * Set the number of contours to place into the list. You only really
   * need to use this method to reduce list size. The method SetValue()
   * will automatically increase list size as needed.
   */
  void SetNumberOfContours(int number)
    {this->ContourValues->SetNumberOfContours(number);}

  /**
   * Get the number of contours in the list of contour values.
   */
  int GetNumberOfContours()
    {return this->ContourValues->GetNumberOfContours();}

  //@{
  /**
   * Generate numContours equally spaced contour values between the specified
   * range. Contour values will include min/max range values.
   */
  void GenerateValues(int numContours, double range[2])
    {this->ContourValues->GenerateValues(numContours, range);}
  void GenerateValues(int numContours, double rangeStart, double rangeEnd)
    {this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);}
  //@}

  //@{
  /**
   * Option to set the cell scalars of the output. The scalars will be the
   * contour values. By default this flag is on.
   */
  vtkSetMacro(ComputeScalars,int);
  vtkGetMacro(ComputeScalars,int);
  vtkBooleanMacro(ComputeScalars,int);
  //@}

  //@{
  /**
   * Set/get which component of a multi-component scalar array to contour on;
   * defaults to 0.
   */
  vtkSetMacro(ArrayComponent, int);
  vtkGetMacro(ArrayComponent, int);
  //@}

protected:
  vtkDiscreteFlyingEdgesClipper2D();
  ~vtkDiscreteFlyingEdgesClipper2D() override;

  int RequestData(vtkInformation *, vtkInformationVector **,
                  vtkInformationVector *) override;
  int FillInputPortInformation(int port, vtkInformation *info) override;

  vtkContourValues *ContourValues;
  int ComputeScalars;
  int ArrayComponent;

private:
  vtkDiscreteFlyingEdgesClipper2D(const vtkDiscreteFlyingEdgesClipper2D&) = delete;
  void operator=(const vtkDiscreteFlyingEdgesClipper2D&) = delete;
};


#endif