VTK
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 =========================================================================*/
67 #ifndef vtkImageToPolyDataFilter_h
68 #define vtkImageToPolyDataFilter_h
69 
70 #include "vtkFiltersHybridModule.h" // For export macro
71 #include "vtkPolyDataAlgorithm.h"
72 
73 #define VTK_STYLE_PIXELIZE 0
74 #define VTK_STYLE_POLYGONALIZE 1
75 #define VTK_STYLE_RUN_LENGTH 2
76 
77 #define VTK_COLOR_MODE_LUT 0
78 #define VTK_COLOR_MODE_LINEAR_256 1
79 
80 class vtkDataArray;
81 class vtkEdgeTable;
82 class vtkIdTypeArray;
83 class vtkIntArray;
84 class vtkScalarsToColors;
86 class vtkTimeStamp;
88 
89 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
90 {
91 public:
93  void PrintSelf(ostream& os, vtkIndent indent) override;
94 
98  static vtkImageToPolyDataFilter* New();
99 
101 
109  vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
110  vtkGetMacro(OutputStyle,int);
112  {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
114  {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
116  {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
118 
120 
123  vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
124  vtkGetMacro(ColorMode,int);
126  {this->SetColorMode(VTK_COLOR_MODE_LUT);};
128  {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
130 
132 
136  virtual void SetLookupTable(vtkScalarsToColors*);
137  vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
139 
141 
145  vtkSetMacro(Smoothing, vtkTypeBool);
146  vtkGetMacro(Smoothing, vtkTypeBool);
147  vtkBooleanMacro(Smoothing, vtkTypeBool);
149 
151 
155  vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_INT_MAX);
156  vtkGetMacro(NumberOfSmoothingIterations,int);
158 
160 
164  vtkSetMacro(Decimation, vtkTypeBool);
165  vtkGetMacro(Decimation, vtkTypeBool);
166  vtkBooleanMacro(Decimation, vtkTypeBool);
168 
170 
176  vtkSetClampMacro(DecimationError,double,0.0,VTK_DOUBLE_MAX);
177  vtkGetMacro(DecimationError,double);
179 
181 
186  vtkSetClampMacro(Error,int,0,VTK_INT_MAX);
187  vtkGetMacro(Error,int);
189 
191 
198  vtkSetClampMacro(SubImageSize,int,10,VTK_INT_MAX);
199  vtkGetMacro(SubImageSize,int);
201 
202 protected:
204  ~vtkImageToPolyDataFilter() override;
205 
207  int FillInputPortInformation(int port, vtkInformation *info) override;
208 
215  int Error;
218 
219  virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
220  double origin[3], double spacing[3],
221  vtkPolyData *output);
222  virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
223  double origin[3], double spacing[3],
224  vtkPolyData *output);
225  virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
226  double origin[3], double spacing[3],
227  vtkPolyData *output);
228 private:
229  vtkUnsignedCharArray *Table; // color table used to quantize points
230  vtkTimeStamp TableMTime;
231  int *Visited; // traverse & mark connected regions
232  vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
233  vtkEdgeTable *EdgeTable; // keep track of intersection points
234  vtkEdgeTable *EdgeUseTable; // keep track of polygons use of edges
235  vtkIntArray *EdgeUses; //the two polygons that use an edge
236  //and point id associated with edge (if any)
237 
238  void BuildTable(unsigned char *inPixels);
239  vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
240  int type, int dims[3], int ext[4]);
241  int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
242  int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], double origin[3],
243  double spacing[3], vtkUnsignedCharArray *pointDescr,
244  vtkPolyData *edges);
245  void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
246  int numPolys, vtkUnsignedCharArray *polyColors);
247  void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
248  void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
249  double tol2);
250  void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
251  vtkUnsignedCharArray *polyColors,
252  vtkUnsignedCharArray *pointDescr);
253 
254  int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
255  unsigned char *neighbors[4], int mode);
256 
257  void GetIJ(int id, int &i, int &j, int dims[2]);
258  unsigned char *GetColor(unsigned char *rgb);
259  int IsSameColor(unsigned char *p1, unsigned char *p2);
260 
261 private:
263  void operator=(const vtkImageToPolyDataFilter&) = delete;
264 };
265 
266 #endif
vtkImageToPolyDataFilter::SetOutputStyleToRunLength
void SetOutputStyleToRunLength()
Definition: vtkImageToPolyDataFilter.h:115
VTK_INT_MAX
#define VTK_INT_MAX
Definition: vtkType.h:159
vtkStructuredPoints
A subclass of ImageData.
Definition: vtkStructuredPoints.h:39
edges
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
Definition: vtkBoostGraphAdapter.h:859
VTK_STYLE_POLYGONALIZE
#define VTK_STYLE_POLYGONALIZE
Definition: vtkImageToPolyDataFilter.h:74
vtkImageToPolyDataFilter::ColorMode
int ColorMode
Definition: vtkImageToPolyDataFilter.h:210
VTK_STYLE_PIXELIZE
#define VTK_STYLE_PIXELIZE
Definition: vtkImageToPolyDataFilter.h:73
vtkX3D::type
Definition: vtkX3D.h:516
vtkImageToPolyDataFilter::LookupTable
vtkScalarsToColors * LookupTable
Definition: vtkImageToPolyDataFilter.h:217
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkImageToPolyDataFilter
generate linear primitives (vtkPolyData) from an image
Definition: vtkImageToPolyDataFilter.h:89
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:41
vtkImageToPolyDataFilter::Error
int Error
Definition: vtkImageToPolyDataFilter.h:215
vtkImageToPolyDataFilter::OutputStyle
int OutputStyle
Definition: vtkImageToPolyDataFilter.h:209
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkImageToPolyDataFilter::SetColorModeToLinear256
void SetColorModeToLinear256()
Definition: vtkImageToPolyDataFilter.h:127
vtkPolyDataAlgorithm::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkEdgeTable
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:40
VTK_COLOR_MODE_LUT
#define VTK_COLOR_MODE_LUT
Definition: vtkImageToPolyDataFilter.h:77
VTK_COLOR_MODE_LINEAR_256
#define VTK_COLOR_MODE_LINEAR_256
Definition: vtkImageToPolyDataFilter.h:78
vtkPolyDataAlgorithm.h
vtkX3D::port
Definition: vtkX3D.h:447
vtkImageToPolyDataFilter::SubImageSize
int SubImageSize
Definition: vtkImageToPolyDataFilter.h:216
vtkPolyDataAlgorithm::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkIntArray
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:45
vtkImageToPolyDataFilter::Smoothing
vtkTypeBool Smoothing
Definition: vtkImageToPolyDataFilter.h:211
vtkImageToPolyDataFilter::SetColorModeToLUT
void SetColorModeToLUT()
Definition: vtkImageToPolyDataFilter.h:125
VTK_STYLE_RUN_LENGTH
#define VTK_STYLE_RUN_LENGTH
Definition: vtkImageToPolyDataFilter.h:75
vtkPolyDataAlgorithm::FillInputPortInformation
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:66
vtkImageToPolyDataFilter::SetOutputStyleToPixelize
void SetOutputStyleToPixelize()
Definition: vtkImageToPolyDataFilter.h:111
vtkX3D::spacing
Definition: vtkX3D.h:481
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:86
vtkX3D::info
Definition: vtkX3D.h:376
vtkImageToPolyDataFilter::DecimationError
double DecimationError
Definition: vtkImageToPolyDataFilter.h:214
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:41
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkImageToPolyDataFilter::SetOutputStyleToPolygonalize
void SetOutputStyleToPolygonalize()
Definition: vtkImageToPolyDataFilter.h:113
vtkX3D::mode
Definition: vtkX3D.h:247
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:169
vtkImageToPolyDataFilter::Decimation
vtkTypeBool Decimation
Definition: vtkImageToPolyDataFilter.h:213
vtkImageToPolyDataFilter::NumberOfSmoothingIterations
int NumberOfSmoothingIterations
Definition: vtkImageToPolyDataFilter.h:212
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkPolyDataAlgorithm::New
static vtkPolyDataAlgorithm * New()
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:44