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

itkQuadEdgeMeshCleanFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkQuadEdgeMeshCleanFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-20 16:55:42 $
00007   Version:   $Revision: 1.5 $
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 
00018 #ifndef __itkQuadEdgeMeshCleanFilter_h
00019 #define __itkQuadEdgeMeshCleanFilter_h
00020 
00021 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.h"
00022 #include "itkBoundingBox.h"
00023 
00024 #include "itkQuadEdgeMeshSquaredEdgeLengthDecimation.h"
00025 #include "itkQuadEdgeMeshDecimationCriteria.h"
00026 
00027 namespace itk
00028 {
00033 template< class TInput, class TOutput >
00034 class QuadEdgeMeshCleanFilter :
00035   public QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >
00036 {
00037 public:
00038   typedef QuadEdgeMeshCleanFilter                                 Self;
00039   typedef SmartPointer< Self >                                    Pointer;
00040   typedef SmartPointer< const Self >                              ConstPointer;
00041   typedef QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >     Superclass;
00042 
00044   itkTypeMacro( QuadEdgeMeshCleanFilter, QuadEdgeMeshToQuadEdgeMeshFilter );
00045 
00047   itkNewMacro( Self );
00048 
00049   typedef TInput                                                InputMeshType;
00050   typedef typename Superclass::InputMeshPointer                 InputMeshPointer;
00051   typedef typename Superclass::InputCoordRepType                InputCoordRepType;
00052   typedef typename Superclass::InputPointType                   InputPointType;
00053   typedef typename Superclass::InputPointIdentifier             InputPointIdentifier;
00054   typedef typename Superclass::InputQEPrimal                    InputQEPrimal;
00055   typedef typename Superclass::InputVectorType                  InputVectorType;
00056 
00057   typedef typename Superclass::InputEdgeCellType                InputEdgeCellType;
00058   typedef typename Superclass::InputPolygonCellType             InputPolygonCellType;
00059   typedef typename Superclass::InputPointIdList                 InputPointIdList;
00060   typedef typename Superclass::InputCellTraits                  InputCellTraits;
00061   typedef typename Superclass::InputPointsIdInternalIterator    InputPointsIdInternalIterator;
00062   typedef typename Superclass::InputQEIterator                  InputQEIterator;
00063 
00064   typedef typename InputMeshType::PointsContainer               InputPointsContainer;
00065   typedef typename InputMeshType::PointsContainerPointer        InputPointsContainerPointer;
00066   typedef typename InputMeshType::PointsContainerIterator       InputPointsContainerIterator;
00067 
00068   typedef typename InputMeshType::CellsContainerIterator        InputCellsContainerIterator;
00069 
00070   itkStaticConstMacro( PointDimension, unsigned int, InputMeshType::PointDimension );
00071 
00072   typedef TOutput                                               OutputMeshType;
00073   typedef typename Superclass::OutputMeshPointer                OutputMeshPointer;
00074   typedef typename Superclass::OutputCoordRepType               OutputCoordRepType;
00075   typedef typename Superclass::OutputPointType                  OutputPointType;
00076   typedef typename Superclass::OutputPointIdentifier            OutputPointIdentifier;
00077   typedef typename Superclass::OutputQEPrimal                   OutputQEPrimal;
00078   typedef typename Superclass::OutputVectorType                 OutputVectorType;
00079 
00080   typedef typename OutputMeshType::QEType                       OutputQEType;
00081   typedef typename OutputMeshType::PointsContainer              OutputPointsContainer;
00082   typedef typename OutputMeshType::PointsContainerPointer       OutputPointsContainerPointer;
00083   typedef typename OutputMeshType::PointsContainerIterator      OutputPointsContainerIterator;
00084 
00085   typedef typename OutputMeshType::CellsContainerIterator      OutputCellsContainerIterator;
00086 
00087   typedef BoundingBox< InputPointIdentifier, itkGetStaticConstMacro(PointDimension),
00088     InputCoordRepType, InputPointsContainer > BoundingBoxType;
00089 
00090   typedef typename BoundingBoxType::Pointer                 BoundingBoxPointer;
00091 
00092   typedef MaxMeasureBoundCriterion< OutputMeshType >        CriterionType;
00093   typedef typename CriterionType::Pointer                   CriterionPointer;
00094 
00095   typedef QuadEdgeMeshSquaredEdgeLengthDecimation< InputMeshType,
00096     InputMeshType, CriterionType >                          DecimationType;
00097   typedef typename DecimationType::Pointer                  DecimationPointer;
00098 
00099   itkSetMacro( AbsoluteTolerance, InputCoordRepType );
00100   itkSetMacro( RelativeTolerance, InputCoordRepType );
00101 
00102 protected:
00103   QuadEdgeMeshCleanFilter()
00104     {
00105     this->m_AbsoluteTolerance2 = itk::NumericTraits< InputCoordRepType >::Zero;
00106     this->m_AbsoluteTolerance  = itk::NumericTraits< InputCoordRepType >::Zero;
00107     this->m_RelativeTolerance  = itk::NumericTraits< InputCoordRepType >::Zero;
00108     }
00109 
00110   virtual ~QuadEdgeMeshCleanFilter() {}
00111 
00112   InputCoordRepType m_AbsoluteTolerance2;
00113   InputCoordRepType m_AbsoluteTolerance;
00114   InputCoordRepType m_RelativeTolerance;
00115 
00116   void GenerateData()
00117     {
00118     InputCoordRepType zeroValue = itk::NumericTraits< InputCoordRepType >::Zero;
00119 
00120     if( ( m_AbsoluteTolerance == zeroValue ) && ( m_RelativeTolerance != zeroValue ) )
00121       {
00122       assert( ( m_RelativeTolerance > zeroValue ) && ( m_RelativeTolerance < 1. ) );
00123       BoundingBoxPointer bounding_box = BoundingBoxType::New();
00124       bounding_box->SetPoints( this->GetInput()->GetPoints() );
00125       bounding_box->ComputeBoundingBox();
00126 
00127       m_AbsoluteTolerance2 = m_RelativeTolerance * m_RelativeTolerance *
00128         bounding_box->GetDiagonalLength2();
00129       }
00130 
00131     if( m_AbsoluteTolerance != zeroValue )
00132       {
00133       m_AbsoluteTolerance2 = m_AbsoluteTolerance * m_AbsoluteTolerance;
00134       }
00135 
00136     this->MergePoints();
00137     this->CleanPoints();
00138     }
00139 
00140   void MergePoints()
00141     {
00142     OutputMeshPointer output = this->GetOutput();
00143 
00144     CriterionPointer criterion = CriterionType::New();
00145     criterion->SetTopologicalChange( false );
00146     criterion->SetMeasureBound( m_AbsoluteTolerance2 );
00147 
00148     DecimationPointer decimate = DecimationType::New();
00149     decimate->SetInput( this->GetInput() );
00150     decimate->SetCriterion( criterion );
00151     decimate->Update();
00152 
00153     InputMeshPointer temp = decimate->GetOutput();
00154 
00155     InputPointsContainerIterator p_it = temp->GetPoints()->Begin();
00156     InputPointsContainerIterator p_end = temp->GetPoints()->End();
00157 
00158     OutputPointType pOut;
00159 
00160     while( p_it != p_end )
00161       {
00162       pOut.CastFrom( p_it.Value() );
00163       output->SetPoint( p_it.Index(), pOut );
00164       ++p_it;
00165       }
00166 
00167     // Copy Edge Cells
00168     InputCellsContainerIterator  c_it = temp->GetEdgeCells()->Begin();
00169     InputCellsContainerIterator  c_end = temp->GetEdgeCells()->End();
00170     InputEdgeCellType* qe;
00171     InputQEPrimal* QEGeom;
00172 
00173     while( c_it != c_end )
00174       {
00175       qe = dynamic_cast< InputEdgeCellType* >( c_it.Value());
00176       QEGeom = qe->GetQEGeom( );
00177       output->AddEdgeWithSecurePointList( QEGeom->GetOrigin(),
00178                                           QEGeom->GetDestination() );
00179       ++c_it;
00180       }
00181 
00182     // Copy cells
00183     c_it = temp->GetCells()->Begin();
00184     c_end = temp->GetCells()->End();
00185     InputPolygonCellType* pe;
00186 
00187     while( c_it != c_end )
00188       {
00189       pe = dynamic_cast< InputPolygonCellType* >( c_it.Value());
00190       if( pe )
00191         {
00192         InputPointIdList points;
00193 
00194         for( InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
00195              pit != pe->InternalPointIdsEnd( ); ++pit )
00196           {
00197           points.push_back( ( *pit ) );
00198           }
00199         output->AddFaceWithSecurePointList( points );
00200         }
00201       ++c_it;
00202       }
00203     }
00204 
00205   void CleanPoints()
00206     {
00207     OutputMeshPointer output = this->GetOutput();
00208 
00209     OutputPointsContainerIterator p_it = output->GetPoints()->Begin();
00210     OutputPointsContainerIterator p_end = output->GetPoints()->End();
00211     OutputPointIdentifier id( 0 );
00212 
00213     while( p_it != p_end )
00214       {
00215       id = p_it->Index();
00216       if( output->FindEdge( id ) == 0 )
00217         {
00218         output->DeletePoint( id );
00219         }
00220       ++p_it;
00221       }
00222 
00223     output->SqueezePointsIds( );
00224     }
00225 
00226 private:
00227   QuadEdgeMeshCleanFilter( const Self& );
00228   void operator = ( const Self& );
00229 };
00230 }
00231 #endif
00232 

Generated at Sat Feb 28 13:18:38 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000