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 "OSGPrimitiveIterator.h"
00049
00050 OSG_USING_NAMESPACE
00051
00052
00053
00054
00055
00056
00057
00066 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
00067
00194 #endif // only include in dev docs
00195
00196
00197
00198
00199
00200 char PrimitiveIterator::cvsid[] = "@(#)$Id: OSGPrimitiveIterator.cpp,v 1.17 2001/11/01 05:55:06 vossg Exp $";
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 PrimitiveIterator::PrimitiveIterator(void) :
00213 _geo ( ),
00214 _ended ( true),
00215 _primIndex ( 0),
00216 _actPointIndex ( 0),
00217 _actPrimType ( 0),
00218 _actPrimLength ( 0),
00219 _types (NullFC),
00220 _lengths (NullFC),
00221 _indices (NullFC),
00222 _nmappings ( 0),
00223 _positionIndex ( -1),
00224 _normalIndex ( -1),
00225 _colorIndex ( -1),
00226 _secondaryColorIndex( -1),
00227 _texcoordsIndex ( -1),
00228 _texcoordsIndex1 ( -1),
00229 _texcoordsIndex2 ( -1),
00230 _texcoordsIndex3 ( -1),
00231 _texcoordsIndex4 ( -1),
00232 _texcoordsIndex5 ( -1),
00233 _texcoordsIndex6 ( -1),
00234 _texcoordsIndex7 ( -1)
00235 {
00236 }
00237
00243 PrimitiveIterator::PrimitiveIterator(const GeometryPtr& geo) :
00244 _geo ( ),
00245 _ended ( true),
00246 _primIndex ( 0),
00247 _actPointIndex ( 0),
00248 _actPrimType ( 0),
00249 _actPrimLength ( 0),
00250 _types (NullFC),
00251 _lengths (NullFC),
00252 _indices (NullFC),
00253 _nmappings ( 0),
00254 _positionIndex ( -1),
00255 _normalIndex ( -1),
00256 _colorIndex ( -1),
00257 _secondaryColorIndex( -1),
00258 _texcoordsIndex ( -1),
00259 _texcoordsIndex1 ( -1),
00260 _texcoordsIndex2 ( -1),
00261 _texcoordsIndex3 ( -1),
00262 _texcoordsIndex4 ( -1),
00263 _texcoordsIndex5 ( -1),
00264 _texcoordsIndex6 ( -1),
00265 _texcoordsIndex7 ( -1)
00266 {
00267 setGeo(geo);
00268 }
00269
00275 PrimitiveIterator::PrimitiveIterator(const NodePtr& geo) :
00276 _geo ( ),
00277 _ended ( true),
00278 _primIndex ( 0),
00279 _actPointIndex ( 0),
00280 _actPrimType ( 0),
00281 _actPrimLength ( 0),
00282 _types (NullFC),
00283 _lengths (NullFC),
00284 _indices (NullFC),
00285 _nmappings ( 0),
00286 _positionIndex ( -1),
00287 _normalIndex ( -1),
00288 _colorIndex ( -1),
00289 _secondaryColorIndex( -1),
00290 _texcoordsIndex ( -1),
00291 _texcoordsIndex1 ( -1),
00292 _texcoordsIndex2 ( -1),
00293 _texcoordsIndex3 ( -1),
00294 _texcoordsIndex4 ( -1),
00295 _texcoordsIndex5 ( -1),
00296 _texcoordsIndex6 ( -1),
00297 _texcoordsIndex7 ( -1)
00298 {
00299 setGeo(geo);
00300 }
00301
00302
00303 PrimitiveIterator::PrimitiveIterator(const PrimitiveIterator &source) :
00304 _geo (source._geo ),
00305 _ended (source._ended ),
00306 _primIndex (source._primIndex ),
00307 _actPointIndex (source._actPointIndex ),
00308 _actPrimType (source._actPrimType ),
00309 _actPrimLength (source._actPrimLength ),
00310 _types (source._types ),
00311 _lengths (source._lengths ),
00312 _indices (source._indices ),
00313 _nmappings (source._nmappings ),
00314 _positionIndex (source._positionIndex ),
00315 _normalIndex (source._normalIndex ),
00316 _colorIndex (source._colorIndex ),
00317 _secondaryColorIndex(source._secondaryColorIndex),
00318 _texcoordsIndex (source._texcoordsIndex ),
00319 _texcoordsIndex1 (source._texcoordsIndex1 ),
00320 _texcoordsIndex2 (source._texcoordsIndex2 ),
00321 _texcoordsIndex3 (source._texcoordsIndex3 ),
00322 _texcoordsIndex4 (source._texcoordsIndex4 ),
00323 _texcoordsIndex5 (source._texcoordsIndex5 ),
00324 _texcoordsIndex6 (source._texcoordsIndex6 ),
00325 _texcoordsIndex7 (source._texcoordsIndex7 )
00326 {
00327 }
00328
00329 PrimitiveIterator::~PrimitiveIterator(void)
00330 {
00331 }
00332
00333
00334
00335
00339 void PrimitiveIterator::setGeo(const GeometryPtr& geo)
00340 {
00341 OSG_ASSERT(geo != NullFC);
00342
00343 _geo = geo;
00344 _types = geo->getTypes();
00345 _lengths = geo->getLengths();
00346 _indices = geo->getIndices();
00347
00348 setToBegin();
00349 }
00350
00351
00355 void PrimitiveIterator::setGeo(const NodePtr& geo)
00356 {
00357 GeometryPtr gc = GeometryPtr::dcast(geo->getCore());
00358
00359 if(gc == NullFC)
00360 {
00361 FWARNING(("PrimitiveIterator::setGeo: called for NodePtr which "
00362 "is not a Geometry!\n"));
00363 }
00364 else
00365 {
00366 setGeo(gc);
00367 }
00368 }
00369
00370
00371
00378 void PrimitiveIterator::operator++()
00379 {
00380 if(isAtEnd())
00381 {
00382 return;
00383 }
00384
00385 _actPointIndex += _actPrimLength;
00386
00387 ++_primIndex;
00388
00389 if(_primIndex >= _types->getSize())
00390 {
00391 _ended = true;
00392 }
00393 else
00394 {
00395 _actPrimType = _types->getValue(_primIndex);
00396 if(_lengths != NullFC)
00397 {
00398 _actPrimLength = _lengths->getValue(_primIndex);
00399 }
00400 else if(_indices != NullFC)
00401 {
00402 _actPrimLength = _indices->getSize() / _nmappings;
00403 }
00404 else
00405 {
00406 _actPrimLength = _geo->getPositions()->getSize() / _nmappings;
00407 }
00408 }
00409 }
00410
00415 void PrimitiveIterator::setToBegin(void)
00416 {
00417 _primIndex = 0;
00418 _actPointIndex = 0;
00419 _ended = false;
00420 _nmappings = _geo->getIndexMapping().size();
00421 _positionIndex = _geo->calcMappingIndex(Geometry::MapPosition);
00422 _normalIndex = _geo->calcMappingIndex(Geometry::MapNormal);
00423 _colorIndex = _geo->calcMappingIndex(Geometry::MapColor);
00424 _secondaryColorIndex = _geo->calcMappingIndex(Geometry::MapSecondaryColor);
00425 _texcoordsIndex = _geo->calcMappingIndex(Geometry::MapTexCoords);
00426 _texcoordsIndex1 = _geo->calcMappingIndex(Geometry::MapTexCoords1);
00427 _texcoordsIndex2 = _geo->calcMappingIndex(Geometry::MapTexCoords2);
00428 _texcoordsIndex3 = _geo->calcMappingIndex(Geometry::MapTexCoords3);
00429 _texcoordsIndex4 = _geo->calcMappingIndex(Geometry::MapTexCoords4);
00430 _texcoordsIndex5 = _geo->calcMappingIndex(Geometry::MapTexCoords5);
00431 _texcoordsIndex6 = _geo->calcMappingIndex(Geometry::MapTexCoords6);
00432 _texcoordsIndex7 = _geo->calcMappingIndex(Geometry::MapTexCoords7);
00433
00434 if(_nmappings == 0)
00435 _nmappings = 1;
00436
00437 if(_types != NullFC && _types->getSize() > 0)
00438 {
00439 _actPrimType = _types->getValue(_primIndex);
00440 if(_lengths != NullFC)
00441 {
00442 _actPrimLength = _lengths->getValue(_primIndex);
00443 }
00444 else if(_indices != NullFC)
00445 {
00446 _actPrimLength = _indices->getSize() / _nmappings;
00447 }
00448 else
00449 {
00450 _actPrimLength = _geo->getPositions()->getSize() / _nmappings;
00451 }
00452 }
00453 else
00454 {
00455 setToEnd();
00456 }
00457 }
00458
00463 void PrimitiveIterator::setToEnd(void)
00464 {
00465 if(_types != NullFC)
00466 _primIndex = _types->getSize();
00467 else
00468 _primIndex = 0;
00469 _actPointIndex = 0;
00470 _ended = true;
00471 }
00472
00479 void PrimitiveIterator::seek(Int32 index)
00480 {
00481 _actPointIndex = 0;
00482 _ended = false;
00483
00484 if(index >= Int32(_types->getSize()))
00485 {
00486 _primIndex = _types->getSize();
00487 _ended = true;
00488 }
00489 else
00490 {
00491 _primIndex = osgMax(0, index);
00492
00493 for(UInt32 j = 0; j < _primIndex; j++)
00494 _actPointIndex += _lengths->getValue(j);
00495
00496 _actPrimType = _types->getValue(_primIndex);
00497 _actPrimLength = _lengths->getValue(_primIndex);
00498 }
00499 }
00500
00501
00502
00503 PrimitiveIterator& PrimitiveIterator::operator =(const PrimitiveIterator &source)
00504 {
00505 if(this == &source)
00506 return *this;
00507
00508 this->_geo = source._geo;
00509 this->_primIndex = source._primIndex;
00510 this->_actPrimType = source._actPrimType;
00511 this->_actPrimLength = source._actPrimLength;
00512 this->_actPointIndex = source._actPointIndex;
00513 this->_types = source._types;
00514 this->_lengths = source._lengths;
00515 this->_indices = source._indices;
00516 this->_ended = source._ended;
00517 this->_nmappings = source._nmappings;
00518 this->_positionIndex = source._positionIndex;
00519 this->_normalIndex = source._normalIndex;
00520 this->_colorIndex = source._colorIndex;
00521 this->_secondaryColorIndex = source._colorIndex;
00522 this->_texcoordsIndex = source._texcoordsIndex;
00523 this->_texcoordsIndex1 = source._texcoordsIndex1;
00524 this->_texcoordsIndex2 = source._texcoordsIndex2;
00525 this->_texcoordsIndex3 = source._texcoordsIndex3;
00526 this->_texcoordsIndex4 = source._texcoordsIndex4;
00527 this->_texcoordsIndex5 = source._texcoordsIndex5;
00528 this->_texcoordsIndex6 = source._texcoordsIndex6;
00529 this->_texcoordsIndex7 = source._texcoordsIndex7;
00530
00531 return *this;
00532 }
00533
00534
00535
00539 bool PrimitiveIterator::operator <(const PrimitiveIterator &other) const
00540 {
00541 return _geo == other._geo &&
00542 _primIndex <= other._primIndex;
00543 }
00544
00548 bool PrimitiveIterator::operator ==(const PrimitiveIterator &other) const
00549 {
00550 return _ended == other._ended &&
00551 _geo == other._geo &&
00552 _primIndex == other._primIndex;
00553 }
00554
00558 bool PrimitiveIterator::operator !=(const PrimitiveIterator &other) const
00559 {
00560 return !(*this == other);
00561 }