Go to the documentation of this file.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 itkAssertOrThrowMacro( ( m_RelativeTolerance > zeroValue ) && ( m_RelativeTolerance < 1. ),
00123 "Relative tolerance out of range" );
00124 BoundingBoxPointer bounding_box = BoundingBoxType::New();
00125 bounding_box->SetPoints( this->GetInput()->GetPoints() );
00126 bounding_box->ComputeBoundingBox();
00127
00128 m_AbsoluteTolerance2 = m_RelativeTolerance * m_RelativeTolerance *
00129 bounding_box->GetDiagonalLength2();
00130 }
00131
00132 if( m_AbsoluteTolerance != zeroValue )
00133 {
00134 m_AbsoluteTolerance2 = m_AbsoluteTolerance * m_AbsoluteTolerance;
00135 }
00136
00137 this->MergePoints();
00138 this->CleanPoints();
00139 }
00140
00141 void MergePoints()
00142 {
00143 OutputMeshPointer output = this->GetOutput();
00144
00145 CriterionPointer criterion = CriterionType::New();
00146 criterion->SetTopologicalChange( false );
00147 criterion->SetMeasureBound( m_AbsoluteTolerance2 );
00148
00149 DecimationPointer decimate = DecimationType::New();
00150 decimate->SetInput( this->GetInput() );
00151 decimate->SetCriterion( criterion );
00152 decimate->Update();
00153
00154 InputMeshPointer temp = decimate->GetOutput();
00155
00156 InputPointsContainerIterator p_it = temp->GetPoints()->Begin();
00157 InputPointsContainerIterator p_end = temp->GetPoints()->End();
00158
00159 OutputPointType pOut;
00160
00161 while( p_it != p_end )
00162 {
00163 pOut.CastFrom( p_it.Value() );
00164 output->SetPoint( p_it.Index(), pOut );
00165 ++p_it;
00166 }
00167
00168
00169 InputCellsContainerIterator c_it = temp->GetEdgeCells()->Begin();
00170 InputCellsContainerIterator c_end = temp->GetEdgeCells()->End();
00171 InputEdgeCellType* qe;
00172 InputQEPrimal* QEGeom;
00173
00174 while( c_it != c_end )
00175 {
00176 qe = dynamic_cast< InputEdgeCellType* >( c_it.Value());
00177 QEGeom = qe->GetQEGeom( );
00178 output->AddEdgeWithSecurePointList( QEGeom->GetOrigin(),
00179 QEGeom->GetDestination() );
00180 ++c_it;
00181 }
00182
00183
00184 c_it = temp->GetCells()->Begin();
00185 c_end = temp->GetCells()->End();
00186 InputPolygonCellType* pe;
00187
00188 while( c_it != c_end )
00189 {
00190 pe = dynamic_cast< InputPolygonCellType* >( c_it.Value());
00191 if( pe )
00192 {
00193 InputPointIdList points;
00194
00195 for( InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
00196 pit != pe->InternalPointIdsEnd( ); ++pit )
00197 {
00198 points.push_back( ( *pit ) );
00199 }
00200 output->AddFaceWithSecurePointList( points );
00201 }
00202 ++c_it;
00203 }
00204 }
00205
00206 void CleanPoints()
00207 {
00208 OutputMeshPointer output = this->GetOutput();
00209
00210 OutputPointsContainerIterator p_it = output->GetPoints()->Begin();
00211 OutputPointsContainerIterator p_end = output->GetPoints()->End();
00212 OutputPointIdentifier id( 0 );
00213
00214 while( p_it != p_end )
00215 {
00216 id = p_it->Index();
00217 if( output->FindEdge( id ) == 0 )
00218 {
00219 output->DeletePoint( id );
00220 }
00221 ++p_it;
00222 }
00223
00224 output->SqueezePointsIds( );
00225 }
00226
00227 private:
00228 QuadEdgeMeshCleanFilter( const Self& );
00229 void operator = ( const Self& );
00230 };
00231 }
00232 #endif
00233