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 "vtkPolyDataAlgorithm.h"
70 
71 #define VTK_STYLE_PIXELIZE 0
72 #define VTK_STYLE_POLYGONALIZE 1
73 #define VTK_STYLE_RUN_LENGTH 2
74 
75 #define VTK_COLOR_MODE_LUT 0
76 #define VTK_COLOR_MODE_LINEAR_256 1
77 
78 class vtkAppendPolyData;
79 class vtkDataArray;
80 class vtkEdgeTable;
81 class vtkIdTypeArray;
82 class vtkIntArray;
83 class vtkScalarsToColors;
85 class vtkTimeStamp;
87 
89 {
90 public:
92  void PrintSelf(ostream& os, vtkIndent indent);
93 
95  static vtkImageToPolyDataFilter* New();
96 
98 
104  vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
105  vtkGetMacro(OutputStyle,int);
107  {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
109  {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
111  {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
113 
115 
116  vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
117  vtkGetMacro(ColorMode,int);
119  {this->SetColorMode(VTK_COLOR_MODE_LUT);};
121  {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
123 
125 
127  virtual void SetLookupTable(vtkScalarsToColors*);
128  vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
130 
132 
134  vtkSetMacro(Smoothing, int);
135  vtkGetMacro(Smoothing, int);
136  vtkBooleanMacro(Smoothing, int);
138 
140 
142  vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_LARGE_INTEGER);
143  vtkGetMacro(NumberOfSmoothingIterations,int);
145 
147 
149  vtkSetMacro(Decimation, int);
150  vtkGetMacro(Decimation, int);
151  vtkBooleanMacro(Decimation, int);
153 
155 
159  vtkSetClampMacro(DecimationError,double,0.0,VTK_DOUBLE_MAX);
160  vtkGetMacro(DecimationError,double);
162 
164 
167  vtkSetClampMacro(Error,int,0,VTK_LARGE_INTEGER);
168  vtkGetMacro(Error,int);
170 
172 
177  vtkSetClampMacro(SubImageSize,int,10,VTK_LARGE_INTEGER);
178  vtkGetMacro(SubImageSize,int);
180 
181 protected:
184 
187 
194  int Error;
197 
198  virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
199  double origin[3], double spacing[3],
200  vtkPolyData *output);
201  virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
202  double origin[3], double spacing[3],
203  vtkPolyData *output);
204  virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
205  double origin[3], double spacing[3],
206  vtkPolyData *output);
207 private:
208  vtkUnsignedCharArray *Table; // color table used to quantize points
209  vtkTimeStamp TableMTime;
210  int *Visited; // traverse & mark connected regions
211  vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
212  vtkEdgeTable *EdgeTable; // keep track of intersection points
213  vtkEdgeTable *EdgeUseTable; // keep track of polygons use of edges
214  vtkIntArray *EdgeUses; //the two polygons that use an edge
215  //and point id associated with edge (if any)
216 
217  vtkAppendPolyData *Append;
218 
219  void BuildTable(unsigned char *inPixels);
220  vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
221  int type, int dims[3], int ext[4]);
222  int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
223  int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], double origin[3],
224  double spacing[3], vtkUnsignedCharArray *pointDescr,
225  vtkPolyData *edges);
226  void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
227  int numPolys, vtkUnsignedCharArray *polyColors);
228  void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
229  void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
230  double tol2);
231  void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
232  vtkUnsignedCharArray *polyColors,
233  vtkUnsignedCharArray *pointDescr);
234 
235  int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
236  unsigned char *neighbors[4], int mode);
237 
238  void GetIJ(int id, int &i, int &j, int dims[3]);
239  unsigned char *GetColor(unsigned char *rgb);
240  int IsSameColor(unsigned char *p1, unsigned char *p2);
241 
242 private:
243  vtkImageToPolyDataFilter(const vtkImageToPolyDataFilter&); // Not implemented.
244  void operator=(const vtkImageToPolyDataFilter&); // Not implemented.
245 };
246 
247 #endif