VTK  9.2.6
vtkImageToPolyDataFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkImageToPolyDataFilter.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
76 #ifndef vtkImageToPolyDataFilter_h
77 #define vtkImageToPolyDataFilter_h
78 
79 #include "vtkFiltersHybridModule.h" // For export macro
80 #include "vtkPolyDataAlgorithm.h"
81 
82 #define VTK_STYLE_PIXELIZE 0
83 #define VTK_STYLE_POLYGONALIZE 1
84 #define VTK_STYLE_RUN_LENGTH 2
85 
86 #define VTK_COLOR_MODE_LUT 0
87 #define VTK_COLOR_MODE_LINEAR_256 1
88 
89 class vtkDataArray;
90 class vtkEdgeTable;
91 class vtkIdTypeArray;
92 class vtkIntArray;
93 class vtkScalarsToColors;
95 class vtkTimeStamp;
97 
98 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
99 {
100 public:
102  void PrintSelf(ostream& os, vtkIndent indent) override;
103 
108 
110 
118  vtkSetClampMacro(OutputStyle, int, VTK_STYLE_PIXELIZE, VTK_STYLE_RUN_LENGTH);
119  vtkGetMacro(OutputStyle, int);
120  void SetOutputStyleToPixelize() { this->SetOutputStyle(VTK_STYLE_PIXELIZE); }
121  void SetOutputStyleToPolygonalize() { this->SetOutputStyle(VTK_STYLE_POLYGONALIZE); }
122  void SetOutputStyleToRunLength() { this->SetOutputStyle(VTK_STYLE_RUN_LENGTH); }
124 
126 
129  vtkSetClampMacro(ColorMode, int, VTK_COLOR_MODE_LUT, VTK_COLOR_MODE_LINEAR_256);
130  vtkGetMacro(ColorMode, int);
131  void SetColorModeToLUT() { this->SetColorMode(VTK_COLOR_MODE_LUT); }
132  void SetColorModeToLinear256() { this->SetColorMode(VTK_COLOR_MODE_LINEAR_256); }
134 
136 
141  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
143 
145 
149  vtkSetMacro(Smoothing, vtkTypeBool);
150  vtkGetMacro(Smoothing, vtkTypeBool);
151  vtkBooleanMacro(Smoothing, vtkTypeBool);
153 
155 
159  vtkSetClampMacro(NumberOfSmoothingIterations, int, 0, VTK_INT_MAX);
160  vtkGetMacro(NumberOfSmoothingIterations, int);
162 
164 
168  vtkSetMacro(Decimation, vtkTypeBool);
169  vtkGetMacro(Decimation, vtkTypeBool);
170  vtkBooleanMacro(Decimation, vtkTypeBool);
172 
174 
180  vtkSetClampMacro(DecimationError, double, 0.0, VTK_DOUBLE_MAX);
181  vtkGetMacro(DecimationError, double);
183 
185 
190  vtkSetClampMacro(Error, int, 0, VTK_INT_MAX);
191  vtkGetMacro(Error, int);
193 
195 
202  vtkSetClampMacro(SubImageSize, int, 10, VTK_INT_MAX);
203  vtkGetMacro(SubImageSize, int);
205 
206 protected:
209 
212 
219  int Error;
222 
223  virtual void PixelizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
224  double spacing[3], vtkPolyData* output);
225  virtual void PolygonalizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
226  double spacing[3], vtkPolyData* output);
227  virtual void RunLengthImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
228  double spacing[3], vtkPolyData* output);
229 
230 private:
231  vtkUnsignedCharArray* Table; // color table used to quantize points
232  vtkTimeStamp TableMTime;
233  int* Visited; // traverse & mark connected regions
234  vtkUnsignedCharArray* PolyColors; // the colors of each region -> polygon
235  vtkEdgeTable* EdgeTable; // keep track of intersection points
236  vtkEdgeTable* EdgeUseTable; // keep track of polygons use of edges
237  vtkIntArray* EdgeUses; // the two polygons that use an edge
238  // and point id associated with edge (if any)
239 
240  void BuildTable(unsigned char* inPixels);
241  vtkUnsignedCharArray* QuantizeImage(
242  vtkDataArray* inScalars, int numComp, int type, int dims[3], int ext[4]);
243  int ProcessImage(vtkUnsignedCharArray* pixels, int dims[2]);
244  int BuildEdges(vtkUnsignedCharArray* pixels, int dims[3], double origin[3], double spacing[3],
245  vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
246  void BuildPolygons(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges, int numPolys,
247  vtkUnsignedCharArray* polyColors);
248  void SmoothEdges(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
249  void DecimateEdges(vtkPolyData* edges, vtkUnsignedCharArray* pointDescr, double tol2);
250  void GeneratePolygons(vtkPolyData* edges, int numPolys, vtkPolyData* output,
251  vtkUnsignedCharArray* polyColors, vtkUnsignedCharArray* pointDescr);
252 
253  int GetNeighbors(
254  unsigned char* ptr, int& i, int& j, int dims[3], unsigned char* neighbors[4], int mode);
255 
256  void GetIJ(int id, int& i, int& j, int dims[2]);
257  unsigned char* GetColor(unsigned char* rgb);
258  int IsSameColor(unsigned char* p1, unsigned char* p2);
259 
260 private:
262  void operator=(const vtkImageToPolyDataFilter&) = delete;
263 };
264 
265 #endif
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:65
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:41
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:49
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:55
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:100
Superclass for mapping scalar values to colors.
A subclass of ImageData.
record modification and/or execution time
Definition: vtkTimeStamp.h:45
dynamic, self-adjusting array of unsigned char
@ info
Definition: vtkX3D.h:382
@ mode
Definition: vtkX3D.h:253
@ port
Definition: vtkX3D.h:453
@ type
Definition: vtkX3D.h:522
@ spacing
Definition: vtkX3D.h:487
int vtkTypeBool
Definition: vtkABI.h:69
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:165
#define VTK_INT_MAX
Definition: vtkType.h:155