00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00168 InputCellsContainerIterator c_it = temp->GetCells()->Begin();
00169 InputCellsContainerIterator c_end = temp->GetCells()->End();
00170 InputEdgeCellType* qe;
00171 InputPolygonCellType* pe;
00172 InputQEPrimal* QEGeom;
00173
00174 while( c_it != c_end )
00175 {
00176 if( ( qe = dynamic_cast< InputEdgeCellType* >( c_it.Value() ) ) )
00177 {
00178 QEGeom = qe->GetQEGeom( );
00179 output->AddEdgeWithSecurePointList( QEGeom->GetOrigin(),
00180 QEGeom->GetDestination() );
00181 }
00182 else
00183 {
00184 pe = dynamic_cast< InputPolygonCellType* >( c_it.Value());
00185 if( pe )
00186 {
00187 InputPointIdList points;
00188
00189 for( InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
00190 pit != pe->InternalPointIdsEnd( ); ++pit )
00191 {
00192 points.push_back( ( *pit ) );
00193 }
00194 output->AddFaceWithSecurePointList( points );
00195 }
00196 }
00197 ++c_it;
00198 }
00199 }
00200
00201 void CleanPoints()
00202 {
00203 OutputMeshPointer output = this->GetOutput();
00204
00205 OutputPointsContainerIterator p_it = output->GetPoints()->Begin();
00206 OutputPointsContainerIterator p_end = output->GetPoints()->End();
00207 OutputPointIdentifier id( 0 );
00208
00209 while( p_it != p_end )
00210 {
00211 id = p_it->Index();
00212 if( output->FindEdge( id ) == 0 )
00213 {
00214 output->DeletePoint( id );
00215 }
00216 ++p_it;
00217 }
00218
00219 output->SqueezePointsIds( );
00220 }
00221
00222 private:
00223 QuadEdgeMeshCleanFilter( const Self& );
00224 void operator = ( const Self& );
00225 };
00226 }
00227 #endif
00228