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

Hybrid/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 =========================================================================*/
00094 #ifndef __vtkImageToPolyDataFilter_h
00095 #define __vtkImageToPolyDataFilter_h
00096 
00097 #include "vtkStructuredPointsToPolyDataFilter.h"
00098 #include "vtkScalarsToColors.h"
00099 
00100 #define VTK_STYLE_PIXELIZE 0
00101 #define VTK_STYLE_POLYGONALIZE 1
00102 #define VTK_STYLE_RUN_LENGTH 2
00103 
00104 #define VTK_COLOR_MODE_LUT 0
00105 #define VTK_COLOR_MODE_LINEAR_256 1
00106 
00107 class vtkStructuredPoints;
00108 class vtkEdgeTable;
00109 class vtkAppendPolyData;
00110 
00111 class VTK_HYBRID_EXPORT vtkImageToPolyDataFilter : public vtkStructuredPointsToPolyDataFilter
00112 {
00113 public:
00114   vtkTypeMacro(vtkImageToPolyDataFilter,vtkStructuredPointsToPolyDataFilter);
00115   void PrintSelf(ostream& os, vtkIndent indent);
00116 
00118 
00119   static vtkImageToPolyDataFilter *New() 
00120     {return new vtkImageToPolyDataFilter;};
00122 
00124 
00130   vtkSetClampMacro(OutputStyle,int,VTK_STYLE_PIXELIZE,VTK_STYLE_RUN_LENGTH);
00131   vtkGetMacro(OutputStyle,int);
00132   void SetOutputStyleToPixelize() 
00133     {this->SetOutputStyle(VTK_STYLE_PIXELIZE);};
00134   void SetOutputStyleToPolygonalize() 
00135     {this->SetOutputStyle(VTK_STYLE_POLYGONALIZE);};
00136   void SetOutputStyleToRunLength() 
00137     {this->SetOutputStyle(VTK_STYLE_RUN_LENGTH);};
00139 
00141 
00142   vtkSetClampMacro(ColorMode,int,VTK_COLOR_MODE_LUT,VTK_COLOR_MODE_LINEAR_256);
00143   vtkGetMacro(ColorMode,int);
00144   void SetColorModeToLUT() 
00145     {this->SetColorMode(VTK_COLOR_MODE_LUT);};
00146   void SetColorModeToLinear256() 
00147     {this->SetColorMode(VTK_COLOR_MODE_LINEAR_256);};
00149 
00151 
00153   vtkSetObjectMacro(LookupTable,vtkScalarsToColors);
00154   vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
00156 
00158 
00160   vtkSetMacro(Smoothing, int);
00161   vtkGetMacro(Smoothing, int);
00162   vtkBooleanMacro(Smoothing, int);
00164   
00166 
00168   vtkSetClampMacro(NumberOfSmoothingIterations,int,0,VTK_LARGE_INTEGER);
00169   vtkGetMacro(NumberOfSmoothingIterations,int);
00171   
00173 
00175   vtkSetMacro(Decimation, int);
00176   vtkGetMacro(Decimation, int);
00177   vtkBooleanMacro(Decimation, int);
00179   
00181 
00182   vtkSetClampMacro(DecimationError,float,0.0,VTK_LARGE_FLOAT);
00183   vtkGetMacro(DecimationError,float);
00185   
00187 
00190   vtkSetClampMacro(Error,int,0,VTK_LARGE_INTEGER);
00191   vtkGetMacro(Error,int);
00193 
00195 
00200   vtkSetClampMacro(SubImageSize,int,10,VTK_LARGE_INTEGER);
00201   vtkGetMacro(SubImageSize,int);
00203   
00204 protected:
00205   vtkImageToPolyDataFilter();
00206   ~vtkImageToPolyDataFilter();
00207 
00208   void Execute();
00209 
00210   int OutputStyle;
00211   int ColorMode;
00212   int Smoothing;
00213   int NumberOfSmoothingIterations;
00214   int Decimation;
00215   float DecimationError;
00216   int Error;
00217   int SubImageSize;
00218   vtkScalarsToColors *LookupTable;
00219 
00220   virtual void PixelizeImage(vtkUnsignedCharArray *pixels, int dims[3], 
00221                              float origin[3], float spacing[3], 
00222                              vtkPolyData *output);
00223   virtual void PolygonalizeImage(vtkUnsignedCharArray *pixels, int dims[3], 
00224                                  float origin[3], float spacing[3], 
00225                                  vtkPolyData *output);
00226   virtual void RunLengthImage(vtkUnsignedCharArray *pixels, int dims[3], 
00227                               float origin[3], float spacing[3], 
00228                               vtkPolyData *output);
00229 private:
00230   vtkUnsignedCharArray *Table;      // color table used to quantize points
00231   vtkTimeStamp         TableMTime;
00232   int                  *Visited;    // traverse & mark connected regions
00233   vtkUnsignedCharArray *PolyColors; // the colors of each region -> polygon
00234   vtkEdgeTable         *EdgeTable;  // keep track of intersection points
00235   vtkEdgeTable         *EdgeUseTable; // keep track of polygons use of edges
00236   vtkIntArray          *EdgeUses; //the two polygons that use an edge
00237                                   //and point id associated with edge (if any)
00238 
00239   vtkAppendPolyData    *Append;
00240 
00241   void BuildTable(unsigned char *inPixels);
00242   vtkUnsignedCharArray *QuantizeImage(vtkDataArray *inScalars, int numComp,
00243                                           int type, int dims[3], int ext[4]);
00244   int ProcessImage(vtkUnsignedCharArray *pixels, int dims[2]);
00245   int BuildEdges(vtkUnsignedCharArray *pixels, int dims[3], float origin[3],
00246                  float spacing[3], vtkUnsignedCharArray *pointDescr, 
00247                  vtkPolyData *edges);
00248   void BuildPolygons(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges,
00249                      int numPolys, vtkUnsignedCharArray *polyColors);
00250   void SmoothEdges(vtkUnsignedCharArray *pointDescr, vtkPolyData *edges);
00251   void DecimateEdges(vtkPolyData *edges, vtkUnsignedCharArray *pointDescr,
00252                      float tol2);
00253   void GeneratePolygons(vtkPolyData *edges, int numPolys, vtkPolyData *output,
00254                         vtkUnsignedCharArray *polyColors,
00255                         vtkUnsignedCharArray *pointDescr);
00256   
00257   int GetNeighbors(unsigned char *ptr, int &i, int &j, int dims[3],
00258                    unsigned char *neighbors[4], int mode);
00259 
00260   void GetIJ(int id, int &i, int &j, int dims[3]);
00261   unsigned char *GetColor(unsigned char *rgb);
00262   int IsSameColor(unsigned char *p1, unsigned char *p2);
00263   
00264 private:
00265   vtkImageToPolyDataFilter(const vtkImageToPolyDataFilter&);  // Not implemented.
00266   void operator=(const vtkImageToPolyDataFilter&);  // Not implemented.
00267 };
00268 
00269 #endif
00270 

Generated on Thu Mar 28 14:19:23 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001