Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

contrib/vtkImageToPolyDataFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkImageToPolyDataFilter.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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;      // color table used to quantize points
00213   vtkTimeStamp         TableMTime;
00214   int                  *Visited;    // traverse & mark connected regions
00215   vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
00216   vtkEdgeTable         *EdgeTable;  // keep track of intersection points
00217   vtkEdgeTable         *EdgeUseTable; // keep track of polygons use of edges
00218   vtkIntArray          *EdgeUses; //the two polygons that use an edge
00219                                   //and point id associated with edge (if any)
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 

Generated on Wed Nov 21 12:26:55 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001