VTK  9.1.0
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 =========================================================================*/
83 #ifndef vtkImageToPolyDataFilter_h
84 #define vtkImageToPolyDataFilter_h
85 
86 #include "vtkFiltersHybridModule.h" // For export macro
87 #include "vtkPolyDataAlgorithm.h"
88 
89 #define VTK_STYLE_PIXELIZE 0
90 #define VTK_STYLE_POLYGONALIZE 1
91 #define VTK_STYLE_RUN_LENGTH 2
92 
93 #define VTK_COLOR_MODE_LUT 0
94 #define VTK_COLOR_MODE_LINEAR_256 1
95 
96 class vtkDataArray;
97 class vtkEdgeTable;
98 class vtkIdTypeArray;
99 class vtkIntArray;
100 class vtkScalarsToColors;
101 class vtkStructuredPoints;
102 class vtkTimeStamp;
104 
105 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
106 {
107 public:
109  void PrintSelf(ostream& os, vtkIndent indent) override;
110 
115 
117 
125  vtkSetClampMacro(OutputStyle, int, VTK_STYLE_PIXELIZE, VTK_STYLE_RUN_LENGTH);
126  vtkGetMacro(OutputStyle, int);
127  void SetOutputStyleToPixelize() { this->SetOutputStyle(VTK_STYLE_PIXELIZE); }
128  void SetOutputStyleToPolygonalize() { this->SetOutputStyle(VTK_STYLE_POLYGONALIZE); }
129  void SetOutputStyleToRunLength() { this->SetOutputStyle(VTK_STYLE_RUN_LENGTH); }
131 
133 
136  vtkSetClampMacro(ColorMode, int, VTK_COLOR_MODE_LUT, VTK_COLOR_MODE_LINEAR_256);
137  vtkGetMacro(ColorMode, int);
138  void SetColorModeToLUT() { this->SetColorMode(VTK_COLOR_MODE_LUT); }
139  void SetColorModeToLinear256() { this->SetColorMode(VTK_COLOR_MODE_LINEAR_256); }
141 
143 
148  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
150 
152 
156  vtkSetMacro(Smoothing, vtkTypeBool);
157  vtkGetMacro(Smoothing, vtkTypeBool);
158  vtkBooleanMacro(Smoothing, vtkTypeBool);
160 
162 
166  vtkSetClampMacro(NumberOfSmoothingIterations, int, 0, VTK_INT_MAX);
167  vtkGetMacro(NumberOfSmoothingIterations, int);
169 
171 
175  vtkSetMacro(Decimation, vtkTypeBool);
176  vtkGetMacro(Decimation, vtkTypeBool);
177  vtkBooleanMacro(Decimation, vtkTypeBool);
179 
181 
187  vtkSetClampMacro(DecimationError, double, 0.0, VTK_DOUBLE_MAX);
188  vtkGetMacro(DecimationError, double);
190 
192 
197  vtkSetClampMacro(Error, int, 0, VTK_INT_MAX);
198  vtkGetMacro(Error, int);
200 
202 
209  vtkSetClampMacro(SubImageSize, int, 10, VTK_INT_MAX);
210  vtkGetMacro(SubImageSize, int);
212 
213 protected:
216 
219 
226  int Error;
229 
230  virtual void PixelizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
231  double spacing[3], vtkPolyData* output);
232  virtual void PolygonalizeImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
233  double spacing[3], vtkPolyData* output);
234  virtual void RunLengthImage(vtkUnsignedCharArray* pixels, int dims[3], double origin[3],
235  double spacing[3], vtkPolyData* output);
236 
237 private:
238  vtkUnsignedCharArray* Table; // color table used to quantize points
239  vtkTimeStamp TableMTime;
240  int* Visited; // traverse & mark connected regions
241  vtkUnsignedCharArray* PolyColors; // the colors of each region -> polygon
242  vtkEdgeTable* EdgeTable; // keep track of intersection points
243  vtkEdgeTable* EdgeUseTable; // keep track of polygons use of edges
244  vtkIntArray* EdgeUses; // the two polygons that use an edge
245  // and point id associated with edge (if any)
246 
247  void BuildTable(unsigned char* inPixels);
248  vtkUnsignedCharArray* QuantizeImage(
249  vtkDataArray* inScalars, int numComp, int type, int dims[3], int ext[4]);
250  int ProcessImage(vtkUnsignedCharArray* pixels, int dims[2]);
251  int BuildEdges(vtkUnsignedCharArray* pixels, int dims[3], double origin[3], double spacing[3],
252  vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
253  void BuildPolygons(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges, int numPolys,
254  vtkUnsignedCharArray* polyColors);
255  void SmoothEdges(vtkUnsignedCharArray* pointDescr, vtkPolyData* edges);
256  void DecimateEdges(vtkPolyData* edges, vtkUnsignedCharArray* pointDescr, double tol2);
257  void GeneratePolygons(vtkPolyData* edges, int numPolys, vtkPolyData* output,
258  vtkUnsignedCharArray* polyColors, vtkUnsignedCharArray* pointDescr);
259 
260  int GetNeighbors(
261  unsigned char* ptr, int& i, int& j, int dims[3], unsigned char* neighbors[4], int mode);
262 
263  void GetIJ(int id, int& i, int& j, int dims[2]);
264  unsigned char* GetColor(unsigned char* rgb);
265  int IsSameColor(unsigned char* p1, unsigned char* p2);
266 
267 private:
269  void operator=(const vtkImageToPolyDataFilter&) = delete;
270 };
271 
272 #endif
vtkImageToPolyDataFilter::SetOutputStyleToRunLength
void SetOutputStyleToRunLength()
Specify how to create the output.
Definition: vtkImageToPolyDataFilter.h:129
VTK_INT_MAX
#define VTK_INT_MAX
Definition: vtkType.h:155
vtkStructuredPoints
A subclass of ImageData.
Definition: vtkStructuredPoints.h:125
VTK_STYLE_POLYGONALIZE
#define VTK_STYLE_POLYGONALIZE
Definition: vtkImageToPolyDataFilter.h:90
vtkImageToPolyDataFilter::ColorMode
int ColorMode
Definition: vtkImageToPolyDataFilter.h:221
vtkImageToPolyDataFilter::vtkImageToPolyDataFilter
vtkImageToPolyDataFilter()
VTK_STYLE_PIXELIZE
#define VTK_STYLE_PIXELIZE
Definition: vtkImageToPolyDataFilter.h:89
vtkX3D::type
@ type
Definition: vtkX3D.h:522
vtkImageToPolyDataFilter::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkImageToPolyDataFilter::LookupTable
vtkScalarsToColors * LookupTable
Definition: vtkImageToPolyDataFilter.h:228
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:145
vtkImageToPolyDataFilter
generate linear primitives (vtkPolyData) from an image
Definition: vtkImageToPolyDataFilter.h:106
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:52
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:145
vtkImageToPolyDataFilter::Error
int Error
Definition: vtkImageToPolyDataFilter.h:226
vtkImageToPolyDataFilter::OutputStyle
int OutputStyle
Definition: vtkImageToPolyDataFilter.h:220
vtkImageToPolyDataFilter::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
vtkImageToPolyDataFilter::RunLengthImage
virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3], double origin[3], double spacing[3], vtkPolyData *output)
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
vtkImageToPolyDataFilter::SetColorModeToLinear256
void SetColorModeToLinear256()
Specify how to quantize color.
Definition: vtkImageToPolyDataFilter.h:139
vtkEdgeTable
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:41
VTK_COLOR_MODE_LUT
#define VTK_COLOR_MODE_LUT
Definition: vtkImageToPolyDataFilter.h:93
VTK_COLOR_MODE_LINEAR_256
#define VTK_COLOR_MODE_LINEAR_256
Definition: vtkImageToPolyDataFilter.h:94
vtkImageToPolyDataFilter::PixelizeImage
virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3], double origin[3], double spacing[3], vtkPolyData *output)
vtkPolyDataAlgorithm.h
vtkImageToPolyDataFilter::~vtkImageToPolyDataFilter
~vtkImageToPolyDataFilter() override
vtkX3D::port
@ port
Definition: vtkX3D.h:453
vtkImageToPolyDataFilter::SubImageSize
int SubImageSize
Definition: vtkImageToPolyDataFilter.h:227
vtkImageToPolyDataFilter::New
static vtkImageToPolyDataFilter * New()
Instantiate object with initial number of colors 256.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkIntArray
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:149
vtkImageToPolyDataFilter::Smoothing
vtkTypeBool Smoothing
Definition: vtkImageToPolyDataFilter.h:222
vtkImageToPolyDataFilter::SetColorModeToLUT
void SetColorModeToLUT()
Specify how to quantize color.
Definition: vtkImageToPolyDataFilter.h:138
VTK_STYLE_RUN_LENGTH
#define VTK_STYLE_RUN_LENGTH
Definition: vtkImageToPolyDataFilter.h:91
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:109
vtkImageToPolyDataFilter::SetOutputStyleToPixelize
void SetOutputStyleToPixelize()
Specify how to create the output.
Definition: vtkImageToPolyDataFilter.h:127
vtkX3D::spacing
@ spacing
Definition: vtkX3D.h:487
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:183
vtkX3D::info
@ info
Definition: vtkX3D.h:382
vtkImageToPolyDataFilter::DecimationError
double DecimationError
Definition: vtkImageToPolyDataFilter.h:225
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:145
vtkImageToPolyDataFilter::SetLookupTable
virtual void SetLookupTable(vtkScalarsToColors *)
Set/Get the vtkLookupTable to use.
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:195
vtkImageToPolyDataFilter::SetOutputStyleToPolygonalize
void SetOutputStyleToPolygonalize()
Specify how to create the output.
Definition: vtkImageToPolyDataFilter.h:128
edges
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
Definition: vtkBoostGraphAdapter.h:1027
vtkX3D::mode
@ mode
Definition: vtkX3D.h:253
vtkImageToPolyDataFilter::FillInputPortInformation
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165
vtkImageToPolyDataFilter::Decimation
vtkTypeBool Decimation
Definition: vtkImageToPolyDataFilter.h:224
vtkImageToPolyDataFilter::NumberOfSmoothingIterations
int NumberOfSmoothingIterations
Definition: vtkImageToPolyDataFilter.h:223
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkImageToPolyDataFilter::PolygonalizeImage
virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3], double origin[3], double spacing[3], vtkPolyData *output)
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:151