VTK  9.3.20240418
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
78 #include "vtkPolyDataAlgorithm.h"
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 
87 VTK_ABI_NAMESPACE_BEGIN
88 class vtkDataArray;
89 class vtkEdgeTable;
90 class vtkIdTypeArray;
91 class vtkIntArray;
92 class vtkScalarsToColors;
94 class vtkTimeStamp;
96 
97 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
98 {
99 public:
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); }
131  void SetColorModeToLinear256() { this->SetColorMode(VTK_COLOR_MODE_LINEAR_256); }
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 
205 protected:
208 
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 
229 private:
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],
244  vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
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 
263 VTK_ABI_NAMESPACE_END
264 #endif
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:155
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:30
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkImageToPolyDataFilter * New()
Instantiate object with initial number of colors 256.
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
Definition: vtkIntArray.h:144
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:181
Superclass for mapping scalar values to colors.
A subclass of ImageData.
record modification and/or execution time
Definition: vtkTimeStamp.h:44
dynamic, self-adjusting array of unsigned char
@ info
Definition: vtkX3D.h:376
@ mode
Definition: vtkX3D.h:247
@ port
Definition: vtkX3D.h:447
@ type
Definition: vtkX3D.h:516
@ spacing
Definition: vtkX3D.h:481
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