VTK
dox/Filters/Hybrid/vtkImageToPolyDataFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkImageToPolyDataFilter.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00066 #ifndef __vtkImageToPolyDataFilter_h
00067 #define __vtkImageToPolyDataFilter_h
00068 
00069 #include "vtkFiltersHybridModule.h" // For export macro
00070 #include "vtkPolyDataAlgorithm.h"
00071 
00072 #define VTK_STYLE_PIXELIZE 0
00073 #define VTK_STYLE_POLYGONALIZE 1
00074 #define VTK_STYLE_RUN_LENGTH 2
00075 
00076 #define VTK_COLOR_MODE_LUT 0
00077 #define VTK_COLOR_MODE_LINEAR_256 1
00078 
00079 class vtkAppendPolyData;
00080 class vtkDataArray;
00081 class vtkEdgeTable;
00082 class vtkIdTypeArray;
00083 class vtkIntArray;
00084 class vtkScalarsToColors;
00085 class vtkStructuredPoints;
00086 class vtkTimeStamp;
00087 class vtkUnsignedCharArray;
00088 
00089 class VTKFILTERSHYBRID_EXPORT vtkImageToPolyDataFilter : public vtkPolyDataAlgorithm
00090 {
00091 public:
00092   vtkTypeMacro(vtkImageToPolyDataFilter,vtkPolyDataAlgorithm);
00093   void PrintSelf(ostream& os, vtkIndent indent);
00094 
00096   static vtkImageToPolyDataFilter* New();
00097 
00099 
00105   vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
00106   vtkGetMacro(OutputStyle,int);
00107   void SetOutputStyleToPixelize()
00108     {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
00109   void SetOutputStyleToPolygonalize()
00110     {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
00111   void SetOutputStyleToRunLength()
00112     {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
00114 
00116 
00117   vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
00118   vtkGetMacro(ColorMode,int);
00119   void SetColorModeToLUT()
00120     {this->SetColorMode(VTK_COLOR_MODE_LUT);};
00121   void SetColorModeToLinear256()
00122     {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
00124 
00126 
00128   virtual void SetLookupTable(vtkScalarsToColors*);
00129   vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
00131 
00133 
00135   vtkSetMacro(Smoothing, int);
00136   vtkGetMacro(Smoothing, int);
00137   vtkBooleanMacro(Smoothing, int);
00139 
00141 
00143   vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_INT_MAX);
00144   vtkGetMacro(NumberOfSmoothingIterations,int);
00146 
00148 
00150   vtkSetMacro(Decimation, int);
00151   vtkGetMacro(Decimation, int);
00152   vtkBooleanMacro(Decimation, int);
00154 
00156 
00160   vtkSetClampMacro(DecimationError,double,0.0,VTK_DOUBLE_MAX);
00161   vtkGetMacro(DecimationError,double);
00163 
00165 
00168   vtkSetClampMacro(Error,int,0,VTK_INT_MAX);
00169   vtkGetMacro(Error,int);
00171 
00173 
00178   vtkSetClampMacro(SubImageSize,int,10,VTK_INT_MAX);
00179   vtkGetMacro(SubImageSize,int);
00181 
00182 protected:
00183   vtkImageToPolyDataFilter();
00184   ~vtkImageToPolyDataFilter();
00185 
00186   virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
00187   virtual int FillInputPortInformation(int port, vtkInformation *info);
00188 
00189   int OutputStyle;
00190   int ColorMode;
00191   int Smoothing;
00192   int NumberOfSmoothingIterations;
00193   int Decimation;
00194   double DecimationError;
00195   int Error;
00196   int SubImageSize;
00197   vtkScalarsToColors *LookupTable;
00198 
00199   virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3],
00200                              double origin[3], double spacing[3],
00201                              vtkPolyData *output);
00202   virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3],
00203                                  double origin[3], double spacing[3],
00204                                  vtkPolyData *output);
00205   virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3],
00206                               double origin[3], double spacing[3],
00207                               vtkPolyData *output);
00208 private:
00209   vtkUnsignedCharArray *Table;      // color table used to quantize points
00210   vtkTimeStamp         TableMTime;
00211   int                  *Visited;    // traverse & mark connected regions
00212   vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
00213   vtkEdgeTable         *EdgeTable;  // keep track of intersection points
00214   vtkEdgeTable         *EdgeUseTable; // keep track of polygons use of edges
00215   vtkIntArray          *EdgeUses; //the two polygons that use an edge
00216                                   //and point id associated with edge (if any)
00217 
00218   vtkAppendPolyData    *Append;
00219 
00220   void BuildTable(unsigned char *inPixels);
00221   vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
00222                                           int type, int dims[3], int ext[4]);
00223   int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
00224   int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], double origin[3],
00225                  double spacing[3], vtkUnsignedCharArray *pointDescr,
00226                  vtkPolyData *edges);
00227   void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
00228                      int numPolys, vtkUnsignedCharArray *polyColors);
00229   void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
00230   void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
00231                      double tol2);
00232   void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
00233                         vtkUnsignedCharArray *polyColors,
00234                         vtkUnsignedCharArray *pointDescr);
00235 
00236   int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
00237                    unsigned char *neighbors[4], int mode);
00238 
00239   void GetIJ(int id, int &i, int &j, int dims[3]);
00240   unsigned char *GetColor(unsigned char *rgb);
00241   int IsSameColor(unsigned char *p1, unsigned char *p2);
00242 
00243 private:
00244   vtkImageToPolyDataFilter(const vtkImageToPolyDataFilter&);  // Not implemented.
00245   void operator=(const vtkImageToPolyDataFilter&);  // Not implemented.
00246 };
00247 
00248 #endif