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> 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>
109 if_has_enter(Action &_action,
BaseNode *_node) {
110 _action.enter (_node);
114 template<
typename Action>
116 if_has_enter(Action &,
BaseNode *) {
122 template<
typename Action>
124 if_has_leave(Action &_action,
BaseNode *_node) {
125 _action.leave (_node);
129 template<
typename Action>
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),
380 Vec3d bbMin( FLT_MAX, FLT_MAX, FLT_MAX);
381 Vec3d bbMax(-FLT_MAX, -FLT_MAX, -FLT_MAX);
384 if ((bbMin[0] > bbMax[0]) ||
385 (bbMin[1] > bbMax[1]) ||
386 (bbMin[2] > bbMax[2]))
389 bbMin_.minimize(state_.modelview().transform_point (bbMin));
390 bbMin_.minimize(state_.modelview().transform_point (bbMax));
391 bbMax_.maximize(state_.modelview().transform_point (bbMin));
392 bbMax_.maximize(state_.modelview().transform_point (bbMax));
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_ );
700 drawMode_(_drawMode),
701 blending_(_blending) {}
706 if(state_.blending() == blending_)
710 _node->
draw(state_, drawMode_);
720 _node->
enter(state_, drawMode_);
728 _node->
leave(state_, drawMode_);
759 pickTarget_(_target),
760 drawmode_(_drawmode) {}
774 _node->
enterPick(state_, pickTarget_, drawmode_);
782 _node->
leavePick(state_, pickTarget_, drawmode_);
849 bool isDirty()
const {
return dirty_; };
861 #endif // ACG_SCENEGRAPH_HH defined StatusMode status() const
Get node's status.
FindNodeAction(unsigned int _node_id)
constructor: _node_id is the node to be searched for
void next_render_pass()
increment render pass counter
ChildIter childrenEnd()
Returns: end-iterator of children.
virtual void enter(GLState &, const DrawModes::DrawMode &)
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
unsigned int MultipassBitMask
Multipass pass bit mask type.
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
DrawAction(DrawModes::DrawMode _drawMode, GLState &_state, bool _blending)
Constructor: draws the scenegraph using _drawMode.
virtual DrawModes::DrawMode availableDrawModes() const
void reset_render_pass()
reset render pass counter
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
Hide this node and its children.
void traverse_all(BaseNode *_node, Action &_action)
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
unsigned int getMaxPasses() const
Get the number of required traverse passes from Scenegraph.
Execute action on node first and then on its children.
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
virtual void leavePick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
Draw this node, but hide children.
PickTarget
What target to use for picking.
unsigned int max_render_passes() const
get maximum number of render passes
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
virtual void enterPick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
Hide this node, but draw children.
ChildIter childrenBegin()
Returns: begin-iterator of children.
virtual void leave(GLState &, const DrawModes::DrawMode &)
void traverse(BaseNode *_node, Action &_action)
Namespace providing different geometric functions concerning angles.
DrawMode NONE
not a valid draw mode
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
SetDrawModesAction(DrawModes::DrawMode _mode, bool _force=false)
Set draw modes for all nodes traversed with this action.
bool isDirty() const
Check if node should be redrawn.
void setDirty(bool _dirty=true)
mark node for redrawn
Draw node in second pass.
unsigned int getNodePasses()
Get the number of required node traversals from Scenegraph.
bool multipassStatusActive(const unsigned int _i) const
Get multipass status to traverse in a specific pass.
Execute action the children first and then on this node.
unsigned int getStatusPasses()
Get the number of required status traversals from Scenegraph.
BaseNode * node_ptr()
Get the pointer of the node (is 0 if node was not found)
PickAction(GLState &_state, PickTarget _target, DrawModes::DrawMode _drawmode)
constructor: what picking target to use
unsigned int traverseMode() const
Return how the node should be traversed.
virtual void boundingBox(Vec3d &, Vec3d &)
BaseNode * find_hidden_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.