1 #ifndef __CPM__DATASTRUCTURES__QUADEDGE__HXX__
2 #define __CPM__DATASTRUCTURES__QUADEDGE__HXX__
6 // -------------------------------------------------------------------------
7 template< typename P, typename D, bool IsPrimal >
8 const typename cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
9 TPrimalGeometry cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
10 NoGeometry = std::numeric_limits< P >::max( );
12 // -------------------------------------------------------------------------
13 template< typename P, typename D, bool IsPrimal >
14 void cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
18 PtrDual r = TDual::New( );
19 Pointer s = Self::New( );
20 PtrDual i = TDual::New( );
33 // -------------------------------------------------------------------------
34 template< typename P, typename D, bool IsPrimal >
35 void cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
36 SetLnextRingGeometry( const D& v )
38 for( Iterator i = this->BeginLnext( ); i != this->EndLnext( ); ++i )
42 // -------------------------------------------------------------------------
43 template< typename P, typename D, bool IsPrimal >
44 void cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
45 UnsetLnextRingGeometry( )
47 this->SetLnextRingGeometry( TDual::NoGeometry );
50 // -------------------------------------------------------------------------
51 template< typename P, typename D, bool IsPrimal >
52 bool cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
53 IsEdgeInOnextRing( const TPrimal* e ) const
57 ConstIterator i = this->BeginOnext( );
58 i != this->EndOnext( ) && !found;
65 // -------------------------------------------------------------------------
66 template< typename P, typename D, bool IsPrimal >
67 bool cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
68 IsEdgeInLnextRing( const TPrimal* e ) const
72 ConstIterator i = this->BeginLnext( );
73 i != this->EndLnext( ) && !found;
80 // -------------------------------------------------------------------------
81 template< typename P, typename D, bool IsPrimal >
82 unsigned int cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
83 GetOnextRingSize( ) const
85 unsigned int count = 0;
87 ConstIterator i = this->BeginOnext( );
88 i != this->EndOnext( );
95 // -------------------------------------------------------------------------
96 template< typename P, typename D, bool IsPrimal >
97 unsigned int cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
98 GetLnextRingSize( ) const
100 unsigned int count = 0;
102 ConstIterator i = this->BeginLnext( );
103 i != this->EndLnext( );
110 // -------------------------------------------------------------------------
111 template< typename P, typename D, bool IsPrimal >
112 bool cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
116 ( this->IsLeftSet( ) && !( this->IsRightSet( ) ) ) ||
117 ( !( this->IsLeftSet( ) ) && this->IsRightSet( ) )
121 // -------------------------------------------------------------------------
122 template< typename P, typename D, bool IsPrimal >
123 bool cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
124 IsOriginInternal( ) const
126 bool internal = true;
128 ConstIterator i = this->BeginOnext( );
129 i != this->EndOnext( ) && internal;
132 internal &= ( *i )->IsInternal( );
136 // -------------------------------------------------------------------------
137 template< typename P, typename D, bool IsPrimal >
138 typename cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
139 TPrimal* cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
140 GetNextBorderEdgeWithUnsetLeft( TPrimal* edge ) const
142 // Be sure the Onext ring isn't already full
143 if( this->IsOriginInternal( ) )
147 edge = ( edge == NULL )? const_cast< TPrimal* >( this ): edge;
149 // On efficiency purposes
150 if( edge->IsIsolated( ) )
153 // Ok, no more special cases
154 const TPrimal* cedge = const_cast< const TPrimal* >( edge );
155 ConstIterator it = cedge->BeginOnext( );
156 TPrimal* found = NULL;
157 for( ; it != cedge->EndOnext( ) && found == NULL; ++it )
158 if( !( ( *it )->IsLeftSet( ) ) )
159 found = const_cast< TPrimal* >( *it );
163 // -------------------------------------------------------------------------
164 template< typename P, typename D, bool IsPrimal >
165 bool cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
166 ReorderOnextRing( TPrimal* first, TPrimal* second )
168 // Making sure point adjacency is correct:
169 if( first->GetOrigin( ) != second->GetOrigin( ) )
172 if( first->GetOnext( ) == second )
175 if( first->IsLeftSet( ) )
178 // Second is an internal edge.
179 if( second->IsInternal( ) )
182 // Disconnect the triangles containing second:
184 if( second->IsLeftSet( ) )
185 bsplice = second->GetNextBorderEdgeWithUnsetLeft( );
188 TPrimal::Splice( second->GetOprev( ), bsplice );
190 // Reconnect second after first:
191 TPrimal::Splice( first, bsplice );
195 // -------------------------------------------------------------------------
196 template< typename P, typename D, bool IsPrimal >
197 void cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
198 Splice( TPrimal* a, TPrimal* b )
200 // Don't waste time splicing the same edge (or non-existent)
201 // remember: it is its own inverse!
202 if( a != b || a == NULL || b == NULL )
204 TPrimal* aNext = a->m_Onext;
205 TPrimal* bNext = b->m_Onext;
206 TDual* al = aNext->m_Rot;
207 TDual* be = bNext->m_Rot;
208 TDual* alNext = al->m_Onext;
209 TDual* beNext = be->m_Onext;
211 a->SetOnext( bNext );
212 b->SetOnext( aNext );
213 al->SetOnext( beNext );
214 be->SetOnext( alNext );
219 // -------------------------------------------------------------------------
220 template< typename P, typename D, bool IsPrimal >
221 cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
223 : m_Origin( Self::NoGeometry )
225 this->m_Onext = this;
229 // -------------------------------------------------------------------------
230 template< typename P, typename D, bool IsPrimal >
231 cpm::DataStructures::QuadEdge< P, D, IsPrimal >::
236 #endif // __CPM__DATASTRUCTURES__QUADEDGE__HXX__