Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMesh.inline.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_geMesh_inline_h
00020 #define freecloth_geom_geMesh_inline_h
00021 
00022 FREECLOTH_NAMESPACE_START
00023 
00024 ////////////////////////////////////////////////////////////////////////////////
00025 // CLASS GeMesh
00026 //
00027 
00028 //------------------------------------------------------------------------------
00029 
00030 inline GeMesh::GeMesh()
00031 {
00032 }
00033 
00034 //------------------------------------------------------------------------------
00035 
00036 inline UInt32 GeMesh::getNbFaces() const
00037 {
00038     return _faces.size();
00039 }
00040 
00041 //------------------------------------------------------------------------------
00042 
00043 inline GeMesh::FaceType GeMesh::getFace( FaceId faceId) const
00044 {
00045     return FaceWrapper( *this, faceId );
00046 }
00047 
00048 //------------------------------------------------------------------------------
00049 
00050 inline GeMesh::FaceConstIterator GeMesh::beginFace() const
00051 {
00052     return FaceConstIterator::begin( *this );
00053 }
00054 
00055 //------------------------------------------------------------------------------
00056 
00057 inline GeMesh::FaceConstIterator GeMesh::endFace() const
00058 {
00059     return FaceConstIterator::end( *this );
00060 }
00061 
00062 //------------------------------------------------------------------------------
00063 
00064 inline UInt32 GeMesh::getNbVertices() const
00065 {
00066     return _vertices.size();
00067 }
00068 
00069 //------------------------------------------------------------------------------
00070 
00071 inline GeMesh::VertexType& GeMesh::getVertex( VertexId vertexId )
00072 {
00073     DGFX_ASSERT( vertexId < getNbVertices() );
00074     return _vertices[ vertexId ];
00075 }
00076 
00077 //------------------------------------------------------------------------------
00078 
00079 inline const GeMesh::VertexType& GeMesh::getVertex( VertexId vertexId ) const
00080 {
00081     DGFX_ASSERT( vertexId < getNbVertices() );
00082     return _vertices[ vertexId ];
00083 }
00084 
00085 //------------------------------------------------------------------------------
00086 
00087 inline GeMesh::VertexIterator GeMesh::beginVertex()
00088 {
00089     return _vertices.begin();
00090 }
00091 
00092 //------------------------------------------------------------------------------
00093 
00094 inline GeMesh::VertexIterator GeMesh::endVertex()
00095 {
00096     return _vertices.end();
00097 }
00098 
00099 //------------------------------------------------------------------------------
00100 
00101 inline GeMesh::VertexConstIterator GeMesh::beginVertex() const
00102 {
00103     return _vertices.begin();
00104 }
00105 
00106 //------------------------------------------------------------------------------
00107 
00108 inline GeMesh::VertexConstIterator GeMesh::endVertex() const
00109 {
00110     return _vertices.end();
00111 }
00112 
00113 //------------------------------------------------------------------------------
00114 
00115 inline bool GeMesh::hasTexture() const
00116 {
00117     return getNbTextureVertices() > 0;
00118 }
00119 
00120 //------------------------------------------------------------------------------
00121 
00122 inline UInt32 GeMesh::getNbTextureVertices() const
00123 {
00124     return _textureVertices.size();
00125 }
00126 
00127 //------------------------------------------------------------------------------
00128 
00129 inline GeMesh::TextureVertexType& GeMesh::getTextureVertex(
00130     TextureVertexId textureVertexId
00131 ) {
00132     DGFX_ASSERT( textureVertexId < getNbTextureVertices() );
00133     return _textureVertices[ textureVertexId ];
00134 }
00135 
00136 //------------------------------------------------------------------------------
00137 
00138 inline const GeMesh::TextureVertexType& GeMesh::getTextureVertex(
00139     TextureVertexId textureVertexId
00140 ) const {
00141     DGFX_ASSERT( textureVertexId < getNbTextureVertices() );
00142     return _textureVertices[ textureVertexId ];
00143 }
00144 
00145 //------------------------------------------------------------------------------
00146 
00147 inline GeMesh::TextureVertexIterator GeMesh::beginTextureVertex()
00148 {
00149     return _textureVertices.begin();
00150 }
00151 
00152 //------------------------------------------------------------------------------
00153 
00154 inline GeMesh::TextureVertexIterator GeMesh::endTextureVertex()
00155 {
00156     return _textureVertices.end();
00157 }
00158 
00159 //------------------------------------------------------------------------------
00160 
00161 inline GeMesh::TextureVertexConstIterator GeMesh::beginTextureVertex() const
00162 {
00163     return _textureVertices.begin();
00164 }
00165 
00166 //------------------------------------------------------------------------------
00167 
00168 inline GeMesh::TextureVertexConstIterator GeMesh::endTextureVertex() const
00169 {
00170     return _textureVertices.end();
00171 }
00172 
00173 
00174 
00175 ////////////////////////////////////////////////////////////////////////////////
00176 // CLASS GeMesh::Face
00177 //
00178 
00179 //------------------------------------------------------------------------------
00180 
00181 inline GeMesh::Face::Face(
00182     VertexId vid1, VertexId vid2, VertexId vid3,
00183     TextureVertexId tvid1, TextureVertexId tvid2, TextureVertexId tvid3
00184 ) {
00185     _vertexIds[ 0 ] = vid1;
00186     _vertexIds[ 1 ] = vid2;
00187     _vertexIds[ 2 ] = vid3;
00188     _textureVertexIds[ 0 ] = tvid1;
00189     _textureVertexIds[ 1 ] = tvid2;
00190     _textureVertexIds[ 2 ] = tvid3;
00191 }
00192 
00193 //------------------------------------------------------------------------------
00194 
00195 inline UInt32 GeMesh::Face::getNbVertices() const
00196 {
00197     return NB_VERTICES;
00198 }
00199 
00200 //------------------------------------------------------------------------------
00201 
00202 inline GeMeshTypes::VertexId GeMesh::Face::getVertexId(
00203     FaceVertexId faceVertexId
00204 ) const {
00205     DGFX_ASSERT( faceVertexId < NB_VERTICES );
00206     return _vertexIds[ faceVertexId ];
00207 }
00208 
00209 //------------------------------------------------------------------------------
00210 
00211 inline GeMeshTypes::TextureVertexId GeMesh::Face::getTextureVertexId(
00212     FaceVertexId faceVertexId
00213 ) const {
00214     DGFX_ASSERT( faceVertexId < NB_VERTICES );
00215     return _textureVertexIds[ faceVertexId ];
00216 }
00217 
00218 
00219 
00220 ////////////////////////////////////////////////////////////////////////////////
00221 // CLASS GeMesh::FaceWrapper
00222 //
00223 
00224 //------------------------------------------------------------------------------
00225 
00226 inline GeMesh::FaceWrapper::FaceWrapper()
00227     : _mesh( 0 ), _faceId( 0 )
00228 {
00229 }
00230 
00231 //------------------------------------------------------------------------------
00232 
00233 inline GeMesh::FaceWrapper::FaceWrapper(
00234     const GeMesh& mesh,
00235     GeMeshTypes::FaceId faceId
00236 ) : _mesh( &mesh ),
00237     _faceId( faceId )
00238 {
00239     DGFX_ASSERT( isValid() );
00240 }
00241 
00242 //------------------------------------------------------------------------------
00243 
00244 inline GeMesh::FaceWrapper::FaceWrapper(
00245     const GeMesh* mesh,
00246     GeMeshTypes::FaceId faceId
00247 ) : _mesh( mesh ),
00248     _faceId( faceId )
00249 {
00250     // Pointer variant is private and unchecked - allows efficient construction
00251     // of invalid wrappers, i.e. for end() iterator.
00252 }
00253 
00254 //------------------------------------------------------------------------------
00255 
00256 inline GeMesh::FaceId GeMesh::FaceWrapper::getFaceId() const
00257 {
00258     return _faceId;
00259 }
00260 
00261 //------------------------------------------------------------------------------
00262 
00263 inline UInt32 GeMesh::FaceWrapper::getNbVertices() const
00264 {
00265     return _mesh->_faces[ _faceId ].getNbVertices();
00266 }
00267 
00268 //------------------------------------------------------------------------------
00269 
00270 inline GeMeshTypes::VertexId GeMesh::FaceWrapper::getVertexId(
00271     FaceVertexId faceVertexId
00272 ) const {
00273     return _mesh->_faces[ _faceId ].getVertexId( faceVertexId );
00274 }
00275 
00276 //------------------------------------------------------------------------------
00277 
00278 inline const GeMeshTypes::VertexType& GeMesh::FaceWrapper::getVertex(
00279     FaceVertexId faceVertexId
00280 ) const {
00281     return _mesh->getVertex( getVertexId( faceVertexId ) );
00282 }
00283 
00284 //------------------------------------------------------------------------------
00285 
00286 inline GeMeshTypes::TextureVertexId GeMesh::FaceWrapper::getTextureVertexId(
00287     FaceVertexId faceVertexId
00288 ) const {
00289     return _mesh->_faces[ _faceId ].getTextureVertexId( faceVertexId );
00290 }
00291 
00292 //------------------------------------------------------------------------------
00293 
00294 inline const GeMeshTypes::TextureVertexType&
00295 GeMesh::FaceWrapper::getTextureVertex(
00296     FaceVertexId faceVertexId
00297 ) const {
00298     return _mesh->getTextureVertex( getTextureVertexId( faceVertexId ) );
00299 }
00300 
00301 //------------------------------------------------------------------------------
00302 
00303 inline bool GeMesh::FaceWrapper::isValid() const
00304 {
00305     return _mesh != 0 && _faceId < _mesh->getNbFaces();
00306 }
00307 
00308 
00309 ////////////////////////////////////////////////////////////////////////////////
00310 // CLASS GeMesh::FaceConstIterator
00311 //
00312 
00313 //------------------------------------------------------------------------------
00314 
00315 inline GeMesh::FaceConstIterator::FaceConstIterator()
00316 {
00317 }
00318 
00319 //------------------------------------------------------------------------------
00320 
00321 inline GeMesh::FaceConstIterator::FaceConstIterator(
00322     const GeMesh& mesh,
00323     GeMeshTypes::FaceId faceId
00324 ) : _wrapper( mesh, faceId )
00325 {
00326 }
00327 
00328 //------------------------------------------------------------------------------
00329 
00330 inline GeMesh::FaceConstIterator::FaceConstIterator(
00331     const FaceWrapper& wrapper
00332 ) : _wrapper( wrapper )
00333 {
00334 }
00335 
00336 //------------------------------------------------------------------------------
00337 
00338 inline GeMesh::FaceConstIterator GeMesh::FaceConstIterator::begin(
00339     const GeMesh& mesh
00340 ) {
00341     return FaceConstIterator( mesh, 0 );
00342 }
00343 
00344 //------------------------------------------------------------------------------
00345 
00346 inline GeMesh::FaceConstIterator GeMesh::FaceConstIterator::end(
00347     const GeMesh& mesh
00348 ) {
00349     // Pointer variant of constructor is unchecked.
00350     return FaceConstIterator( FaceWrapper( &mesh, mesh.getNbFaces() ) );
00351 }
00352 
00353 //------------------------------------------------------------------------------
00354 
00355 inline GeMesh::FaceConstIterator& GeMesh::FaceConstIterator::operator++()
00356 {
00357     ++_wrapper._faceId;
00358     return *this;
00359 }
00360 
00361 //------------------------------------------------------------------------------
00362 
00363 inline GeMesh::FaceConstIterator GeMesh::FaceConstIterator::operator++( int )
00364 {
00365     FaceConstIterator copy( *this );
00366     ++_wrapper._faceId;
00367     return copy;
00368 }
00369 
00370 //------------------------------------------------------------------------------
00371 
00372 inline GeMesh::FaceConstIterator& GeMesh::FaceConstIterator::operator--()
00373 {
00374     --_wrapper._faceId;
00375     return *this;
00376 }
00377 
00378 //------------------------------------------------------------------------------
00379 
00380 inline GeMesh::FaceConstIterator GeMesh::FaceConstIterator::operator--( int )
00381 {
00382     FaceConstIterator copy( *this );
00383     --_wrapper._faceId;
00384     return copy;
00385 }
00386 
00387 //------------------------------------------------------------------------------
00388 
00389 inline bool GeMesh::FaceConstIterator::operator == (
00390     const FaceConstIterator& rhs
00391 ) const {
00392     return ( _wrapper._mesh == rhs._wrapper._mesh ) &&
00393         ( _wrapper._faceId == rhs._wrapper._faceId );
00394 }
00395 
00396 //------------------------------------------------------------------------------
00397 
00398 inline bool GeMesh::FaceConstIterator::operator != (
00399     const FaceConstIterator& rhs
00400 ) const {
00401     return !operator == ( rhs );
00402 }
00403 
00404 //------------------------------------------------------------------------------
00405 
00406 inline const GeMesh::FaceWrapper& GeMesh::FaceConstIterator::operator*() const
00407 {
00408     DGFX_ASSERT( _wrapper.isValid() );
00409     return _wrapper;
00410 }
00411 
00412 //------------------------------------------------------------------------------
00413 
00414 inline const GeMesh::FaceWrapper* GeMesh::FaceConstIterator::operator->() const
00415 {
00416     DGFX_ASSERT( _wrapper.isValid() );
00417     return &_wrapper;
00418 }
00419 
00420 FREECLOTH_NAMESPACE_END
00421 
00422 #endif

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