00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include "nvmath/BoundingSphere.h"
00018 #include "nvsg/Object.h"
00019
00020 namespace nvsg
00021 {
00022 class Group;
00023
00025
00026 class Node : public Object
00027 {
00028 public:
00030
00031 NVSG_API virtual const Node * clone( void ) const = 0;
00032
00034
00035 NVSG_API virtual bool isDataShared( void ) const;
00036
00038
00039 NVSG_API virtual DataID getDataID( void ) const;
00040
00042
00043 NVSG_API size_t getNumberOfParents() const;
00044
00046
00049 NVSG_API const Group * getParent( size_t i
00050 ) const;
00051
00053
00055 NVSG_API bool isBoundingSphereValid( void ) const;
00056
00058
00061 NVSG_API const nvmath::Sphere3f & getBoundingSphere( void ) const;
00062
00064 NVSG_API void invalidateBoundingSphere( void ) const;
00065
00067
00068 NVSG_API virtual bool containsCgFx( void ) const;
00069
00071
00072 NVSG_API virtual void invalidateCgFxContainment( void );
00073
00075
00076 NVSG_API virtual bool containsLight( void ) const;
00077
00079
00080 NVSG_API virtual void invalidateLightContainment( void );
00081
00083
00084 NVSG_API virtual bool containsTransparentMaterial( void ) const;
00085
00087
00088 NVSG_API virtual void invalidateTransparentMaterialContainment( void );
00089
00091
00092 NVSG_API virtual bool containsTransparentTexture( void ) const;
00093
00095
00096 NVSG_API virtual void invalidateTransparentTextureContainment( void );
00097
00099
00100 NVSG_API virtual size_t getNumberOfFrames( void ) const;
00101
00103
00104 NVSG_API virtual void invalidateNumberOfFrames( void ) const;
00105
00107 NVSG_API void setAnnotation( const char *anno );
00108
00110 NVSG_API const char * getAnnotation( void ) const;
00111
00112 protected:
00114 NVSG_API Node(void);
00115
00117 NVSG_API Node(const Node& rhs);
00118
00120 NVSG_API virtual ~Node(void);
00121
00123
00124 NVSG_API virtual bool calcBoundingSphere( void ) const = 0;
00125
00127
00129 NVSG_API bool extendBoundingSphere( const nvmath::Sphere3f &sphere
00130 ) const;
00131
00133 NVSG_API void transformBoundingSphere( const nvmath::Mat44f &m
00134 , float factor = 1.0f
00135 ) const;
00136
00137 private:
00138
00139 friend class Group;
00140 void addParent(const Group * group);
00141 void removeParent(const Group * group);
00142
00143
00144 void validateBoundingSphere( void ) const;
00145
00146 private:
00147 std::string * m_annotation;
00148 std::vector<const Group*> m_parents;
00149 mutable nvmath::BoundingSphere m_boundingSphere;
00150 };
00151
00152
00153
00154 inline const char * Node::getAnnotation( void ) const
00155 {
00156 return( m_annotation ? m_annotation->c_str() : NULL );
00157 }
00158
00159 inline size_t Node::getNumberOfParents() const
00160 {
00161 return m_parents.size();
00162 }
00163
00164 inline const Group * Node::getParent( size_t i ) const
00165 {
00166 __ASSERT(i < m_parents.size());
00167 return m_parents[i];
00168 }
00169
00170 inline bool Node::isBoundingSphereValid( void ) const
00171 {
00172 validateBoundingSphere();
00173 return( m_boundingSphere.isValid() );
00174 }
00175
00176 inline const nvmath::Sphere3f & Node::getBoundingSphere( void ) const
00177 {
00178 validateBoundingSphere();
00179 __ASSERT( m_boundingSphere.isValid() );
00180 return( m_boundingSphere.getSphere() );
00181 }
00182
00183 inline bool Node::extendBoundingSphere( const nvmath::Sphere3f &sphere ) const
00184 {
00185 return( m_boundingSphere.extend( sphere ) );
00186 }
00187
00188 inline void Node::transformBoundingSphere( const nvmath::Mat44f &m, float factor ) const
00189 {
00190 validateBoundingSphere();
00191 __ASSERT( m_boundingSphere.isValid() );
00192 m_boundingSphere.transform( m );
00193 m_boundingSphere.enlarge( factor );
00194 }
00195
00196 inline void Node::validateBoundingSphere( void ) const
00197 {
00198 if ( ! m_boundingSphere.isValid() )
00199 {
00200 calcBoundingSphere();
00201 }
00202 }
00203
00204 }