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: 2010-03-24 21:51:55 $
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 __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 ];
00150 
00151     OutputMeshPointer output = this->GetOutput();
00152     
00153     OutputPointType org = output->GetPoint( id_org );
00154     OutputPointType dest = output->GetPoint( id_dest );
00155     
00156     OutputPointType mid;
00157     mid.SetToMidPoint( org, dest );
00158     OutputPointType p = Q.ComputeOptimalLocation( mid );
00159     
00160     return static_cast< MeasureType >( Q.ComputeError( p ) );
00161     }
00162   
00163   virtual void DeletePoint( const OutputPointIdentifier& iIdToBeDeleted,
00164     const OutputPointIdentifier& iRemaining )
00165     {
00166     Superclass::DeletePoint( iIdToBeDeleted, iRemaining );
00167 
00168     QuadricElementMapIterator it = m_Quadric.find( iIdToBeDeleted );
00169     m_Quadric[iRemaining] += it->second;
00170     m_Quadric.erase( it );
00171     }
00172 
00178   OutputPointType Relocate( OutputQEType* iEdge )
00179     {
00180     OutputPointIdentifier id_org = iEdge->GetOrigin();
00181     OutputPointIdentifier id_dest = iEdge->GetDestination();
00182     QuadricElementType Q = m_Quadric[ id_org ] + m_Quadric[ id_dest ];
00184 
00185     OutputMeshPointer output = this->GetOutput();
00186     
00187     OutputPointType org = output->GetPoint( id_org );
00188     OutputPointType dest = output->GetPoint( id_dest );
00189     
00190     OutputPointType mid;
00191     mid.SetToMidPoint( org, dest );
00192     
00193     return Q.ComputeOptimalLocation( mid );
00194     }
00195 
00196 private:
00197   QuadEdgeMeshQuadricDecimation( const Self& );
00198   void operator = ( const Self& );
00199 };
00200 
00201 }
00202 #endif
00203 

Generated at Fri Apr 16 19:23:25 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000