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 #include "OSGNodePtr.h"
00048 #include "OSGLineIterator.h"
00049
00050 OSG_USING_NAMESPACE
00051
00052
00053
00054
00055
00056
00067 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
00068
00084 #endif // only include in dev docs
00085
00086
00087
00088
00089
00090
00091 char LineIterator::cvsid[] = "@(#)$Id: OSGLineIterator.cpp,v 1.1 2005/01/14 11:24:22 a-m-z Exp $";
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 LineIterator::LineIterator(void) : PrimitiveIterator(),
00104 _lineIndex(0), _actPrimIndex(0), _linePntIndex()
00105 {
00106 }
00107
00108 LineIterator::LineIterator(const LineIterator &source) :
00109 PrimitiveIterator(source),
00110 _lineIndex(source._lineIndex), _actPrimIndex(source._actPrimIndex),
00111 _linePntIndex()
00112 {
00113 _linePntIndex[0] = source._linePntIndex[0];
00114 _linePntIndex[1] = source._linePntIndex[1];
00115 }
00116
00117
00123 LineIterator::LineIterator(const GeometryPtr& geo) :
00124 PrimitiveIterator(),
00125 _lineIndex(0), _actPrimIndex(0), _linePntIndex()
00126 {
00127 setGeo(geo);
00128 }
00129
00130
00137 LineIterator::LineIterator(const NodePtr& geo) :
00138 PrimitiveIterator(),
00139 _lineIndex(0), _actPrimIndex(0), _linePntIndex()
00140 {
00141 setGeo(geo);
00142 }
00143
00144
00145 LineIterator::~LineIterator(void)
00146 {
00147 }
00148
00149
00150
00154 void LineIterator::operator++()
00155 {
00156
00157 if(isAtEnd())
00158 return;
00159
00160 ++_lineIndex;
00161
00162
00163 if((_actPrimIndex > getLength()) ||
00164 (_actPrimIndex == getLength() && getType() != GL_LINE_LOOP))
00165 {
00166 ++(static_cast<PrimitiveIterator&>(*this));
00167 startPrim();
00168
00169 return;
00170 }
00171
00172
00173 switch(getType())
00174 {
00175 case GL_LINES: _linePntIndex[0] = _actPrimIndex++;
00176 _linePntIndex[1] = _actPrimIndex++;
00177 break;
00178 case GL_LINE_STRIP: _linePntIndex[0] = _linePntIndex[1];
00179 _linePntIndex[1] = _actPrimIndex++;
00180 break;
00181 case GL_LINE_LOOP: _linePntIndex[0] = _linePntIndex[1];
00182 if(_actPrimIndex < getLength())
00183 {
00184 _linePntIndex[1] = _actPrimIndex++;
00185 }
00186 else
00187 {
00188 _linePntIndex[1] = 0;
00189 _actPrimIndex++;
00190 }
00191 break;
00192 default: SWARNING << "LineIterator::++: encountered "
00193 << "unknown primitive type "
00194 << getType()
00195 << ", ignoring!" << std::endl;
00196 startPrim();
00197 break;
00198 }
00199 }
00200
00201
00206 void LineIterator::startPrim(void)
00207 {
00208
00209 if(isAtEnd())
00210 return;
00211
00212 _linePntIndex[0] = 0;
00213 _linePntIndex[1] = 1;
00214 _actPrimIndex = 2;
00215
00216
00217 while(! isAtEnd())
00218 {
00219 switch(getType())
00220 {
00221 case GL_POINTS:
00222 case GL_TRIANGLES:
00223 case GL_TRIANGLE_STRIP:
00224 case GL_TRIANGLE_FAN:
00225 case GL_QUADS:
00226 case GL_QUAD_STRIP:
00227 case GL_POLYGON:
00228 break;
00229 case GL_LINES:
00230 case GL_LINE_STRIP:
00231 case GL_LINE_LOOP: if(getLength() >= 2)
00232 return;
00233 break;
00234 default: SWARNING << "LineIterator::startPrim: "
00235 << "encountered "
00236 << "unknown primitive type "
00237 << getType()
00238 << ", ignoring!" << std::endl;
00239 break;
00240 }
00241
00242 ++(static_cast<PrimitiveIterator&>(*this));
00243 }
00244 }
00245
00246
00253 void LineIterator::seek(Int32 index)
00254 {
00255 setToBegin();
00256
00257 while(getIndex() != index)
00258 ++(*this);
00259 }
00260
00261
00266 void LineIterator::setToBegin(void)
00267 {
00268 PrimitiveIterator::setToBegin();
00269 _lineIndex = 0;
00270 startPrim();
00271 }
00272
00277 void LineIterator::setToEnd(void)
00278 {
00279 PrimitiveIterator::setToEnd();
00280 _actPrimIndex = 0;
00281 }
00282
00283
00284
00285 LineIterator& LineIterator::operator =(const LineIterator &source)
00286 {
00287 if(this == &source)
00288 return *this;
00289
00290 *static_cast<Inherited *>(this) = source;
00291
00292 this->_lineIndex = source._lineIndex;
00293 this->_actPrimIndex = source._actPrimIndex;
00294 this->_linePntIndex[0] = source._linePntIndex[0];
00295 this->_linePntIndex[1] = source._linePntIndex[1];
00296
00297 return *this;
00298 }
00299
00300
00301
00302 bool LineIterator::operator <(const LineIterator &other) const
00303 {
00304 return
00305 (*static_cast<const Inherited *>(this) < other) ||
00306 ( (*static_cast<const Inherited *>(this) == other) &&
00307 _actPrimIndex < other._actPrimIndex);
00308 }
00309
00310 bool LineIterator::operator ==(const LineIterator &other) const
00311 {
00312 if(isAtEnd() && other.isAtEnd())
00313 return true;
00314
00315 if(isAtEnd() || other.isAtEnd())
00316 return false;
00317
00318 return
00319 (*static_cast<const Inherited *>(this) == other ) &&
00320 _actPrimIndex == other._actPrimIndex;
00321 }
00322
00323 bool LineIterator::operator !=(const LineIterator &other) const
00324 {
00325 return !(*this == other);
00326 }