VTK  9.3.1
vtkImageToPolyDataFilter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
55 #ifndef vtkImageToPolyDataFilter_h
56 #define vtkImageToPolyDataFilter_h
57 
58 #include "vtkFiltersHybridModule.h" // For export macro
59 #include "vtkPolyDataAlgorithm.h"
60 
61 #define VTK_STYLE_PIXELIZE 0
62 #define VTK_STYLE_POLYGONALIZE 1
63 #define VTK_STYLE_RUN_LENGTH 2
64 
65 #define VTK_COLOR_MODE_LUT 0
66 #define VTK_COLOR_MODE_LINEAR_256 1
67 
68 VTK_ABI_NAMESPACE_BEGIN
69 class vtkDataArray;
70 class vtkEdgeTable;
71 class vtkIdTypeArray;
72 class vtkIntArray;
73 class vtkScalarsToColors;
75 class vtkTimeStamp;
77 
78 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
79 {
80 public:
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83 
87  static vtkImageToPolyDataFilter* New();
88 
90 
98  vtkSetClampMacro(OutputStyle, int, VTK_STYLE_PIXELIZE, VTK_STYLE_RUN_LENGTH);
99  vtkGetMacro(OutputStyle, int);
100  void SetOutputStyleToPixelize() { this->SetOutputStyle(VTK_STYLE_PIXELIZE); }
101  void SetOutputStyleToPolygonalize() { this->SetOutputStyle(VTK_STYLE_POLYGONALIZE); }
102  void SetOutputStyleToRunLength() { this->SetOutputStyle(VTK_STYLE_RUN_LENGTH); }
104 
106 
109  vtkSetClampMacro(ColorMode, int, VTK_COLOR_MODE_LUT, VTK_COLOR_MODE_LINEAR_256);
110  vtkGetMacro(ColorMode, int);
111  void SetColorModeToLUT() { this->SetColorMode(VTK_COLOR_MODE_LUT); }
112  void SetColorModeToLinear256() { this->SetColorMode(VTK_COLOR_MODE_LINEAR_256); }
114 
116 
120  virtual void SetLookupTable(vtkScalarsToColors*);
121  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
123 
125 
129  vtkSetMacro(Smoothing, vtkTypeBool);
130  vtkGetMacro(Smoothing, vtkTypeBool);
131  vtkBooleanMacro(Smoothing, vtkTypeBool);
133 
135 
139  vtkSetClampMacro(NumberOfSmoothingIterations, int, 0, VTK_INT_MAX);
140  vtkGetMacro(NumberOfSmoothingIterations, int);
142 
144 
148  vtkSetMacro(Decimation, vtkTypeBool);
149  vtkGetMacro(Decimation, vtkTypeBool);
150  vtkBooleanMacro(Decimation, vtkTypeBool);
152 
154 
160  vtkSetClampMacro(DecimationError, double, 0.0, VTK_DOUBLE_MAX);
161  vtkGetMacro(DecimationError, double);
163 
165 
170  vtkSetClampMacro(Error, int, 0, VTK_INT_MAX);
171  vtkGetMacro(Error, int);
173 
175 
182  vtkSetClampMacro(SubImageSize, int, 10, VTK_INT_MAX);
183  vtkGetMacro(SubImageSize, int);
185 
186 protected:
188  ~vtkImageToPolyDataFilter() override;
189 
191  int FillInputPortInformation(int port, vtkInformation* info) override;
192 
199  int Error;
202 
203  virtual void PixelizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
204  double spacing[3], vtkPolyData* output);
205  virtual void PolygonalizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
206  double spacing[3], vtkPolyData* output);
207  virtual void RunLengthImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
208  double spacing[3], vtkPolyData* output);
209 
210 private:
211  vtkUnsignedCharArray* Table; // color table used to quantize points
212  vtkTimeStamp TableMTime;
213  int* Visited; // traverse & mark connected regions
214  vtkUnsignedCharArray* PolyColors; // the colors of each region -> polygon
215  vtkEdgeTable* EdgeTable; // keep track of intersection points
216  vtkEdgeTable* EdgeUseTable; // keep track of polygons use of edges
217  vtkIntArray* EdgeUses; // the two polygons that use an edge
218  // and point id associated with edge (if any)
219 
220  void BuildTable(unsigned char* inPixels);
221  vtkUnsignedCharArray* QuantizeImage(
222  vtkDataArray* inScalars, int numComp, int type, int dims[3], int ext[4]);
223  int ProcessImage(vtkUnsignedCharArray* pixels, int dims[2]);
224  int BuildEdges(vtkUnsignedCharArray* pixels, int dims[3], double origin[3], double spacing[3],
225  vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
226  void BuildPolygons(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges, int numPolys,
227  vtkUnsignedCharArray* polyColors);
228  void SmoothEdges(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
229  void DecimateEdges(vtkPolyData* edges, vtkUnsignedCharArray* pointDescr, double tol2);
230  void GeneratePolygons(vtkPolyData* edges, int numPolys, vtkPolyData* output,
231  vtkUnsignedCharArray* polyColors, vtkUnsignedCharArray* pointDescr);
232 
233  int GetNeighbors(
234  unsigned char* ptr, int& i, int& j, int dims[2], unsigned char* neighbors[4], int mode);
235 
236  void GetIJ(int id, int& i, int& j, int dims[2]);
237  unsigned char* GetColor(unsigned char* rgb);
238  int IsSameColor(unsigned char* p1, unsigned char* p2);
239 
241  void operator=(const vtkImageToPolyDataFilter&) = delete;
242 };
243 
244 VTK_ABI_NAMESPACE_END
245 #endif
generate linear primitives (vtkPolyData) from an image
#define VTK_STYLE_RUN_LENGTH
#define VTK_DOUBLE_MAX
Definition: vtkType.h:154
Store vtkAlgorithm input/output information.
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
#define VTK_INT_MAX
Definition: vtkType.h:144
record modification and/or execution time
Definition: vtkTimeStamp.h:24
dynamic, self-adjusting array of vtkIdType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:29
static vtkPolyDataAlgorithm * New()
int vtkTypeBool
Definition: vtkABI.h:64
Superclass for mapping scalar values to colors.
void SetColorModeToLUT()
Specify how to quantize color.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:34
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:28
#define VTK_STYLE_PIXELIZE
void SetColorModeToLinear256()
Specify how to quantize color.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
dynamic, self-adjusting array of unsigned char
A subclass of ImageData.
void SetOutputStyleToRunLength()
Specify how to create the output.
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
Store zero or more vtkInformation instances.
#define VTK_STYLE_POLYGONALIZE
void SetOutputStyleToPixelize()
Specify how to create the output.
#define VTK_COLOR_MODE_LINEAR_256
#define VTK_COLOR_MODE_LUT
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetOutputStyleToPolygonalize()
Specify how to create the output.
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)