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

itkQuadEdgeMeshQuadricDecimation.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkQuadEdgeMeshQuadricDecimation.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-03 22:23:46 $
00007   Version:   $Revision: 1.4 $
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 __itkQuadEdgeMeshQuadricDecimation_h
00019 #define __itkQuadEdgeMeshQuadricDecimation_h
00020 
00021 #include "itkQuadEdgeMeshEdgeMergeDecimationFilter.h"
00022 #include "itkQuadEdgeMeshDecimationQuadricElementHelper.h"
00023 
00024 namespace itk
00025 {
00030 template< class TInput, class TOutput, class TCriterion >
00031 class QuadEdgeMeshQuadricDecimation :
00032   public QuadEdgeMeshEdgeMergeDecimationFilter< TInput, TOutput, TCriterion >
00033 {
00034 public:
00035   typedef QuadEdgeMeshQuadricDecimation               Self;
00036   typedef SmartPointer< Self >                        Pointer;
00037   typedef SmartPointer< const Self >                  ConstPointer;
00038   typedef QuadEdgeMeshEdgeMergeDecimationFilter< 
00039     TInput, TOutput, TCriterion >                     Superclass;
00040 
00042   itkTypeMacro( QuadEdgeMeshQuadricDecimation, QuadEdgeMeshEdgeMergeDecimationFilter );
00043 
00045   itkNewMacro( Self );
00046 
00047   typedef TInput                                      InputMeshType;
00048   typedef typename InputMeshType::Pointer             InputMeshPointer;
00049 
00050   typedef TOutput                                     OutputMeshType;
00051   typedef typename OutputMeshType::Pointer            OutputMeshPointer;
00052   typedef typename OutputMeshType::PointIdentifier    OutputPointIdentifier;
00053   typedef typename OutputMeshType::PointType          OutputPointType;
00054   typedef typename OutputPointType::CoordRepType      OutputCoordType;
00055   typedef typename OutputMeshType::QEType             OutputQEType;
00056   typedef typename OutputMeshType::EdgeCellType       OutputEdgeCellType;
00057   typedef typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator;
00058   typedef typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer;
00059   typedef typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator;
00060   
00061   itkStaticConstMacro( OutputPointDimension, unsigned int, OutputMeshType::PointDimension );
00062 
00063 
00064   typedef TCriterion                                      CriterionType;
00065   typedef typename CriterionType::MeasureType             MeasureType;
00066 
00067   typedef typename Superclass::PriorityType               PriorityType;
00068   typedef typename Superclass::PriorityQueueItemType      PriorityQueueItemType;
00069   typedef typename Superclass::PriorityQueueType          PriorityQueueType;
00070   typedef typename Superclass::PriorityQueuePointer       PriorityQueuePointer;
00071 
00072   typedef typename Superclass::QueueMapType               QueueMapType;
00073   typedef typename Superclass::QueueMapIterator           QueueMapIterator;
00074 
00075   typedef typename Superclass::OperatorType               OperatorType;
00076   typedef typename Superclass::OperatorPointer            OperatorPointer;
00077 
00078   typedef QuadEdgeMeshDecimationQuadricElementHelper< OutputPointType > 
00079                                                           QuadricElementType;
00080 
00081   typedef std::map< OutputPointIdentifier, QuadricElementType > 
00082                                                           QuadricElementMapType;
00083 
00084   typedef typename QuadricElementMapType::iterator        QuadricElementMapIterator;
00085       
00086 protected:
00087 
00088   QuadEdgeMeshQuadricDecimation() {}
00089   virtual ~QuadEdgeMeshQuadricDecimation() {}
00090   
00091   QuadricElementMapType m_Quadric;
00092 
00093   virtual void Initialize()
00094     {
00095     OutputMeshPointer output = this->GetOutput();
00096     OutputPointsContainerPointer points = output->GetPoints();
00097     OutputPointsContainerIterator it = points->Begin();
00098     OutputPointIdentifier p_id;
00099     OutputQEType * qe;
00100     OutputQEType * qe_it;
00101     
00102     while( it != points->End() )
00103       {
00104       p_id = it->Index();
00105       
00106       qe = output->FindEdge( p_id );
00107       if( qe != 0 )
00108         {
00109         qe_it = qe;
00110         do
00111           {
00112           QuadricAtOrigin( qe_it, m_Quadric[p_id] );
00113           qe_it = qe_it->GetOnext();
00114           } while( qe_it != qe );
00115         }
00116       it++;
00117       }
00118     }
00119   
00120   inline void QuadricAtOrigin( OutputQEType* iEdge, QuadricElementType& oQ ) 
00121     {
00122     OutputMeshPointer output = this->GetOutput();
00123     
00124     OutputPointIdentifier id[3];
00125     id[0] = iEdge->GetOrigin();
00126     id[1] = iEdge->GetDestination();
00127     id[2] = iEdge->GetOnext()->GetDestination();
00128     
00129     OutputPointType p[3];
00130     
00131     for( int i = 0; i < 3; i++ )
00132       {
00133       p[i] = output->GetPoint( id[i] );
00134       }
00135       
00136     oQ.AddTriangle( p[0], p[1], p[2] );
00137     }
00138   
00144   inline MeasureType MeasureEdge( OutputQEType* iEdge )
00145     {
00146     OutputPointIdentifier id_org = iEdge->GetOrigin();
00147     OutputPointIdentifier id_dest = iEdge->GetDestination();
00148     QuadricElementType Q = m_Quadric[ id_org ] + m_Quadric[ id_dest ];
00149     return static_cast< MeasureType >( Q.ComputeErrorAtOptimalLocation() );
00150     }
00152 
00153   virtual void DeletePoint( const OutputPointIdentifier& iIdToBeDeleted,
00154     const OutputPointIdentifier& iRemaining )
00155     {
00156     Superclass::DeletePoint( iIdToBeDeleted, iRemaining );
00157     m_Quadric[iRemaining] += m_Quadric[iIdToBeDeleted];
00158     }
00159 
00165   OutputPointType Relocate( OutputQEType* iEdge )
00166     {
00167     OutputPointIdentifier id_org = iEdge->GetOrigin();
00168     OutputPointIdentifier id_dest = iEdge->GetDestination();
00169     QuadricElementType Q = m_Quadric[ id_org ] + m_Quadric[ id_dest ];
00170     return Q.ComputeOptimalLocation();
00171     }
00173 
00174 private:
00175   QuadEdgeMeshQuadricDecimation( const Self& );
00176   void operator = ( const Self& );
00177 };
00178 
00179 }
00180 #endif
00181 

Generated at Tue Sep 15 04:29:27 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000