Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

GeometryIterator.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id:  $
00022 */
00023 
00024 
00025 #include "Teddy/Models/GeometryIterator.h"
00026 #include "Teddy/Models/Element.h"
00027 
00028 
00029 #if 0
00030 
00031 namespace Teddy  {
00032 namespace Models {
00033 
00034 
00035 GeometryIterator::GeometryIterator( Geometry *g ){
00036     this->geometry = g;
00037 }
00038 
00039 
00040 /*virtual*/ GeometryIterator::~GeometryIterator(){
00041 }
00042 
00043 
00044 unsigned long GeometryIterator::countCSGFaceElements(){
00045     unsigned long num_csg_faces = 0;
00046     list<Element*>::const_iterator e_it = geometry->elements.begin();
00047     while( e_it!=geometry->elements.end() ){
00048         Element *e = *e_it;
00049         num_csg_faces += e->countCSGFaceElements();
00050         e_it++;
00051     }
00052     return num_csg_faces;
00053 }
00054 
00055 
00056 unsigned long GeometryIterator::countCSGVertexElements(){
00057     unsigned long num_csg_vertices = 0;
00058     list<Element*>::const_iterator e_it = geometry->elements.begin();
00059     while( e_it!=geometry->elements.end() ){
00060         num_csg_vertices += (*e_it)->countCSGFaceElements();
00061         e_it++;
00062     }
00063     return num_csg_vertices;
00064 }
00065 
00066 
00067 CSG_FaceIteratorDescriptor GeometryIterator::getFaceIterator(){
00068     CSG_FaceIteratorDescriptor res;
00069     res.it           = (CSG_IteratorPtr)this;
00070     res.Done         = GeometryIterator::FaceItDone;
00071     res.Fill         = GeometryIterator::FaceItFill;
00072     res.Step         = GeometryIterator::FaceItStep;
00073     res.Reset        = GeometryIterator::FaceItReset;
00074     res.num_elements = countCSGFaceElements();
00075     face_e_it        = geometry->elements.begin();
00076     Element *e       = *face_e_it;
00077     e->initCSGFace( this );
00078     return res;
00079 }
00080 
00081 
00082 CSG_VertexIteratorDescriptor GeometryIterator::getVertexIterator(){
00083     CSG_VertexIteratorDescriptor res;
00084     res.it           = (CSG_IteratorPtr)this;
00085     res.Done         = GeometryIterator::VertexItDone;
00086     res.Fill         = GeometryIterator::VertexItFill;
00087     res.Step         = GeometryIterator::VertexItStep;
00088     res.Reset        = GeometryIterator::VertexItReset;
00089     res.num_elements = countCSGVertexElements();
00090     vertex_e_it      = geometry->elements.begin();
00091     Element *e       = *vertex_e_it;
00092     e->initCSGVertex( this );
00093     return res;
00094 }
00095 
00096 
00097 int GeometryIterator::faceDone(){
00098     //  NO-OP
00099     return 1;
00100 }
00101 
00102 
00103 void GeometryIterator::faceFill( CSG_IFace *face ){
00104     Element *e = *face_e_it;
00105     e->fillCSGFace( this, face );
00106 }
00107 
00108 
00109 void GeometryIterator::faceStep(){
00110     Element *e          = *face_e_it;
00111     bool     e_has_more = e->stepCSGFace( this );
00112     if( e_has_more == false ){
00113         face_e_it++;
00114         e = *face_e_it;
00115         e->initCSGFace( this );
00116     }
00117 }
00118 
00119 
00120 void GeometryIterator::faceReset(){
00121     face_e_it  =  geometry->elements.begin();
00122     Element *e = *face_e_it;
00123     e->initCSGFace( this );
00124 }
00125 
00126 
00127 int GeometryIterator::vertexDone(){
00128     //  NO-OP
00129     return 1;
00130 }
00131 
00132 
00133 void GeometryIterator::vertexFill( CSG_IVertex *vertex ){
00134     Element *e = *vertex_e_it;
00135     e->fillCSGVertex( this, vertex );
00136 }
00137 
00138 
00139 void GeometryIterator::vertexStep(){
00140     Element *e          = *vertex_e_it;
00141     bool     e_has_more = e->stepCSGVertex( this );
00142     if( e_has_more == false ){
00143         vertex_e_it++;
00144         e = *vertex_e_it;
00145         e->initCSGVertex( this );
00146     }
00147 }
00148 
00149 
00150 void GeometryIterator::vertexReset(){
00151     vertex_e_it =  geometry->elements.begin();
00152     Element *e  = *vertex_e_it;
00153     e->initCSGVertex( this );
00154 }
00155 
00156 
00157 /*static*/ int GeometryIterator::FaceItDone( CSG_IteratorPtr it ){
00158     GeometryIterator *g = (GeometryIterator *)( it );
00159     return g->faceDone();
00160 }
00161 
00162 /*static*/ void GeometryIterator::FaceItFill( CSG_IteratorPtr it, CSG_IFace *face ){
00163     GeometryIterator *g = (GeometryIterator *)( it );
00164     g->faceFill( face );
00165 }
00166 
00167 /*static*/ void GeometryIterator::FaceItStep( CSG_IteratorPtr it ){
00168     GeometryIterator *g = (GeometryIterator *)( it );
00169     g->faceStep();
00170 }
00171 
00172 
00173 /*static*/ void GeometryIterator::FaceItReset( CSG_IteratorPtr it ){
00174     GeometryIterator *g = (GeometryIterator *)( it );
00175     g->faceReset();
00176 }
00177 
00178 
00179 /*static*/ int GeometryIterator::VertexItDone( CSG_IteratorPtr it ){
00180     GeometryIterator *g = (GeometryIterator *)( it );
00181     return g->vertexDone();
00182 }
00183 
00184 
00185 /*static*/ void GeometryIterator::VertexItFill( CSG_IteratorPtr it, CSG_IVertex *vertex ){
00186     GeometryIterator *g = (GeometryIterator *)( it );
00187     g->vertexFill( vertex );
00188 }
00189 
00190 
00191 /*static*/ void GeometryIterator::VertexItStep( CSG_IteratorPtr it ){
00192     GeometryIterator *g = (GeometryIterator *)( it );
00193     g->vertexStep();
00194 }
00195 /*static*/ void GeometryIterator::VertexItReset( CSG_IteratorPtr it ){
00196     GeometryIterator *g = (GeometryIterator *)( it );
00197     g->vertexReset();
00198 }
00199 
00200 
00201 };  //  namespace Models
00202 };  //  namespace Teddy
00203 
00204 
00205 #endif
00206