1 #ifndef __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__QUADEDGE__HXX__
2 #define __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__QUADEDGE__HXX__
6 // -------------------------------------------------------------------------
7 template< typename P, typename D, bool IsPrimal >
8 const typename cpPlugins::Extensions::DataStructures::
9 QuadEdge< P, D, IsPrimal >::TPrimalGeometry
10 cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
11 NoGeometry = std::numeric_limits< P >::max( );
13 // -------------------------------------------------------------------------
14 template< typename P, typename D, bool IsPrimal >
15 void cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
19 PtrDual r = TDual::New( );
20 Pointer s = Self::New( );
21 PtrDual i = TDual::New( );
34 // -------------------------------------------------------------------------
35 template< typename P, typename D, bool IsPrimal >
36 void cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
37 SetLnextRingGeometry( const D& v )
39 for( Iterator i = this->BeginLnext( ); i != this->EndLnext( ); ++i )
43 // -------------------------------------------------------------------------
44 template< typename P, typename D, bool IsPrimal >
45 void cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
46 UnsetLnextRingGeometry( )
48 this->SetLnextRingGeometry( TDual::NoGeometry );
51 // -------------------------------------------------------------------------
52 template< typename P, typename D, bool IsPrimal >
53 bool cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
54 IsEdgeInOnextRing( const TPrimal* e ) const
58 ConstIterator i = this->BeginOnext( );
59 i != this->EndOnext( ) && !found;
66 // -------------------------------------------------------------------------
67 template< typename P, typename D, bool IsPrimal >
68 bool cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
69 IsEdgeInLnextRing( const TPrimal* e ) const
73 ConstIterator i = this->BeginLnext( );
74 i != this->EndLnext( ) && !found;
81 // -------------------------------------------------------------------------
82 template< typename P, typename D, bool IsPrimal >
84 cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
85 GetOnextRingSize( ) const
87 unsigned int count = 0;
89 ConstIterator i = this->BeginOnext( );
90 i != this->EndOnext( );
97 // -------------------------------------------------------------------------
98 template< typename P, typename D, bool IsPrimal >
100 cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
101 GetLnextRingSize( ) const
103 unsigned int count = 0;
105 ConstIterator i = this->BeginLnext( );
106 i != this->EndLnext( );
113 // -------------------------------------------------------------------------
114 template< typename P, typename D, bool IsPrimal >
115 bool cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
119 ( this->IsLeftSet( ) && !( this->IsRightSet( ) ) ) ||
120 ( !( this->IsLeftSet( ) ) && this->IsRightSet( ) )
124 // -------------------------------------------------------------------------
125 template< typename P, typename D, bool IsPrimal >
126 bool cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
127 IsOriginInternal( ) const
129 bool internal = true;
131 ConstIterator i = this->BeginOnext( );
132 i != this->EndOnext( ) && internal;
135 internal &= ( *i )->IsInternal( );
139 // -------------------------------------------------------------------------
140 template< typename P, typename D, bool IsPrimal >
141 typename cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
142 TPrimal* cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
143 GetNextBorderEdgeWithUnsetLeft( TPrimal* edge ) const
145 // Be sure the Onext ring isn't already full
146 if( this->IsOriginInternal( ) )
150 edge = ( edge == NULL )? const_cast< TPrimal* >( this ): edge;
152 // On efficiency purposes
153 if( edge->IsIsolated( ) )
156 // Ok, no more special cases
157 const TPrimal* cedge = const_cast< const TPrimal* >( edge );
158 ConstIterator it = cedge->BeginOnext( );
159 TPrimal* found = NULL;
160 for( ; it != cedge->EndOnext( ) && found == NULL; ++it )
161 if( !( ( *it )->IsLeftSet( ) ) )
162 found = const_cast< TPrimal* >( *it );
166 // -------------------------------------------------------------------------
167 template< typename P, typename D, bool IsPrimal >
168 bool cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
169 ReorderOnextRing( TPrimal* first, TPrimal* second )
171 // Making sure point adjacency is correct:
172 if( first->GetOrigin( ) != second->GetOrigin( ) )
175 if( first->GetOnext( ) == second )
178 if( first->IsLeftSet( ) )
181 // Second is an internal edge.
182 if( second->IsInternal( ) )
185 // Disconnect the triangles containing second:
187 if( second->IsLeftSet( ) )
188 bsplice = second->GetNextBorderEdgeWithUnsetLeft( );
191 TPrimal::Splice( second->GetOprev( ), bsplice );
193 // Reconnect second after first:
194 TPrimal::Splice( first, bsplice );
198 // -------------------------------------------------------------------------
199 template< typename P, typename D, bool IsPrimal >
200 void cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
201 Splice( TPrimal* a, TPrimal* b )
203 // Don't waste time splicing the same edge (or non-existent)
204 // remember: it is its own inverse!
205 if( a != b || a == NULL || b == NULL )
207 TPrimal* aNext = a->m_Onext;
208 TPrimal* bNext = b->m_Onext;
209 TDual* al = aNext->m_Rot;
210 TDual* be = bNext->m_Rot;
211 TDual* alNext = al->m_Onext;
212 TDual* beNext = be->m_Onext;
214 a->SetOnext( bNext );
215 b->SetOnext( aNext );
216 al->SetOnext( beNext );
217 be->SetOnext( alNext );
222 // -------------------------------------------------------------------------
223 template< typename P, typename D, bool IsPrimal >
224 cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
226 : m_Origin( Self::NoGeometry )
228 this->m_Onext = this;
232 // -------------------------------------------------------------------------
233 template< typename P, typename D, bool IsPrimal >
234 cpPlugins::Extensions::DataStructures::QuadEdge< P, D, IsPrimal >::
239 #endif // __CPPLUGINS__EXTENSIONS__DATASTRUCTURES__QUADEDGE__HXX__