63 #ifndef ACG_SCENEGRAPH_HH
64 #define ACG_SCENEGRAPH_HH
69 #include "BaseNode.hh"
70 #include "DrawModes.hh"
71 #include "../Math/VectorT.hh"
74 #include <QMouseEvent>
79 namespace SceneGraph {
87 template<
bool C,
typename T =
void>
95 #define HAS_MEM_FUNC(func) \
96 template<typename T, typename Sign> \
98 template <typename U, U> struct type_check; \
99 template <typename _1> static char (& chk(type_check<Sign, &_1::func> *))[1]; \
100 template <typename > static char (& chk(...))[2]; \
101 static bool const value = sizeof(chk<T>(0)) == 1; \
107 template<typename Action>
108 typename
enable_if<has_enter <Action,
void (Action::*) (
BaseNode *) >::value,
void>::type
109 if_has_enter(Action &_action,
BaseNode *_node) {
110 _action.enter (_node);
114 template<
typename Action>
115 typename enable_if<!has_enter <Action, void (Action::*) (BaseNode *) >::value,
void>::type
116 if_has_enter(Action &,
BaseNode *) {
122 template<typename Action>
123 typename enable_if<has_leave <Action,
void (Action::*) (
BaseNode *) >::value,
void>::type
124 if_has_leave(Action &_action,
BaseNode *_node) {
125 _action.leave (_node);
129 template<
typename Action>
130 typename enable_if<!has_enter <Action, void (Action::*) (BaseNode *) >::value,
void>::type
131 if_has_leave(Action &,
BaseNode *) {
141 template <
class Action>
160 if_has_enter (_action, _node);
164 process_children &= _action(_node);
167 if (process_children)
193 if_has_leave (_action, _node);
206 template <
class Action>
212 bool process_children(
true);
215 if_has_enter(_action, _node);
219 process_children &= _action(_node);
241 if_has_leave (_action, _node);
258 template <
class Action>
275 if_has_enter(_action, _node);
282 process_children &= _action(_node);
284 if (process_children) {
309 if_has_leave(_action, _node);
333 template <
class Action>
347 for(
unsigned int pass = BaseNode::PASS_1; pass <= (BaseNode::PASS_1 + max_passes); ++pass) {
373 bbMin_( FLT_MAX, FLT_MAX, FLT_MAX),
374 bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX),
384 if ((bbMin[0] > bbMax[0]) ||
385 (bbMin[1] > bbMax[1]) ||
386 (bbMin[2] > bbMax[2]))
413 Vec3d bbMin_, bbMax_;
437 statusPasses_(BaseNode::ALLPASSES),
438 nodePasses_(BaseNode::ALLPASSES)
447 if ( statusPass != BaseNode::ALLPASSES) {
454 statusPass = statusPass >> 1;
456 while( statusPass != 0u ) {
457 statusPass = statusPass >> 1;
460 statusPasses_ = c > statusPasses_ ? c : statusPasses_;
468 if ( nodePass != BaseNode::ALLPASSES) {
475 nodePass = nodePass >> 1;
477 while(nodePass != 0u) {
478 nodePass = nodePass >> 1;
481 nodePasses_ = c > nodePasses_ ? c : nodePasses_;
492 unsigned int maxpasses = std::max(statusPasses_,nodePasses_);
495 return maxpasses == 0 ? 1 : maxpasses;
508 unsigned int getNodePasses() {
return nodePasses_ == 0 ? 1 : nodePasses_; };
512 unsigned int statusPasses_;
513 unsigned int nodePasses_;
535 node_id_(_node_id), node_ptr_(0) {}
539 if (_node->
id() == node_id_)
552 unsigned int node_id_;
662 }
else if ( availableModes & newModes_ ) {
664 _node->
drawMode( availableModes & newModes_ );
675 DrawModes::DrawMode newModes_;
700 drawMode_(_drawMode),
701 blending_(_blending) {}
710 _node->
draw(state_, drawMode_);
720 _node->
enter(state_, drawMode_);
728 _node->
leave(state_, drawMode_);
736 DrawModes::DrawMode drawMode_;
759 pickTarget_(_target),
760 drawmode_(_drawmode) {}
774 _node->
enterPick(state_, pickTarget_, drawmode_);
782 _node->
leavePick(state_, pickTarget_, drawmode_);
791 DrawModes::DrawMode drawmode_;
849 bool isDirty()
const {
return dirty_; };
861 #endif // ACG_SCENEGRAPH_HH defined
Namespace providing different geometric functions concerning angles.
DrawAction(DrawModes::DrawMode _drawMode, GLState &_state, bool _blending)
Constructor: draws the scenegraph using _drawMode.
PickTarget
What target to use for picking.
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
bool blending()
get whether transparenet or solid objects should be drawn
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
void next_render_pass()
increment render pass counter
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
bool isDirty() const
Check if node should be redrawn.
unsigned int MultipassBitMask
Multipass pass bit mask type.
Hide this node and its children.
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
Execute action on node first and then on its children.
ChildIter childrenBegin()
Returns: begin-iterator of children.
virtual void leavePick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
virtual void enter(GLState &, const DrawModes::DrawMode &)
const GLMatrixd & modelview() const
get modelview matrix
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
void reset_render_pass()
reset render pass counter
virtual void enterPick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
Draw this node, but hide children.
unsigned int getMaxPasses() const
Get the number of required traverse passes from Scenegraph.
Draw node in second pass.
BaseNode * node_ptr()
Get the pointer of the node (is 0 if node was not found)
Execute action the children first and then on this node.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
virtual DrawModes::DrawMode availableDrawModes() const
StatusMode status() const
Get node's status.
virtual void boundingBox(Vec3d &, Vec3d &)
unsigned int getStatusPasses()
Get the number of required status traversals from Scenegraph.
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
BaseNode * find_hidden_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
void setDirty(bool _dirty=true)
mark node for redrawn
unsigned int max_render_passes() const
get maximum number of render passes
SetDrawModesAction(DrawModes::DrawMode _mode, bool _force=false)
Set draw modes for all nodes traversed with this action.
void traverse_all(BaseNode *_node, Action &_action)
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
unsigned int getNodePasses()
Get the number of required node traversals from Scenegraph.
Hide this node, but draw children.
bool multipassStatusActive(const unsigned int _i) const
Get multipass status to traverse in a specific pass.
FindNodeAction(unsigned int _node_id)
constructor: _node_id is the node to be searched for
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
void traverse(BaseNode *_node, Action &_action)
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
ChildIter childrenEnd()
Returns: end-iterator of children.
PickAction(GLState &_state, PickTarget _target, DrawModes::DrawMode _drawmode)
constructor: what picking target to use
DrawMode NONE
not a valid draw mode
unsigned int traverseMode() const
Return how the node should be traversed.
virtual void leave(GLState &, const DrawModes::DrawMode &)