00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00093 #ifndef __vtkImageToPolyDataFilter_h
00094 #define __vtkImageToPolyDataFilter_h
00095
00096 #include "vtkStructuredPointsToPolyDataFilter.h"
00097 #include "vtkScalarsToColors.h"
00098
00099 #define VTK_STYLE_PIXELIZE 0
00100 #define VTK_STYLE_POLYGONALIZE 1
00101 #define VTK_STYLE_RUN_LENGTH 2
00102
00103 #define VTK_COLOR_MODE_LUT 0
00104 #define VTK_COLOR_MODE_LINEAR_256 1
00105
00106 class vtkStructuredPoints;
00107 class vtkEdgeTable;
00108 class vtkScalars;
00109 class vtkAppendPolyData;
00110
00111 class VTK_EXPORT vtkImageToPolyDataFilter : public vtkStructuredPointsToPolyDataFilter
00112 {
00113 public:
00114 vtkTypeMacro(vtkImageToPolyDataFilter,vtkStructuredPointsToPolyDataFilter);
00115 void PrintSelf(ostream& os, vtkIndent indent);
00116
00118 static vtkImageToPolyDataFilter *New()
00119 {return new vtkImageToPolyDataFilter;};
00120
00127 vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
00128 vtkGetMacro(OutputStyle,int);
00129 void SetOutputStyleToPixelize()
00130 {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
00131 void SetOutputStyleToPolygonalize()
00132 {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
00133 void SetOutputStyleToRunLength()
00134 {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
00135
00137 vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
00138 vtkGetMacro(ColorMode,int);
00139 void SetColorModeToLUT()
00140 {this->SetColorMode(VTK_COLOR_MODE_LUT);};
00141 void SetColorModeToLinear256()
00142 {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
00143
00146 vtkSetObjectMacro(LookupTable,vtkScalarsToColors);
00147 vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
00148
00151 vtkSetMacro(Smoothing, int);
00152 vtkGetMacro(Smoothing, int);
00153 vtkBooleanMacro(Smoothing, int);
00154
00157 vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_LARGE_INTEGER);
00158 vtkGetMacro(NumberOfSmoothingIterations,int);
00159
00162 vtkSetMacro(Decimation, int);
00163 vtkGetMacro(Decimation, int);
00164 vtkBooleanMacro(Decimation, int);
00165
00167 vtkSetClampMacro(DecimationError,float,0.0,VTK_LARGE_FLOAT);
00168 vtkGetMacro(DecimationError,float);
00169
00173 vtkSetClampMacro(Error,int,0,VTK_LARGE_INTEGER);
00174 vtkGetMacro(Error,int);
00175
00181 vtkSetClampMacro(SubImageSize,int,10,VTK_LARGE_INTEGER);
00182 vtkGetMacro(SubImageSize,int);
00183
00184 protected:
00185 vtkImageToPolyDataFilter();
00186 ~vtkImageToPolyDataFilter();
00187 vtkImageToPolyDataFilter(const vtkImageToPolyDataFilter&) {};
00188 void operator=(const vtkImageToPolyDataFilter&) {};
00189
00190 void Execute();
00191
00192 int OutputStyle;
00193 int ColorMode;
00194 int Smoothing;
00195 int NumberOfSmoothingIterations;
00196 int Decimation;
00197 float DecimationError;
00198 int Error;
00199 int SubImageSize;
00200 vtkScalarsToColors *LookupTable;
00201
00202 virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
00203 float origin[3], float spacing[3],
00204 vtkPolyData *output);
00205 virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
00206 float origin[3], float spacing[3],
00207 vtkPolyData *output);
00208 virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
00209 float origin[3], float spacing[3],
00210 vtkPolyData *output);
00211 private:
00212 vtkUnsignedCharArray *Table;
00213 vtkTimeStamp TableMTime;
00214 int *Visited;
00215 vtkUnsignedCharArray *PolyColors;
00216 vtkEdgeTable *EdgeTable;
00217 vtkEdgeTable *EdgeUseTable;
00218 vtkIntArray *EdgeUses;
00219
00220
00221 vtkAppendPolyData *Append;
00222
00223 void BuildTable(unsigned char *inPixels);
00224 vtkUnsignedCharArray *QuantizeImage(vtkScalars *inScalars, int numComp,
00225 int type, int dims[3], int ext[4]);
00226 int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
00227 int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], float origin[3],
00228 float spacing[3], vtkUnsignedCharArray *pointDescr,
00229 vtkPolyData *edges);
00230 void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
00231 int numPolys, vtkUnsignedCharArray *polyColors);
00232 void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
00233 void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
00234 float tol2);
00235 void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
00236 vtkUnsignedCharArray *polyColors,
00237 vtkUnsignedCharArray *pointDescr);
00238
00239 int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
00240 unsigned char *neighbors[4], int mode);
00241
00242 void GetIJ(int id, int &i, int &j, int dims[3]);
00243 unsigned char *GetColor(unsigned char *rgb);
00244 int IsSameColor(unsigned char *p1, unsigned char *p2);
00245
00246 };
00247
00248 #endif
00249