57#ifndef ACG_SCENEGRAPH_HH
58#define ACG_SCENEGRAPH_HH
64#include "DrawModes.hh"
65#include "../Math/VectorT.hh"
81template<
bool C,
typename T =
void>
89#define HAS_MEM_FUNC(func) \
90 template<typename T, typename Sign> \
92 template <typename U, U> struct type_check; \
93 template <typename _1> static char (& chk(type_check<Sign, &_1::func> *))[1]; \
94 template <typename > static char (& chk(...))[2]; \
95 static bool const value = sizeof(chk<T>(0)) == 1; \
101template<
typename Action>
102typename enable_if<has_enter <Action, void (Action::*) (
BaseNode *) >::value,
void>::type
103if_has_enter(Action &_action,
BaseNode *_node) {
104 _action.enter (_node);
108template<
typename Action>
109typename enable_if<!has_enter <Action, void (Action::*) (
BaseNode *) >::value,
void>::type
116template<
typename Action>
117typename enable_if<has_leave <Action, void (Action::*) (
BaseNode *) >::value,
void>::type
118if_has_leave(Action &_action,
BaseNode *_node) {
119 _action.leave (_node);
123template<
typename Action>
124typename enable_if<!has_enter <Action, void (Action::*) (
BaseNode *) >::value,
void>::type
135template <
class Action>
154 if_has_enter (_action, _node);
158 process_children &= _action(_node);
161 if (process_children)
187 if_has_leave (_action, _node);
200template <
class Action>
206 bool process_children(
true);
209 if_has_enter(_action, _node);
213 process_children &= _action(_node);
235 if_has_leave (_action, _node);
252template <
class Action>
269 if_has_enter(_action, _node);
276 process_children &= _action(_node);
278 if (process_children) {
303 if_has_leave(_action, _node);
327template <
class Action>
341 for(
unsigned int pass = BaseNode::PASS_1; pass <= (BaseNode::PASS_1 + max_passes); ++pass) {
367 bbMin_( FLT_MAX, FLT_MAX, FLT_MAX),
368 bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX),
374 Vec3d bbMinimum( FLT_MAX, FLT_MAX, FLT_MAX);
375 Vec3d bbMaximum(-FLT_MAX, -FLT_MAX, -FLT_MAX);
378 if ((bbMinimum[0] > bbMaximum[0]) ||
379 (bbMinimum[1] > bbMaximum[1]) ||
380 (bbMinimum[2] > bbMaximum[2]))
407 Vec3d bbMin_, bbMax_;
431 statusPasses_(BaseNode::ALLPASSES),
432 nodePasses_(BaseNode::ALLPASSES)
441 if ( statusPass != BaseNode::ALLPASSES) {
448 statusPass = statusPass >> 1;
450 while( statusPass != 0u ) {
451 statusPass = statusPass >> 1;
454 statusPasses_ = c > statusPasses_ ? c : statusPasses_;
462 if ( nodePass != BaseNode::ALLPASSES) {
469 nodePass = nodePass >> 1;
471 while(nodePass != 0u) {
472 nodePass = nodePass >> 1;
475 nodePasses_ = c > nodePasses_ ? c : nodePasses_;
486 unsigned int maxpasses = std::max(statusPasses_,nodePasses_);
489 return maxpasses == 0 ? 1 : maxpasses;
502 unsigned int getNodePasses() {
return nodePasses_ == 0 ? 1 : nodePasses_; };
506 unsigned int statusPasses_;
507 unsigned int nodePasses_;
529 node_id_(_node_id), node_ptr_(0) {}
533 if (_node->
id() == node_id_)
546 unsigned int node_id_;
656 }
else if ( availableModes & newModes_ ) {
658 _node->
drawMode( availableModes & newModes_ );
669 DrawModes::DrawMode newModes_;
694 drawMode_(_drawMode),
695 blending_(_blending) {}
704 _node->
draw(state_, drawMode_);
714 _node->
enter(state_, drawMode_);
722 _node->
leave(state_, drawMode_);
730 DrawModes::DrawMode drawMode_;
753 pickTarget_(_target),
754 drawmode_(_drawmode) {}
768 _node->
enterPick(state_, pickTarget_, drawmode_);
776 _node->
leavePick(state_, pickTarget_, drawmode_);
785 DrawModes::DrawMode drawmode_;
843 bool isDirty()
const {
return dirty_; };
const GLMatrixd & modelview() const
get modelview matrix
unsigned int max_render_passes() const
get maximum number of render passes
bool blending()
get whether transparenet or solid objects should be drawn
void reset_render_pass()
reset render pass counter
void next_render_pass()
increment render pass counter
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
ChildIter childrenBegin()
Returns: begin-iterator of children.
bool isDirty() const
Check if node should be redrawn.
ChildIter childrenEnd()
Returns: end-iterator of children.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
unsigned int traverseMode() const
Return how the node should be traversed.
bool multipassStatusActive(const unsigned int _i) const
Get multipass status to traverse in a specific pass.
@ HideNode
Hide this node, but draw children.
@ HideChildren
Draw this node, but hide children.
@ HideSubtree
Hide this node and its children.
@ ChildrenFirst
Execute action the children first and then on this node.
@ NodeFirst
Execute action on node first and then on its children.
@ SecondPass
Draw node in second pass.
unsigned int MultipassBitMask
Multipass pass bit mask type.
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
virtual void enterPick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
virtual void boundingBox(Vec3d &, Vec3d &)
void setDirty(bool _dirty=true)
mark node for redrawn
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
StatusMode status() const
Get node's status.
virtual void leave(GLState &, const DrawModes::DrawMode &)
virtual DrawModes::DrawMode availableDrawModes() const
virtual void leavePick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
virtual void enter(GLState &, const DrawModes::DrawMode &)
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
DrawAction(const DrawModes::DrawMode &_drawMode, GLState &_state, bool _blending)
Constructor: draws the scenegraph using _drawMode.
FindNodeAction(unsigned int _node_id)
constructor: _node_id is the node to be searched for
BaseNode * node_ptr()
Get the pointer of the node (is 0 if node was not found)
unsigned int getNodePasses()
Get the number of required node traversals from Scenegraph.
unsigned int getMaxPasses() const
Get the number of required traverse passes from Scenegraph.
unsigned int getStatusPasses()
Get the number of required status traversals from Scenegraph.
PickAction(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawmode)
constructor: what picking target to use
SetDrawModesAction(const DrawModes::DrawMode &_mode, bool _force=false)
Set draw modes for all nodes traversed with this action.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
DrawMode NONE
not a valid draw mode
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
void traverse_all(BaseNode *_node, Action &_action)
BaseNode * find_hidden_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
void traverse(BaseNode *_node, Action &_action)
PickTarget
What target to use for picking.
Namespace providing different geometric functions concerning angles.
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.