1 #ifndef __CPM__ALGORITHMS__QUADEDGEMESHTO__DUALFILTER__HXX__
2 #define __CPM__ALGORITHMS__QUADEDGEMESHTO__DUALFILTER__HXX__
6 #include <itkPolygonCell.h>
8 // -------------------------------------------------------------------------
9 template< class I, class O >
10 cpm::Algorithms::QuadEdge::MeshToDualFilter< I, O >::
16 // -------------------------------------------------------------------------
17 template< class I, class O >
18 cpm::Algorithms::QuadEdge::MeshToDualFilter< I, O >::
23 // -------------------------------------------------------------------------
24 template< class I, class O >
25 void cpm::Algorithms::QuadEdge::MeshToDualFilter< I, O >::
28 typedef itk::PolygonCell< typename O::CellType > TPolygon;
29 typedef typename I::TPrimalEdge TInPrimalEdge;
30 typedef typename I::PixelType TInScalar;
31 typedef typename O::PixelType TOutScalar;
32 typedef typename I::PointType TInPoint;
33 typedef typename O::PointType TOutPoint;
34 typedef typename TInPoint::VectorType TInVector;
35 typedef std::map< TPointId, TPointId > _TBorderColumn;
36 typedef std::map< TPointId, _TBorderColumn > _TBorderMatrix;
38 const I* in = this->GetInput( );
39 O* out = this->GetOutput( );
40 // TODO: this->m_Function->SetInputMesh( in );
42 // Convert faces to points
43 unsigned long nCells = in->GetNumberOfCells( );
44 out->GetPoints( )->Reserve( nCells );
45 for( unsigned long cId = 0; cId < nCells; cId++ )
47 const typename I::TPrimalEdge* e = in->FindEntryEdge( cId );
50 if( !( e->IsLeftSet( ) ) )
54 TInVector bc( TInScalar( 0 ) );
55 typename TInPrimalEdge::PointConstIterator pIt = e->BeginPointLnext( );
56 unsigned long pCount = 0;
57 for( ; pIt != e->EndPointLnext( ); pIt++ )
59 bc += in->GetPoint( *pIt ).GetVectorFromOrigin( );
64 bc /= TInScalar( pCount );
67 for( unsigned int d = 0; d < I::PointDimension; d++ )
68 pnt[ d ] = TOutScalar( bc[ d ] );
69 out->SetPoint( e->GetLeft( ), pnt );
73 _TBorderMatrix borderIds;
74 unsigned long nPoints = in->GetNumberOfPoints( );
75 for( unsigned long pId = 0; pId < nPoints; pId++ )
77 const TInPrimalEdge* e = in->FindEdge( pId );
79 // Add dual faces: each point becomes a face
80 typename O::CellAutoPointer cell;
81 TPolygon* face = new TPolygon( );
82 typename TInPrimalEdge::ConstIterator eIt = e->BeginOnext( );
83 for( ; eIt != e->EndOnext( ); eIt++ )
85 if( ( *eIt )->IsAtBorder( ) )
87 // Keep track of created border points
88 TPointId ori = ( *eIt )->GetOrigin( );
89 TPointId des = ( *eIt )->GetDestination( );
90 typename _TBorderMatrix::const_iterator bmIt =
91 borderIds.find( ori );
93 if( bmIt != borderIds.end( ) )
94 found = ( bmIt->second.find( des ) != bmIt->second.end( ) );
97 // Compute border point
98 TInVector bc = in->GetPoint( ( *eIt )->GetOrigin( ) ).
99 GetVectorFromOrigin( );
100 bc += in->GetPoint( ( *eIt )->GetDestination( ) ).
101 GetVectorFromOrigin( );
102 bc /= TInScalar( 2 );
105 for( unsigned int d = 0; d < I::PointDimension; d++ )
106 pnt[ d ] = TOutScalar( bc[ d ] );
108 unsigned long nOutPoints = out->GetNumberOfPoints( );
109 out->SetPoint( nOutPoints, pnt );
110 borderIds[ ori ][ des ] = nOutPoints;
111 borderIds[ des ][ ori ] = nOutPoints;
114 face->AddPointId( borderIds[ ori ][ des ] );
117 if( ( *eIt )->IsLeftSet( ) )
118 face->AddPointId( ( *eIt )->GetLeft( ) );
121 cell.TakeOwnership( face );
122 out->SetCell( out->GetNumberOfCells( ), cell );
127 #endif // __CPM__ALGORITHMS__QUADEDGEMESHTO__DUALFILTER__HXX__