00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00076 #ifndef __vtkImageToPolyDataFilter_h
00077 #define __vtkImageToPolyDataFilter_h
00078
00079 #include "vtkStructuredPointsToPolyDataFilter.h"
00080
00081 #define VTK_STYLE_PIXELIZE 0
00082 #define VTK_STYLE_POLYGONALIZE 1
00083 #define VTK_STYLE_RUN_LENGTH 2
00084
00085 #define VTK_COLOR_MODE_LUT 0
00086 #define VTK_COLOR_MODE_LINEAR_256 1
00087
00088 class vtkAppendPolyData;
00089 class vtkDataArray;
00090 class vtkEdgeTable;
00091 class vtkIdTypeArray;
00092 class vtkIntArray;
00093 class vtkScalarsToColors;
00094 class vtkStructuredPoints;
00095 class vtkTimeStamp;
00096 class vtkUnsignedCharArray;
00097
00098 class VTK_HYBRID_EXPORT vtkImageToPolyDataFilter : public vtkStructuredPointsToPolyDataFilter
00099 {
00100 public:
00101 vtkTypeRevisionMacro(vtkImageToPolyDataFilter,vtkStructuredPointsToPolyDataFilter);
00102 void PrintSelf(ostream& os, vtkIndent indent);
00103
00105 static vtkImageToPolyDataFilter* New();
00106
00108
00114 vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
00115 vtkGetMacro(OutputStyle,int);
00116 void SetOutputStyleToPixelize()
00117 {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
00118 void SetOutputStyleToPolygonalize()
00119 {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
00120 void SetOutputStyleToRunLength()
00121 {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
00123
00125
00126 vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
00127 vtkGetMacro(ColorMode,int);
00128 void SetColorModeToLUT()
00129 {this->SetColorMode(VTK_COLOR_MODE_LUT);};
00130 void SetColorModeToLinear256()
00131 {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
00133
00135
00137 virtual void SetLookupTable(vtkScalarsToColors*);
00138 vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
00140
00142
00144 vtkSetMacro(Smoothing, int);
00145 vtkGetMacro(Smoothing, int);
00146 vtkBooleanMacro(Smoothing, int);
00148
00150
00152 vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_LARGE_INTEGER);
00153 vtkGetMacro(NumberOfSmoothingIterations,int);
00155
00157
00159 vtkSetMacro(Decimation, int);
00160 vtkGetMacro(Decimation, int);
00161 vtkBooleanMacro(Decimation, int);
00163
00165
00169 vtkSetClampMacro(DecimationError,double,0.0,VTK_DOUBLE_MAX);
00170 vtkGetMacro(DecimationError,double);
00172
00174
00177 vtkSetClampMacro(Error,int,0,VTK_LARGE_INTEGER);
00178 vtkGetMacro(Error,int);
00180
00182
00187 vtkSetClampMacro(SubImageSize,int,10,VTK_LARGE_INTEGER);
00188 vtkGetMacro(SubImageSize,int);
00190
00191 protected:
00192 vtkImageToPolyDataFilter();
00193 ~vtkImageToPolyDataFilter();
00194
00195 void Execute();
00196
00197 int OutputStyle;
00198 int ColorMode;
00199 int Smoothing;
00200 int NumberOfSmoothingIterations;
00201 int Decimation;
00202 double DecimationError;
00203 int Error;
00204 int SubImageSize;
00205 vtkScalarsToColors *LookupTable;
00206
00207 virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
00208 double origin[3], double spacing[3],
00209 vtkPolyData *output);
00210 virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
00211 double origin[3], double spacing[3],
00212 vtkPolyData *output);
00213 virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
00214 double origin[3], double spacing[3],
00215 vtkPolyData *output);
00216 private:
00217 vtkUnsignedCharArray *Table;
00218 vtkTimeStamp TableMTime;
00219 int *Visited;
00220 vtkUnsignedCharArray *PolyColors;
00221 vtkEdgeTable *EdgeTable;
00222 vtkEdgeTable *EdgeUseTable;
00223 vtkIntArray *EdgeUses;
00224
00225
00226 vtkAppendPolyData *Append;
00227
00228 void BuildTable(unsigned char *inPixels);
00229 vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
00230 int type, int dims[3], int ext[4]);
00231 int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
00232 int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], double origin[3],
00233 double spacing[3], vtkUnsignedCharArray *pointDescr,
00234 vtkPolyData *edges);
00235 void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
00236 int numPolys, vtkUnsignedCharArray *polyColors);
00237 void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
00238 void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
00239 double tol2);
00240 void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
00241 vtkUnsignedCharArray *polyColors,
00242 vtkUnsignedCharArray *pointDescr);
00243
00244 int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
00245 unsigned char *neighbors[4], int mode);
00246
00247 void GetIJ(int id, int &i, int &j, int dims[3]);
00248 unsigned char *GetColor(unsigned char *rgb);
00249 int IsSameColor(unsigned char *p1, unsigned char *p2);
00250
00251 private:
00252 vtkImageToPolyDataFilter(const vtkImageToPolyDataFilter&);
00253 void operator=(const vtkImageToPolyDataFilter&);
00254 };
00255
00256 #endif
00257