00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include <stack>
00016
00017 #include "nvsgcommon.h"
00018
00019 #include "nvsg/Object.h"
00020 #include "nvutil/MemFunTbl.h"
00021 #include "nvutil/SWMRSync.h"
00022
00023
00024 namespace nvmath
00025 {
00026 class Trafo;
00027 }
00028 namespace nvsg
00029 {
00030 class AnimatedQuads;
00031 class AnimatedTransform;
00032 class AnimatedTriangles;
00033 class CgFx;
00034 class CullData;
00035 class DirectedLight;
00036 class Drawable;
00037 class FaceAttribute;
00038 class GeoNode;
00039 class GeoSet;
00040 class Group;
00041 class HighlightBox;
00042 class HighlightEdges;
00043 class JitterCamera;
00044 class LightSource;
00045 class LOD;
00046 class Material;
00047 class Node;
00048 class ParallelCamera;
00049 class PerspectiveCamera;
00050 class PointLight;
00051 class Quads;
00052 class QuadStrips;
00053 class SimpleCamera;
00054 class SkinnedTriangles;
00055 class SpotLight;
00056 class StateSet;
00057 class StereoCamera;
00058 class TextureAttribute;
00059 class TextureAttributeItem;
00060 class Transform;
00061 class Triangles;
00062 class TriStrips;
00063 class Switch;
00064 class Scene;
00065 class ViewState;
00066 class VNVector;
00067 template<typename T> class FramedAnimation;
00068 template<typename T> class LinearInterpolatedAnimation;
00069 }
00070
00071 namespace nvtraverser
00072 {
00073
00075
00089 class Traverser : public nvutil::RCObject
00090 {
00091 public:
00092
00094
00104 NVSG_API void apply(
00105 const nvsg::ViewState * viewState
00106 , const nvsg::Scene * scene
00107 );
00108
00109 protected:
00110
00112
00114 NVSG_API Traverser( bool readOnly = true );
00115
00117 NVSG_API virtual ~Traverser(void);
00118
00120
00128 NVSG_API virtual void doApply(
00129 const nvsg::ViewState * viewState
00130 , const nvsg::Scene * scene
00131 );
00132
00134
00151 template<typename HandlerType>
00152 void addObjectHandler(
00153 unsigned int objectCode
00154 , HandlerType handler
00155 );
00156
00158
00162 void traverseObject(
00163 const nvsg::Object* object
00164 );
00165
00167
00172 template <typename T>
00173 void traverseObject(
00174 const nvsg::Object* object
00175 , T arg
00176 );
00177
00178
00179
00180
00181
00183
00188 NVSG_API virtual void handleGeoNode(
00189 const nvsg::GeoNode * p
00190 );
00191
00193
00198 NVSG_API virtual void handleGroup(
00199 const nvsg::Group * p
00200 );
00201
00203
00208 NVSG_API virtual void handleLOD(
00209 const nvsg::LOD * p
00210 );
00211
00213
00218 NVSG_API virtual void handleSwitch(
00219 const nvsg::Switch * p
00220 );
00221
00223
00228 NVSG_API virtual void handleTransform(
00229 const nvsg::Transform * p
00230 );
00231
00233
00238 NVSG_API virtual void handleAnimatedTransform(
00239 const nvsg::AnimatedTransform * p
00240 );
00241
00243
00248 NVSG_API virtual void handleDirectedLight(
00249 const nvsg::DirectedLight * p
00250 );
00251
00253
00258 NVSG_API virtual void handlePointLight(
00259 const nvsg::PointLight * p
00260 );
00261
00263
00268 NVSG_API virtual void handleSpotLight(
00269 const nvsg::SpotLight * p
00270 );
00271
00272
00273
00274
00275
00277
00282 NVSG_API virtual void handleQuads(
00283 const nvsg::Quads * p
00284 );
00285
00287
00292 NVSG_API virtual void handleAnimatedQuads(
00293 const nvsg::AnimatedQuads * p
00294 );
00295
00297
00302 NVSG_API virtual void handleQuadStrips(
00303 const nvsg::QuadStrips * p
00304 );
00305
00307
00312 NVSG_API virtual void handleTriangles(
00313 const nvsg::Triangles * p
00314 );
00315
00317
00322 NVSG_API virtual void handleAnimatedTriangles(
00323 const nvsg::AnimatedTriangles * p
00324 );
00325
00327
00332 NVSG_API virtual void handleSkinnedTriangles(
00333 const nvsg::SkinnedTriangles * p
00334 );
00335
00337
00342 NVSG_API virtual void handleTriStrips(
00343 const nvsg::TriStrips * p
00344 );
00345
00346
00347
00348
00349
00351
00356 NVSG_API virtual void handleStateSet(
00357 const nvsg::StateSet * p
00358 );
00359
00361
00366 NVSG_API virtual void handleCgFx(
00367 const nvsg::CgFx * p
00368 );
00369
00371
00376 NVSG_API virtual void handleFaceAttribute(
00377 const nvsg::FaceAttribute * p
00378 );
00379
00381
00386 NVSG_API virtual void handleMaterial(
00387 const nvsg::Material * p
00388 );
00389
00391
00396 NVSG_API virtual void handleTextureAttribute(
00397 const nvsg::TextureAttribute * p
00398 );
00399
00401
00406 NVSG_API virtual void handleTextureAttributeItem(
00407 const nvsg::TextureAttributeItem * p
00408 , size_t tu
00409 );
00410
00411
00412
00413
00414
00416
00423 NVSG_API virtual void handleJitterCamera(
00424 const nvsg::JitterCamera * p
00425 , const nvsg::Node * root
00426 );
00427
00429
00436 NVSG_API virtual void handleParallelCamera(
00437 const nvsg::ParallelCamera * p
00438 , const nvsg::Node * root
00439 );
00440
00442
00449 NVSG_API virtual void handlePerspectiveCamera(
00450 const nvsg::PerspectiveCamera * p
00451 , const nvsg::Node * root
00452 );
00453
00455
00462 NVSG_API virtual void handleStereoCamera(
00463 const nvsg::StereoCamera * p
00464 , const nvsg::Node * root
00465 );
00466
00467
00468
00469
00470
00472
00477 NVSG_API virtual void handleFramedTrafoAnimation(
00478 const nvsg::FramedAnimation<nvmath::Trafo> * p
00479 );
00480
00482
00487 NVSG_API virtual void handleFramedVNVectorAnimation(
00488 const nvsg::FramedAnimation<nvsg::VNVector> * p
00489 );
00490
00492
00498 NVSG_API virtual void handleLinearInterpolatedTrafoAnimation(
00499 const nvsg::LinearInterpolatedAnimation<nvmath::Trafo> * p
00500 );
00501
00503
00509 NVSG_API virtual void handleLinearInterpolatedVNVectorAnimation(
00510 const nvsg::LinearInterpolatedAnimation<nvsg::VNVector> * p
00511 );
00512
00513
00514
00515
00516
00518
00523 NVSG_API virtual void handleHighlightBox(
00524 const nvsg::HighlightBox * p
00525 , const nvsg::GeoSet * geoSet
00526 );
00527
00529
00534 NVSG_API virtual void handleHighlightEdges(
00535 const nvsg::HighlightEdges * p
00536 , const nvsg::GeoSet * geoSet
00537 );
00538
00539
00541
00544 NVSG_API virtual bool preTraverseRoot(
00545 const nvsg::SimpleCamera *p
00546 , const nvsg::Node *root
00547 );
00548
00550
00552 NVSG_API virtual void postTraverseRoot(
00553 const nvsg::SimpleCamera *p
00554 , const nvsg::Node *root
00555 );
00556
00558
00560 NVSG_API virtual void preTraverseGroup(
00561 const nvsg::Group *p
00562 );
00563
00565
00567 NVSG_API virtual void postTraverseGroup(
00568 const nvsg::Group *p
00569 );
00570
00572
00575 NVSG_API virtual bool preTraverseDrawable( const nvsg::Drawable *p
00576 );
00577
00579
00581 NVSG_API virtual void traverseLight(
00582 const nvsg::LightSource * p
00583 );
00584
00586
00588 template<typename T>
00589 T * beginEdit( const T * obj
00590 ) const
00591 {
00592 __TRACE();
00593 __ASSERT( ! m_readOnly );
00594 return const_cast<T *>(obj);
00595 }
00596
00598
00600 template<typename T>
00601 const T * endEdit( const T * obj
00602 ) const
00603 {
00604 __TRACE();
00605 return( obj );
00606 }
00607
00608 protected:
00609 std::stack<size_t> m_lodStack;
00610 std::stack<const nvsg::CullData *> m_cullStack;
00611 std::stack<const nvsg::Group *> m_groupStack;
00612
00613 const nvsg::StateSet * m_defaultStateSet;
00614 const nvsg::StateSet * m_overrideStateSet;
00615
00616
00617 private:
00618
00619 void traverse(const nvsg::GeoNode * p);
00620 void traverse(const nvsg::GeoNode * p, size_t i);
00621
00622 template <typename GrpType>
00623 void traverseGroup(const GrpType * p);
00624
00625 void traverse(const nvsg::Group * p);
00626 void traverse(const nvsg::Group * p, const nvsg::CullData * cd);
00627
00628 void traverse(const nvsg::LOD * p);
00629 void traverse(const nvsg::LOD * p, const nvsg::CullData * cd);
00630
00631 void traverse(const nvsg::Switch * p);
00632 void traverse(const nvsg::Switch * p, const nvsg::CullData * cd);
00633
00634 void traverse(const nvsg::SimpleCamera *p, const nvsg::Node *root);
00635
00636 bool waitToRead( const nvutil::ISWMRSync *obj ) const;
00637 void doneReading( const nvutil::ISWMRSync *obj ) const;
00638 bool waitToWrite( const nvutil::ISWMRSync *obj ) const;
00639 void doneWriting( const nvutil::ISWMRSync *obj ) const;
00640
00641 private:
00642 nvutil::MemFunTbl<Traverser> * m_mftbl;
00643
00644 bool m_readOnly;
00645 bool (Traverser::*m_pfnLock)( const nvutil::ISWMRSync *obj ) const;
00646 void (Traverser::*m_pfnUnlock)( const nvutil::ISWMRSync *obj ) const;
00647 };
00648
00649 template<typename HandlerType>
00650 inline void Traverser::addObjectHandler(unsigned int objectCode, HandlerType handler)
00651 {
00652 m_mftbl->addEntry(objectCode, handler);
00653 }
00654
00655 inline bool Traverser::waitToRead( const nvutil::ISWMRSync *obj ) const
00656 {
00657 return( obj->waitToRead() );
00658 }
00659
00660 inline void Traverser::doneReading( const nvutil::ISWMRSync *obj ) const
00661 {
00662 return( obj->doneReading() );
00663 }
00664
00665 inline bool Traverser::waitToWrite( const nvutil::ISWMRSync *obj ) const
00666 {
00667 return( obj->waitToWrite() );
00668 }
00669
00670 inline void Traverser::doneWriting( const nvutil::ISWMRSync *obj ) const
00671 {
00672 return( obj->doneWriting() );
00673 }
00674
00675 inline void Traverser::traverseObject(const nvsg::Object* object)
00676 {
00677 __TRACE();
00678 __ASSERT(object->getObjectCode()!=nvsg::OC_INVALID);
00679 unsigned int oc = object->getObjectCode();
00680
00681 if ( m_mftbl->testEntry(oc) && (this->*m_pfnLock)( object ) )
00682 {
00683 #if !defined(_WIN64) && defined(_WIN32) && defined(_DEBUG)
00684 void * __esp__0;
00685 void * __esp__1;
00686 __asm mov __esp__0, esp
00687 #endif
00688 (this->*(void (Traverser::*)(const nvsg::Object*))(*m_mftbl)[oc])(object);
00689 #if !defined(_WIN64) && defined(_WIN32) && defined(_DEBUG)
00690 __asm mov __esp__1, esp
00691 __ASSERT(__esp__1==__esp__0);
00692 #endif
00693 (this->*m_pfnUnlock)( object );
00694 }
00695 }
00696
00697 template <typename T>
00698 inline void Traverser::traverseObject( const nvsg::Object* object, T arg)
00699 {
00700 __TRACE();
00701 __ASSERT(object->getObjectCode()!=nvsg::OC_INVALID);
00702 unsigned int oc = object->getObjectCode();
00703
00704 if ( m_mftbl->testEntry(oc) && (this->*m_pfnLock)( object ) )
00705 {
00706 #if !defined(_WIN64) && defined(_WIN32) && defined(_DEBUG)
00707 void * __esp__0;
00708 void * __esp__1;
00709 __asm mov __esp__0, esp
00710 #endif
00711 (this->*(void (Traverser::*)(const nvsg::Object*, T))(*m_mftbl)[oc])(object, arg);
00712 #if !defined(_WIN64) && defined(_WIN32) && defined(_DEBUG)
00713 __asm mov __esp__1, esp
00714 __ASSERT(__esp__1==__esp__0);
00715 #endif
00716 (this->*m_pfnUnlock)( object );
00717 }
00718 }
00719
00720 }