VTK  9.4.20250130
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
74#ifndef vtkImageToPolyDataFilter_h
75#define vtkImageToPolyDataFilter_h
76
77#include "vtkFiltersHybridModule.h" // For export macro
79
80#define VTK_STYLE_PIXELIZE 0
81#define VTK_STYLE_POLYGONALIZE 1
82#define VTK_STYLE_RUN_LENGTH 2
83
84#define VTK_COLOR_MODE_LUT 0
85#define VTK_COLOR_MODE_LINEAR_256 1
86
87VTK_ABI_NAMESPACE_BEGIN
88class vtkDataArray;
89class vtkEdgeTable;
90class vtkIdTypeArray;
91class vtkIntArray;
94class vtkTimeStamp;
96
97class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
98{
99public:
101 void PrintSelf(ostream& os, vtkIndent indent) override;
102
107
109
117 vtkSetClampMacro(OutputStyle, int, VTK_STYLE_PIXELIZE, VTK_STYLE_RUN_LENGTH);
118 vtkGetMacro(OutputStyle, int);
119 void SetOutputStyleToPixelize() { this->SetOutputStyle(VTK_STYLE_PIXELIZE); }
120 void SetOutputStyleToPolygonalize() { this->SetOutputStyle(VTK_STYLE_POLYGONALIZE); }
121 void SetOutputStyleToRunLength() { this->SetOutputStyle(VTK_STYLE_RUN_LENGTH); }
123
125
128 vtkSetClampMacro(ColorMode, int, VTK_COLOR_MODE_LUT, VTK_COLOR_MODE_LINEAR_256);
129 vtkGetMacro(ColorMode, int);
130 void SetColorModeToLUT() { this->SetColorMode(VTK_COLOR_MODE_LUT); }
133
135
140 vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
142
144
148 vtkSetMacro(Smoothing, vtkTypeBool);
149 vtkGetMacro(Smoothing, vtkTypeBool);
150 vtkBooleanMacro(Smoothing, vtkTypeBool);
152
154
158 vtkSetClampMacro(NumberOfSmoothingIterations, int, 0, VTK_INT_MAX);
159 vtkGetMacro(NumberOfSmoothingIterations, int);
161
163
167 vtkSetMacro(Decimation, vtkTypeBool);
168 vtkGetMacro(Decimation, vtkTypeBool);
169 vtkBooleanMacro(Decimation, vtkTypeBool);
171
173
179 vtkSetClampMacro(DecimationError, double, 0.0, VTK_DOUBLE_MAX);
180 vtkGetMacro(DecimationError, double);
182
184
189 vtkSetClampMacro(Error, int, 0, VTK_INT_MAX);
190 vtkGetMacro(Error, int);
192
194
201 vtkSetClampMacro(SubImageSize, int, 10, VTK_INT_MAX);
202 vtkGetMacro(SubImageSize, int);
204
205protected:
208
210 int FillInputPortInformation(int port, vtkInformation* info) override;
211
218 int Error;
221
222 virtual void PixelizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
223 double spacing[3], vtkPolyData* output);
224 virtual void PolygonalizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
225 double spacing[3], vtkPolyData* output);
226 virtual void RunLengthImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
227 double spacing[3], vtkPolyData* output);
228
229private:
230 vtkUnsignedCharArray* Table; // color table used to quantize points
231 vtkTimeStamp TableMTime;
232 int* Visited; // traverse & mark connected regions
233 vtkUnsignedCharArray* PolyColors; // the colors of each region -> polygon
234 vtkEdgeTable* EdgeTable; // keep track of intersection points
235 vtkEdgeTable* EdgeUseTable; // keep track of polygons use of edges
236 vtkIntArray* EdgeUses; // the two polygons that use an edge
237 // and point id associated with edge (if any)
238
239 void BuildTable(unsigned char* inPixels);
240 vtkUnsignedCharArray* QuantizeImage(
241 vtkDataArray* inScalars, int numComp, int type, int dims[3], int ext[4]);
242 int ProcessImage(vtkUnsignedCharArray* pixels, int dims[2]);
243 int BuildEdges(vtkUnsignedCharArray* pixels, int dims[3], double origin[3], double spacing[3],
245 void BuildPolygons(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges, int numPolys,
246 vtkUnsignedCharArray* polyColors);
247 void SmoothEdges(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
248 void DecimateEdges(vtkPolyData* edges, vtkUnsignedCharArray* pointDescr, double tol2);
249 void GeneratePolygons(vtkPolyData* edges, int numPolys, vtkPolyData* output,
250 vtkUnsignedCharArray* polyColors, vtkUnsignedCharArray* pointDescr);
251
252 int GetNeighbors(
253 unsigned char* ptr, int& i, int& j, int dims[2], unsigned char* neighbors[4], int mode);
254
255 void GetIJ(int id, int& i, int& j, int dims[2]);
256 unsigned char* GetColor(unsigned char* rgb);
257 int IsSameColor(unsigned char* p1, unsigned char* p2);
258
260 void operator=(const vtkImageToPolyDataFilter&) = delete;
261};
262
263VTK_ABI_NAMESPACE_END
264#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:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
dynamic, self-adjusting array of int
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
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