VTK  9.3.0
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
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
68VTK_ABI_NAMESPACE_BEGIN
69class vtkDataArray;
70class vtkEdgeTable;
71class vtkIdTypeArray;
72class vtkIntArray;
75class vtkTimeStamp;
77
78class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
79{
80public:
82 void PrintSelf(ostream& os, vtkIndent indent) override;
83
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); }
114
116
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
186protected:
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
210private:
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],
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
244VTK_ABI_NAMESPACE_END
245#endif
abstract superclass for arrays of numeric data
keep track of edges (edge is pair of integer id's)
dynamic, self-adjusting array of vtkIdType
generate linear primitives (vtkPolyData) from an image
virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3], double origin[3], double spacing[3], vtkPolyData *output)
void SetColorModeToLinear256()
Specify how to quantize color.
static vtkImageToPolyDataFilter * New()
Instantiate object with initial number of colors 256.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
void SetOutputStyleToPixelize()
Specify how to create the output.
void SetOutputStyleToPolygonalize()
Specify how to create the output.
void SetColorModeToLUT()
Specify how to quantize color.
virtual void SetLookupTable(vtkScalarsToColors *)
Set/Get the vtkLookupTable to use.
virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3], double origin[3], double spacing[3], vtkPolyData *output)
~vtkImageToPolyDataFilter() override
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3], double origin[3], double spacing[3], vtkPolyData *output)
void SetOutputStyleToRunLength()
Specify how to create the output.
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
dynamic, self-adjusting array of int
Definition vtkIntArray.h:35
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:80
Superclass for mapping scalar values to colors.
A subclass of ImageData.
record modification and/or execution time
dynamic, self-adjusting array of unsigned char
int vtkTypeBool
Definition vtkABI.h:64
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
#define VTK_COLOR_MODE_LINEAR_256
#define VTK_COLOR_MODE_LUT
#define VTK_STYLE_POLYGONALIZE
#define VTK_STYLE_PIXELIZE
#define VTK_STYLE_RUN_LENGTH
#define VTK_DOUBLE_MAX
Definition vtkType.h:154
#define VTK_INT_MAX
Definition vtkType.h:144