Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkVoronoiSegmentationImageFilterBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVoronoiSegmentationImageFilterBase.h,v $
00005   Language:  C++
00006   Date:      $Date: 2010-02-26 05:28:24 $
00007   Version:   $Revision: 1.32 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkVoronoiSegmentationImageFilterBase_h
00018 #define __itkVoronoiSegmentationImageFilterBase_h
00019 
00020 #include "itkImageToImageFilter.h"
00021 #include "itkVoronoiDiagram2D.h"
00022 #include "itkVoronoiDiagram2DGenerator.h"
00023 #include "itkImage.h"
00024 
00025 namespace itk
00026 {
00027 
00058 template <class TInputImage, class TOutputImage,class TBinaryPriorImage=Image<unsigned char,2> >
00059 class ITK_EXPORT VoronoiSegmentationImageFilterBase:
00060     public ImageToImageFilter<TInputImage,TOutputImage>
00061 {
00062 public:
00064   typedef VoronoiSegmentationImageFilterBase             Self;
00065   typedef ImageToImageFilter<TInputImage,TOutputImage>   Superclass;
00066   typedef SmartPointer <Self>                            Pointer;
00067   typedef SmartPointer<const Self>                       ConstPointer;
00068 
00070   itkNewMacro(Self);
00071 
00073   itkTypeMacro(VoronoiSegmentationImageFilterBase,ImageToImageFilter);
00074 
00076   itkStaticConstMacro(ImageDimension, unsigned int,
00077                       TInputImage::ImageDimension);
00078 
00080   typedef TInputImage                        InputImageType;
00081   typedef typename TInputImage::Pointer      InputImagePointer;
00082   typedef typename TInputImage::ConstPointer InputImageConstPointer;
00083   typedef typename TInputImage::IndexType    IndexType;
00084   typedef typename TInputImage::SizeType     SizeType;
00085   typedef typename TInputImage::RegionType   RegionType;
00086   typedef typename TInputImage::PixelType    PixelType;
00087 
00088   typedef TOutputImage                       OutputImageType;
00089   typedef typename TOutputImage::PixelType   OutputPixelType;
00090 
00091   typedef VoronoiDiagram2D<double>                     VoronoiDiagram;
00092   typedef VoronoiDiagram2DGenerator<double>            VoronoiDiagramGenerator;
00093   typedef typename VoronoiDiagram::PointType           PointType;
00094   typedef typename VoronoiDiagram::CellType            CellType;
00095   typedef typename VoronoiDiagram::CellAutoPointer     CellAutoPointer;
00096   typedef typename VoronoiDiagram::Pointer             VoronoiPointer;
00097   typedef typename CellType::PointIdIterator           PointIdIterator;
00098   typedef typename VoronoiDiagram::SeedsType           SeedsType;
00099   typedef typename VoronoiDiagram::SeedsIterator       SeedsIterator;
00100   typedef typename VoronoiDiagram::NeighborIdIterator  NeighborIdIterator;
00101   typedef typename VoronoiDiagram::VoronoiEdgeIterator EdgeIterator;
00102   typedef typename VoronoiDiagram::VoronoiEdge         EdgeInfo;
00103   typedef std::vector<PointType>                       PointTypeVector;
00104   typedef std::deque<PointType>                        PointTypeDeque;
00105   typedef TBinaryPriorImage                            BinaryObjectImage;
00106   typedef typename BinaryObjectImage::Pointer          BinaryObjectImagePointer;
00107   typedef std::vector<IndexType>                       IndexList;
00108 
00110   typedef Image<unsigned char,2>     VDImage; 
00111   typedef typename VDImage::Pointer  VDImagePointer; 
00112 
00114   itkSetMacro(NumberOfSeeds, int);
00115   itkGetConstMacro(NumberOfSeeds, int);
00117 
00119   itkSetMacro(MinRegion, int);
00120   itkGetConstMacro(MinRegion, int);
00122 
00125   itkSetMacro(Steps, int);
00126   itkGetConstMacro(Steps, int);
00128 
00130   itkGetConstMacro(LastStepSeeds, int);
00131 
00133   itkGetConstMacro(NumberOfSeedsToAdded, int); 
00134 
00136   itkSetMacro(UseBackgroundInAPrior, bool);
00137   itkGetConstMacro(UseBackgroundInAPrior, bool);
00139 
00141   itkSetMacro(OutputBoundary, bool);
00142   itkGetConstMacro(OutputBoundary, bool);
00144 
00147   itkSetMacro(InteractiveSegmentation, bool);
00148   itkGetConstMacro(InteractiveSegmentation, bool);
00149   itkBooleanMacro(InteractiveSegmentation);
00151 
00153   itkSetMacro(MeanDeviation, double);
00154   itkGetConstMacro(MeanDeviation, double);
00156 
00158   itkSetMacro(Size,SizeType);
00159   itkGetConstMacro(Size,SizeType);
00161 
00164   virtual void TakeAPrior(const BinaryObjectImage*){}
00165 
00167   void RunSegment(void);
00168 
00170   void RunSegmentOneStep(void);
00171 
00173   virtual void MakeSegmentBoundary(void);
00174   virtual void MakeSegmentObject(void);
00176 
00178   VoronoiPointer GetVoronoiDiagram(void)
00179     { return m_WorkingVD; }
00180 
00181 #if !defined(CABLE_CONFIGURATION)  // generates invalid iterator instantiation with msvc
00182 
00185   void SetSeeds(int num, SeedsIterator begin)
00186     { 
00187     m_NumberOfSeeds = num; 
00188     m_WorkingVD->SetSeeds(num,begin); 
00189     } 
00190 #endif
00191 
00192 
00196   void SetSeeds(SeedsType & seeds)
00197     { 
00198     m_NumberOfSeeds = seeds.size();
00199     typename SeedsType::iterator it = seeds.begin();
00200     m_WorkingVD->SetSeeds(m_NumberOfSeeds, it); 
00201     } 
00203 
00205   PointType GetSeed(int SeedID)
00206     { return m_WorkingVD->GetSeed(SeedID); } 
00207 
00209   void DrawDiagram(VDImagePointer result,unsigned char incolor, 
00210                    unsigned char outcolor,unsigned char boundcolor); 
00211 
00212   void BeforeNextStep(void); 
00213 
00216   virtual void GenerateInputRequestedRegion();
00217 
00220   virtual void EnlargeOutputRequestedRegion(DataObject *output);  
00221 
00222 protected:
00223   VoronoiSegmentationImageFilterBase();
00224   ~VoronoiSegmentationImageFilterBase();
00225   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00226 
00227   void GenerateData(void); //general pipeline function.
00228 
00229   SizeType m_Size;
00230   int      m_NumberOfSeeds;
00231   int      m_MinRegion;
00232   int      m_Steps;
00233   int      m_LastStepSeeds;
00234   int      m_NumberOfSeedsToAdded;
00235   int      m_NumberOfBoundary;
00236 
00237   std::vector<int>           m_NumberOfPixels;
00238   std::vector<unsigned char> m_Label;
00239 
00240   double m_MeanDeviation;
00241   bool   m_UseBackgroundInAPrior;
00242   bool   m_OutputBoundary; //if =1 then output the boundaries, if = 0 then output the object.
00243   bool   m_InteractiveSegmentation;
00244   
00245   typename VoronoiDiagram::Pointer          m_WorkingVD;
00246   typename VoronoiDiagramGenerator::Pointer m_VDGenerator;
00247 
00248   std::vector<PointType> m_SeedsToAdded;
00249 
00250   // private methods:
00251   // Classify all the voronoi cells as interior , exterior or boundary.
00252   virtual void ClassifyDiagram(void);
00253   
00254   // Generate the seeds to be added by dividing the boundary cells.
00255   virtual void GenerateAddingSeeds(void);
00256   
00257   // Compute the statistics of the pixels inside the cell.
00258   void GetPixelIndexFromPolygon(PointTypeDeque VertList, IndexList *PixelPool);
00259   virtual bool TestHomogeneity(IndexList&)
00260     {return 1;}
00261   
00262   void FillPolygon(PointTypeDeque vertlist, OutputPixelType color=1);
00263   
00264   // Draw a straight line to the output image.
00265   void drawLine(PointType p1,PointType p2);
00266   
00267   // Draw the intermedia Voronoi Diagram structure. 
00268   void drawVDline(VDImagePointer result,PointType p1,PointType p2, unsigned char color);
00269   
00270 private:
00271   VoronoiSegmentationImageFilterBase(const Self&); //purposely not implemented
00272   void operator=(const Self&); //purposely not implemented
00273   
00274 };
00275 
00276 }//end namespace
00277 
00278 
00279 #ifndef ITK_MANUAL_INSTANTIATION
00280 #include "itkVoronoiSegmentationImageFilterBase.txx"
00281 #endif
00282 
00283 #endif
00284 

Generated at Fri Apr 16 20:00:37 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000