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 =========================================================================*/
64 #ifndef vtkImageToPolyDataFilter_h
65 #define vtkImageToPolyDataFilter_h
66 
67 #include "vtkFiltersHybridModule.h" // For export macro
68 #include "vtkPolyDataAlgorithm.h"
69 
70 #define VTK_STYLE_PIXELIZE 0
71 #define VTK_STYLE_POLYGONALIZE 1
72 #define VTK_STYLE_RUN_LENGTH 2
73 
74 #define VTK_COLOR_MODE_LUT 0
75 #define VTK_COLOR_MODE_LINEAR_256 1
76 
77 class vtkDataArray;
78 class vtkEdgeTable;
79 class vtkIdTypeArray;
80 class vtkIntArray;
81 class vtkScalarsToColors;
83 class vtkTimeStamp;
85 
86 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
87 {
88 public:
90  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
95  static vtkImageToPolyDataFilter* New();
96 
98 
106  vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
107  vtkGetMacro(OutputStyle,int);
109  {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
111  {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
113  {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
115 
117 
120  vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
121  vtkGetMacro(ColorMode,int);
123  {this->SetColorMode(VTK_COLOR_MODE_LUT);};
125  {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
127 
129 
133  virtual void SetLookupTable(vtkScalarsToColors*);
134  vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
136 
138 
142  vtkSetMacro(Smoothing, vtkTypeBool);
143  vtkGetMacro(Smoothing, vtkTypeBool);
144  vtkBooleanMacro(Smoothing, vtkTypeBool);
146 
148 
152  vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_INT_MAX);
153  vtkGetMacro(NumberOfSmoothingIterations,int);
155 
157 
161  vtkSetMacro(Decimation, vtkTypeBool);
162  vtkGetMacro(Decimation, vtkTypeBool);
163  vtkBooleanMacro(Decimation, vtkTypeBool);
165 
167 
173  vtkSetClampMacro(DecimationError,double,0.0,VTK_DOUBLE_MAX);
174  vtkGetMacro(DecimationError,double);
176 
178 
183  vtkSetClampMacro(Error,int,0,VTK_INT_MAX);
184  vtkGetMacro(Error,int);
186 
188 
195  vtkSetClampMacro(SubImageSize,int,10,VTK_INT_MAX);
196  vtkGetMacro(SubImageSize,int);
198 
199 protected:
201  ~vtkImageToPolyDataFilter() override;
202 
204  int FillInputPortInformation(int port, vtkInformation *info) override;
205 
212  int Error;
215 
216  virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
217  double origin[3], double spacing[3],
218  vtkPolyData *output);
219  virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
220  double origin[3], double spacing[3],
221  vtkPolyData *output);
222  virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
223  double origin[3], double spacing[3],
224  vtkPolyData *output);
225 private:
226  vtkUnsignedCharArray *Table; // color table used to quantize points
227  vtkTimeStamp TableMTime;
228  int *Visited; // traverse & mark connected regions
229  vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
230  vtkEdgeTable *EdgeTable; // keep track of intersection points
231  vtkEdgeTable *EdgeUseTable; // keep track of polygons use of edges
232  vtkIntArray *EdgeUses; //the two polygons that use an edge
233  //and point id associated with edge (if any)
234 
235  void BuildTable(unsigned char *inPixels);
236  vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
237  int type, int dims[3], int ext[4]);
238  int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
239  int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], double origin[3],
240  double spacing[3], vtkUnsignedCharArray *pointDescr,
241  vtkPolyData *edges);
242  void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
243  int numPolys, vtkUnsignedCharArray *polyColors);
244  void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
245  void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
246  double tol2);
247  void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
248  vtkUnsignedCharArray *polyColors,
249  vtkUnsignedCharArray *pointDescr);
250 
251  int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
252  unsigned char *neighbors[4], int mode);
253 
254  void GetIJ(int id, int &i, int &j, int dims[2]);
255  unsigned char *GetColor(unsigned char *rgb);
256  int IsSameColor(unsigned char *p1, unsigned char *p2);
257 
258 private:
260  void operator=(const vtkImageToPolyDataFilter&) = delete;
261 };
262 
263 #endif
generate linear primitives (vtkPolyData) from an image
#define VTK_STYLE_RUN_LENGTH
#define VTK_DOUBLE_MAX
Definition: vtkType.h:167
Store vtkAlgorithm input/output information.
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
#define VTK_INT_MAX
Definition: vtkType.h:157
record modification and/or execution time
Definition: vtkTimeStamp.h:32
dynamic, self-adjusting array of vtkIdType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:40
static vtkPolyDataAlgorithm * New()
int vtkTypeBool
Definition: vtkABI.h:69
Superclass for mapping scalar values to colors.
void SetColorModeToLUT()
Specify how to quantize color.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:39
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:33
#define VTK_STYLE_PIXELIZE
void SetColorModeToLinear256()
Specify how to quantize color.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
dynamic, self-adjusting array of unsigned char
A subclass of ImageData.
void SetOutputStyleToRunLength()
Specify how to create the output.
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
Store zero or more vtkInformation instances.
#define VTK_STYLE_POLYGONALIZE
void SetOutputStyleToPixelize()
Specify how to create the output.
#define VTK_COLOR_MODE_LINEAR_256
#define VTK_COLOR_MODE_LUT
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
void SetOutputStyleToPolygonalize()
Specify how to create the output.