00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include "OSGEdgeIterator.h"
00049
00050 OSG_USING_NAMESPACE
00051
00052
00053
00054
00055
00056
00067 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
00068
00090 #endif // only include in dev docs
00091
00092
00093
00094
00095
00096
00097 char EdgeIterator::cvsid[] = "@(#)$Id: OSGEdgeIterator.cpp,v 1.1 2005/01/14 11:24:21 a-m-z Exp $";
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 EdgeIterator::EdgeIterator(void) : PrimitiveIterator(),
00110 _edgeIndex(0), _actPrimIndex(), _edgePntIndex()
00111 {
00112 }
00113
00114 EdgeIterator::EdgeIterator(const EdgeIterator &source) :
00115 PrimitiveIterator(source),
00116 _edgeIndex(source._edgeIndex),
00117 _actPrimIndex(source._actPrimIndex),
00118 _edgePntIndex()
00119 {
00120 _edgePntIndex[0] = source._edgePntIndex[0];
00121 _edgePntIndex[1] = source._edgePntIndex[1];
00122 }
00123
00129 EdgeIterator::EdgeIterator(const NodePtr& geo) : PrimitiveIterator(),
00130 _edgeIndex(0), _actPrimIndex(), _edgePntIndex()
00131 {
00132 setGeo(geo);
00133 }
00134
00140 EdgeIterator::EdgeIterator(const GeometryPtr& geo) : PrimitiveIterator(),
00141 _edgeIndex(0), _actPrimIndex(), _edgePntIndex()
00142 {
00143 setGeo(geo);
00144 }
00145
00146
00147 EdgeIterator::~EdgeIterator(void)
00148 {
00149 }
00150
00151
00152
00162 void EdgeIterator::operator++()
00163 {
00164
00165 if(isAtEnd())
00166 return;
00167
00168 ++_edgeIndex;
00169
00170
00171 if(_actPrimIndex >= PrimitiveIterator::getLength() ||
00172 getType() == GL_LINE_STRIP ||
00173 getType() == GL_LINE_LOOP )
00174 {
00175 ++(static_cast<PrimitiveIterator&>(*this));
00176
00177 startPrim();
00178
00179 return;
00180 }
00181
00182 switch(getType())
00183 {
00184 case GL_LINES: _edgePntIndex[0] = _actPrimIndex++;
00185 _edgePntIndex[1] = _actPrimIndex++;
00186 break;
00187 #if 0 // probably to be implemented
00188
00189 case GL_POLYGON: TODO
00190 break;
00191 case GL_TRIANGLES: TODO
00192 break;
00193 case GL_QUAD_STRIP: TODO
00194 break;
00195 case GL_TRIANGLE_STRIP: TODO
00196 break;
00197 case GL_TRIANGLE_FAN: TODO
00198 break;
00199 case GL_QUADS: TODO
00200 break;
00201 #endif // probably to be implemented
00202 default: SWARNING << "EdgeIterator::++: encountered "
00203 << "unknown primitive type "
00204 << getType()
00205 << ", ignoring!" << std::endl;
00206 startPrim();
00207 break;
00208 }
00209 }
00210
00211
00216 void EdgeIterator::startPrim(void)
00217 {
00218
00219 if(isAtEnd())
00220 return;
00221
00222 _edgePntIndex[0] = 0;
00223 _edgePntIndex[1] = 1;
00224 _actPrimIndex = 2;
00225
00226
00227 while(! isAtEnd())
00228 {
00229 switch(getType())
00230 {
00231 case GL_LINES:
00232 case GL_LINE_STRIP:
00233 case GL_LINE_LOOP: if(PrimitiveIterator::getLength() >= 2)
00234 return;
00235 break;
00236 case GL_POINTS:
00237 case GL_TRIANGLES:
00238 case GL_TRIANGLE_STRIP:
00239 case GL_TRIANGLE_FAN:
00240 case GL_POLYGON:
00241 case GL_QUADS:
00242 case GL_QUAD_STRIP:
00243 break;
00244 default: SWARNING << "EdgeIterator::startPrim: encountered "
00245 << "unknown primitive type "
00246 << getType()
00247 << ", ignoring!" << std::endl;
00248 break;
00249 }
00250
00251 ++(static_cast<PrimitiveIterator&>(*this));
00252 }
00253 }
00254
00261 void EdgeIterator::seek(Int32 index)
00262 {
00263 setToBegin();
00264
00265 while(getIndex() != index)
00266 ++(*this);
00267 }
00268
00273 void EdgeIterator::setToBegin(void)
00274 {
00275 PrimitiveIterator::setToBegin();
00276 _edgeIndex = 0;
00277 startPrim();
00278 }
00279
00284 void EdgeIterator::setToEnd(void)
00285 {
00286 PrimitiveIterator::setToEnd();
00287 _actPrimIndex = 0;
00288 }
00289
00290
00291
00292 EdgeIterator& EdgeIterator::operator =(const EdgeIterator &source)
00293 {
00294 if(this == &source)
00295 return *this;
00296
00297 *static_cast<Inherited *>(this) = source;
00298
00299 this->_edgeIndex = source._edgeIndex;
00300 this->_actPrimIndex = source._actPrimIndex;
00301 this->_edgePntIndex[0] = source._edgePntIndex[0];
00302 this->_edgePntIndex[1] = source._edgePntIndex[1];
00303
00304 return *this;
00305 }
00306
00307
00308
00309 bool EdgeIterator::operator <(const EdgeIterator &other) const
00310 {
00311 return
00312 (*static_cast<const Inherited *>(this) < other) ||
00313 ( (*static_cast<const Inherited *>(this) == other) &&
00314 _actPrimIndex < other._actPrimIndex);
00315 }
00316
00317 bool EdgeIterator::operator ==(const EdgeIterator &other) const
00318 {
00319 if(isAtEnd() && other.isAtEnd())
00320 return true;
00321
00322 if(isAtEnd() || other.isAtEnd())
00323 return false;
00324
00325 return
00326 (*static_cast<const Inherited *>(this) == other ) &&
00327 _actPrimIndex == other._actPrimIndex;
00328 }
00329
00330 bool EdgeIterator::operator !=(const EdgeIterator &other) const
00331 {
00332 return !(*this == other);
00333 }