Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMeshWingedEdge.imp.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_geom_geMeshWingedEdge_imp_h
00020 #define freecloth_geom_geMeshWingedEdge_imp_h
00021 
00022 #ifndef freecloth_geom_geMeshWingedEdge_h
00023 #include <freecloth/geom/geMeshWingedEdge.h>
00024 #endif
00025 
00026 FREECLOTH_NAMESPACE_START
00027 
00028 ////////////////////////////////////////////////////////////////////////////////
00029 // CLASS GeMeshWingedEdge::EdgeIteratorBase
00030 //
00031 
00032 //------------------------------------------------------------------------------
00033 
00034 template <bool HALF>
00035 TEMPLATE_NAMESPACE_PREFIX
00036 GeMeshWingedEdge::EdgeIteratorBase<HALF>::EdgeIteratorBase()
00037 {
00038 }
00039 
00040 //------------------------------------------------------------------------------
00041 
00042 template <bool HALF>
00043 TEMPLATE_NAMESPACE_PREFIX
00044 GeMeshWingedEdge::EdgeIteratorBase<HALF>::EdgeIteratorBase(
00045     const GeMeshWingedEdge& meshwe,
00046     HalfEdgeId halfEdgeId
00047 ) : _wrapper( meshwe, halfEdgeId )
00048 {
00049 }
00050 
00051 //------------------------------------------------------------------------------
00052 
00053 template <bool HALF>
00054 TEMPLATE_NAMESPACE_PREFIX
00055 GeMeshWingedEdge::EdgeIteratorBase<HALF>::EdgeIteratorBase(
00056     const HalfEdgeWrapper& wrapper
00057 ) : _wrapper( wrapper )
00058 {
00059 }
00060 
00061 //------------------------------------------------------------------------------
00062 
00063 template <bool HALF>
00064 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::EdgeIteratorBase<HALF>
00065 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::EdgeIteratorBase<HALF>::begin(
00066     const GeMeshWingedEdge& meshwe
00067 ) {
00068     return EdgeIteratorBase( meshwe, 0 );
00069 }
00070 
00071 //------------------------------------------------------------------------------
00072 
00073 template <bool HALF>
00074 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::EdgeIteratorBase<HALF>&
00075 TEMPLATE_NAMESPACE_PREFIX
00076 GeMeshWingedEdge::EdgeIteratorBase<HALF>::operator++()
00077 {
00078     do {
00079         ++_wrapper._halfEdgeId;
00080         if ( HALF ) {
00081             break;
00082         }
00083     } while (
00084         // If we're doing full-edges, repeat increment until
00085         // a) we reach the end
00086         _wrapper._halfEdgeId < _wrapper.getMeshWE().getNbHalfEdges() &&
00087         // b) we find a half-edge with a lower origin id than tip id (used
00088         // to ensure that only one half-edge in each edge is iterated)
00089         _wrapper.getOriginVertexId() > _wrapper.getTipVertexId() &&
00090         // c) ... unless this half-edge has no twin
00091         _wrapper.hasTwin()
00092     );
00093     return *this;
00094 }
00095 
00096 //------------------------------------------------------------------------------
00097 
00098 template <bool HALF>
00099 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::EdgeIteratorBase<HALF>
00100 TEMPLATE_NAMESPACE_PREFIX
00101 GeMeshWingedEdge::EdgeIteratorBase<HALF>::operator++( int )
00102 {
00103     EdgeIteratorBase copy( *this );
00104     operator++();
00105     return copy;
00106 }
00107 
00108 
00109 ////////////////////////////////////////////////////////////////////////////////
00110 // CLASS GeMeshWingedEdge::VertexEdgeIteratorBase
00111 //
00112 
00113 //------------------------------------------------------------------------------
00114 
00115 template <bool HALF>
00116 TEMPLATE_NAMESPACE_PREFIX
00117 GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>::VertexEdgeIteratorBase()
00118 {
00119 }
00120 
00121 //------------------------------------------------------------------------------
00122 
00123 template <bool HALF>
00124 TEMPLATE_NAMESPACE_PREFIX
00125 GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>::VertexEdgeIteratorBase(
00126     const GeMeshWingedEdge& meshwe,
00127     VertexId vertexId,
00128     HalfEdgeId halfEdgeId
00129 ) : _wrapper( meshwe, halfEdgeId ),
00130     _vertexId( vertexId )
00131 {
00132     if ( HALF ) {
00133         DGFX_ASSERT(
00134             _wrapper.getOriginVertexId() == _vertexId
00135         );
00136     }
00137 }
00138 
00139 //------------------------------------------------------------------------------
00140 
00141 template <bool HALF>
00142 TEMPLATE_NAMESPACE_PREFIX
00143 GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>::VertexEdgeIteratorBase(
00144     const HalfEdgeWrapper& wrapper,
00145     VertexId vertexId
00146 ) : _wrapper( wrapper ),
00147     _vertexId( vertexId )
00148 {
00149 #if 0
00150     if ( HALF ) {
00151         DGFX_ASSERT(
00152             _wrapper.getOriginVertexId() == _vertexId
00153         );
00154     }
00155 #endif
00156 }
00157 
00158 //------------------------------------------------------------------------------
00159 
00160 template <bool HALF>
00161 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>
00162 TEMPLATE_NAMESPACE_PREFIX
00163 GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>::begin(
00164     const GeMeshWingedEdge& meshwe,
00165     VertexId vertexId
00166 ) {
00167     DGFX_ASSERT( vertexId < meshwe._vertexHalfEdgeIds.size() );
00168     // Not adjacent to any edges
00169     if ( meshwe._vertexHalfEdgeIds[ vertexId ] == ID_INVALID ) {
00170         return end( meshwe, vertexId );
00171     }
00172     return VertexEdgeIteratorBase(
00173         meshwe, vertexId, meshwe._vertexHalfEdgeIds[ vertexId ]
00174     );
00175 }
00176 
00177 //------------------------------------------------------------------------------
00178 
00179 template <bool HALF>
00180 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>&
00181 TEMPLATE_NAMESPACE_PREFIX
00182 GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>::operator++()
00183 {
00184     bool atEnd = false;
00185     if ( _wrapper.getOriginVertexId() != _vertexId ) {
00186         atEnd = true;
00187     }
00188     else if ( _wrapper.getPrevHalfEdge().hasTwin() ) {
00189         _wrapper._halfEdgeId = _wrapper.getPrevHalfEdge().getTwinHalfEdgeId();
00190         DGFX_ASSERT( _wrapper.getOriginVertexId() == _vertexId );
00191         atEnd = (
00192             _wrapper._halfEdgeId ==
00193             _wrapper.getMeshWE()._vertexHalfEdgeIds[ _vertexId ]
00194         );
00195     }
00196     else {
00197         if ( HALF ) {
00198             atEnd = true;
00199         }
00200         else {
00201             _wrapper._halfEdgeId = _wrapper.getPrevHalfEdgeId();
00202             DGFX_ASSERT( _wrapper.getOriginVertexId() != _vertexId );
00203         }
00204     }
00205     if ( atEnd ) {
00206         _vertexId = ID_INVALID;
00207         _wrapper._halfEdgeId = ID_INVALID;
00208     }
00209     return *this;
00210 }
00211 
00212 //------------------------------------------------------------------------------
00213 
00214 template <bool HALF>
00215 TEMPLATE_NAMESPACE_PREFIX GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>
00216 TEMPLATE_NAMESPACE_PREFIX
00217 GeMeshWingedEdge::VertexEdgeIteratorBase<HALF>::operator++( int )
00218 {
00219     VertexEdgeIteratorBase copy( *this );
00220     operator++();
00221     return copy;
00222 }
00223 
00224 FREECLOTH_NAMESPACE_END
00225 
00226 #endif

Generated on Wed Apr 23 15:58:46 2003 for Freecloth by doxygen1.3-rc3