1 #ifndef __CPM__ALGORITHMS__QUADEDGE__MESHPLANECUTTERFILTER__HXX__
2 #define __CPM__ALGORITHMS__QUADEDGE__MESHPLANECUTTERFILTER__HXX__
8 // -------------------------------------------------------------------------
10 void cpm::Algorithms::QuadEdge::MeshPlaneCutterFilter< M >::
11 SetPlaneNormal( const TVector& n )
13 TScalar nn = n.GetNorm( );
14 if( TScalar( 0 ) < nn )
16 this->m_PlaneNormal = n / nn;
22 // -------------------------------------------------------------------------
24 cpm::Algorithms::QuadEdge::MeshPlaneCutterFilter< M >::
25 MeshPlaneCutterFilter( )
28 this->m_PlanePoint.Fill( TScalar( 0 ) );
29 this->m_PlaneNormal.Fill( TScalar( 0 ) );
30 this->m_PlaneNormal[ 0 ] = TScalar( 1 );
33 // -------------------------------------------------------------------------
35 cpm::Algorithms::QuadEdge::MeshPlaneCutterFilter< M >::
36 ~MeshPlaneCutterFilter( )
40 // -------------------------------------------------------------------------
42 void cpm::Algorithms::QuadEdge::MeshPlaneCutterFilter< M >::
45 typedef typename M::TPrimalEdge _TEdge;
46 typedef typename M::TQuadEdgeCell _TCell;
47 typedef typename _TEdge::Iterator _TEdgeIt;
49 const M* input = this->GetInput( );
50 M* output = this->GetOutput( );
53 output->Initialize( );
56 std::set< _TEdge* > marks;
58 unsigned long nCells = input->GetNumberOfCells( );
59 unsigned long actualCell = 0;
61 TVector pp = this->m_PlanePoint;
62 TVector np = this->m_PlaneNormal;
65 while( actualCell < nCells )
67 std::queue< _TEdge* > q;
69 // Is the next cell a QuadEdgeCell?
70 typename M::CellAutoPointer cell_ptr;
71 input->GetCell( actualCell++, cell_ptr );
72 _TCell* cell = dynamic_cast< _TCell* >( cell_ptr.GetPointer( ) );
76 // Ok, it is... now, does its face needs to be analyzed?
77 _TEdge* edge = cell->GetEntryPrimalEdge( );
78 _TEdgeIt fIt = edge->BeginLnext( );
79 for( ; fIt != edge->EndLnext( ); ++fIt )
81 // Has the edge already been visited?
82 if( marks.find( *fIt ) != marks.end( ) )
85 // No, ok -> intersection candidate
91 while( !( q.empty( ) ) )
93 // Pick next candidate
98 if( marks.find( edge ) != marks.end( ) )
101 // Mark it (with its symmetric)
102 marks.insert( edge );
103 marks.insert( edge->GetSym( ) );
105 // Now, edge is a true candidate: check intersection
106 pl = input->GetPoint( edge->GetOrigin( ) ).GetVectorFromOrigin( );
107 pm = input->GetPoint( edge->GetDestination( ) ).GetVectorFromOrigin( );
109 num = ( pp - pl ) * pml;
111 // std::cout << num << " " << den << " " << pp << " " << np << " " << pl << " " << pm << " {" << edge->GetOrigin( ) << "," << edge->GetDestination( ) << "}" << std::endl;
112 if( !( double( 0 ) < std::fabs( double( den ) ) ) )
114 if( !( double( 0 ) < std::fabs( double( num ) ) ) )
116 // Line lies on plane: both points intersect
117 // std::cout << pl << " " << pm << " ";
120 // else: Line parallel to plane -> no intersection
125 if( TScalar( 0 ) <= num && num <= TScalar( 1 ) )
127 // One point intersection
128 // TPoint pnt( TScalar( 0 )
130 output->GetNumberOfPoints( ),
131 ( ( pm - pl ) * num ) + pl
135 fIt = edge->BeginLnext( );
136 for( ; fIt != edge->EndLnext( ); ++fIt )
138 // Has the edge already been visited?
139 if( marks.find( *fIt ) != marks.end( ) )
142 // No, ok -> intersection candidate
147 // else: no intersection between pm and pl
156 #endif // __CPM__ALGORITHMS__QUADEDGE__MESHPLANECUTTERFILTER__HXX__