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 =========================================================================*/
66 #ifndef vtkImageToPolyDataFilter_h
67 #define vtkImageToPolyDataFilter_h
68 
69 #include "vtkFiltersHybridModule.h" // For export macro
70 #include "vtkPolyDataAlgorithm.h"
71 
72 #define VTK_STYLE_PIXELIZE 0
73 #define VTK_STYLE_POLYGONALIZE 1
74 #define VTK_STYLE_RUN_LENGTH 2
75 
76 #define VTK_COLOR_MODE_LUT 0
77 #define VTK_COLOR_MODE_LINEAR_256 1
78 
79 class vtkAppendPolyData;
80 class vtkDataArray;
81 class vtkEdgeTable;
82 class vtkIdTypeArray;
83 class vtkIntArray;
84 class vtkScalarsToColors;
86 class vtkTimeStamp;
88 
90 {
91 public:
93  void PrintSelf(ostream& os, vtkIndent indent);
94 
96  static vtkImageToPolyDataFilter* New();
97 
99 
105  vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
106  vtkGetMacro(OutputStyle,int);
108  {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
110  {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
112  {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
114 
116 
117  vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
118  vtkGetMacro(ColorMode,int);
120  {this->SetColorMode(VTK_COLOR_MODE_LUT);};
122  {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
124 
126 
128  virtual void SetLookupTable(vtkScalarsToColors*);
129  vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
131 
133 
135  vtkSetMacro(Smoothing, int);
136  vtkGetMacro(Smoothing, int);
137  vtkBooleanMacro(Smoothing, int);
139 
141 
143  vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_INT_MAX);
144  vtkGetMacro(NumberOfSmoothingIterations,int);
146 
148 
150  vtkSetMacro(Decimation, int);
151  vtkGetMacro(Decimation, int);
152  vtkBooleanMacro(Decimation, int);
154 
156 
160  vtkSetClampMacro(DecimationError,double,0.0,VTK_DOUBLE_MAX);
161  vtkGetMacro(DecimationError,double);
163 
165 
168  vtkSetClampMacro(Error,int,0,VTK_INT_MAX);
169  vtkGetMacro(Error,int);
171 
173 
178  vtkSetClampMacro(SubImageSize,int,10,VTK_INT_MAX);
179  vtkGetMacro(SubImageSize,int);
181 
182 protected:
185 
188 
195  int Error;
198 
199  virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
200  double origin[3], double spacing[3],
201  vtkPolyData *output);
202  virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
203  double origin[3], double spacing[3],
204  vtkPolyData *output);
205  virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
206  double origin[3], double spacing[3],
207  vtkPolyData *output);
208 private:
209  vtkUnsignedCharArray *Table; // color table used to quantize points
210  vtkTimeStamp TableMTime;
211  int *Visited; // traverse & mark connected regions
212  vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
213  vtkEdgeTable *EdgeTable; // keep track of intersection points
214  vtkEdgeTable *EdgeUseTable; // keep track of polygons use of edges
215  vtkIntArray *EdgeUses; //the two polygons that use an edge
216  //and point id associated with edge (if any)
217 
218  vtkAppendPolyData *Append;
219 
220  void BuildTable(unsigned char *inPixels);
221  vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
222  int type, int dims[3], int ext[4]);
223  int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
224  int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], double origin[3],
225  double spacing[3], vtkUnsignedCharArray *pointDescr,
226  vtkPolyData *edges);
227  void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
228  int numPolys, vtkUnsignedCharArray *polyColors);
229  void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
230  void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
231  double tol2);
232  void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
233  vtkUnsignedCharArray *polyColors,
234  vtkUnsignedCharArray *pointDescr);
235 
236  int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
237  unsigned char *neighbors[4], int mode);
238 
239  void GetIJ(int id, int &i, int &j, int dims[3]);
240  unsigned char *GetColor(unsigned char *rgb);
241  int IsSameColor(unsigned char *p1, unsigned char *p2);
242 
243 private:
244  vtkImageToPolyDataFilter(const vtkImageToPolyDataFilter&); // Not implemented.
245  void operator=(const vtkImageToPolyDataFilter&); // Not implemented.
246 };
247 
248 #endif
generate linear primitives (vtkPolyData) from an image
virtual int FillInputPortInformation(int port, vtkInformation *info)
#define VTK_STYLE_RUN_LENGTH
#define VTK_DOUBLE_MAX
Definition: vtkType.h:140
Store vtkAlgorithm input/output information.
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
#define VTK_INT_MAX
Definition: vtkType.h:130
record modification and/or execution time
Definition: vtkTimeStamp.h:34
dynamic, self-adjusting array of vtkIdType
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:39
static vtkPolyDataAlgorithm * New()
Superclass for mapping scalar values to colors.
void PrintSelf(ostream &os, vtkIndent indent)
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:49
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:38
#define VTKFILTERSHYBRID_EXPORT
#define VTK_STYLE_PIXELIZE
appends one or more polygonal datasets together
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
dynamic, self-adjusting array of unsigned char
A subclass of ImageData.
Store zero or more vtkInformation instances.
#define VTK_STYLE_POLYGONALIZE
#define VTK_COLOR_MODE_LINEAR_256
#define VTK_COLOR_MODE_LUT
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)