57 #ifndef ACG_SCENEGRAPH_HH 58 #define ACG_SCENEGRAPH_HH 63 #include "BaseNode.hh" 64 #include "DrawModes.hh" 65 #include "../Math/VectorT.hh" 68 #include <QMouseEvent> 81 template<
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; \ 101 template<
typename Action>
103 if_has_enter(Action &_action,
BaseNode *_node) {
104 _action.enter (_node);
108 template<
typename Action>
110 if_has_enter(Action &,
BaseNode *) {
116 template<
typename Action>
118 if_has_leave(Action &_action,
BaseNode *_node) {
119 _action.leave (_node);
123 template<
typename Action>
125 if_has_leave(Action &,
BaseNode *) {
135 template <
class Action>
154 if_has_enter (_action, _node);
158 process_children &= _action(_node);
161 if (process_children)
187 if_has_leave (_action, _node);
200 template <
class Action>
206 bool process_children(
true);
209 if_has_enter(_action, _node);
213 process_children &= _action(_node);
235 if_has_leave (_action, _node);
252 template <
class Action>
269 if_has_enter(_action, _node);
276 process_children &= _action(_node);
278 if (process_children) {
303 if_has_leave(_action, _node);
327 template <
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 bbMin( FLT_MAX, FLT_MAX, FLT_MAX);
375 Vec3d bbMax(-FLT_MAX, -FLT_MAX, -FLT_MAX);
378 if ((bbMin[0] > bbMax[0]) ||
379 (bbMin[1] > bbMax[1]) ||
380 (bbMin[2] > bbMax[2]))
383 bbMin_.minimize(state_.modelview().transform_point (bbMin));
384 bbMin_.minimize(state_.modelview().transform_point (bbMax));
385 bbMax_.maximize(state_.modelview().transform_point (bbMin));
386 bbMax_.maximize(state_.modelview().transform_point (bbMax));
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_ );
694 drawMode_(_drawMode),
695 blending_(_blending) {}
700 if(state_.blending() == blending_)
704 _node->
draw(state_, drawMode_);
714 _node->
enter(state_, drawMode_);
722 _node->
leave(state_, drawMode_);
753 pickTarget_(_target),
754 drawmode_(_drawmode) {}
768 _node->
enterPick(state_, pickTarget_, drawmode_);
776 _node->
leavePick(state_, pickTarget_, drawmode_);
843 bool isDirty()
const {
return dirty_; };
855 #endif // ACG_SCENEGRAPH_HH defined Draw this node, but hide children.
PickAction(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawmode)
constructor: what picking target to use
Namespace providing different geometric functions concerning angles.
Execute action on node first and then on its children.
virtual void enterPick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
unsigned int MultipassBitMask
Multipass pass bit mask type.
Draw node in second pass.
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
ChildIter childrenEnd()
Returns: end-iterator of children.
SetDrawModesAction(const DrawModes::DrawMode &_mode, bool _force=false)
Set draw modes for all nodes traversed with this action.
virtual void leave(GLState &, const DrawModes::DrawMode &)
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
ChildIter childrenBegin()
Returns: begin-iterator of children.
Hide this node, but draw children.
Hide this node and its children.
void reset_render_pass()
reset render pass counter
bool multipassStatusActive(const unsigned int _i) const
Get multipass status to traverse in a specific pass.
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
FindNodeAction(unsigned int _node_id)
constructor: _node_id is the node to be searched for
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
virtual void boundingBox(Vec3d &, Vec3d &)
unsigned int traverseMode() const
Return how the node should be traversed.
void setDirty(bool _dirty=true)
mark node for redrawn
unsigned int getNodePasses()
Get the number of required node traversals from Scenegraph.
virtual void enter(GLState &, const DrawModes::DrawMode &)
void traverse_all(BaseNode *_node, Action &_action)
unsigned int getStatusPasses()
Get the number of required status traversals from Scenegraph.
DrawMode NONE
not a valid draw mode
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Execute action the children first and then on this node.
BaseNode * node_ptr()
Get the pointer of the node (is 0 if node was not found)
virtual DrawModes::DrawMode availableDrawModes() const
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
PickTarget
What target to use for picking.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
void traverse(BaseNode *_node, Action &_action)
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
virtual void leavePick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
unsigned int max_render_passes() const
get maximum number of render passes
BaseNode * find_hidden_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
void next_render_pass()
increment render pass counter
DrawAction(const DrawModes::DrawMode &_drawMode, GLState &_state, bool _blending)
Constructor: draws the scenegraph using _drawMode.
bool isDirty() const
Check if node should be redrawn.
StatusMode status() const
Get node's status.
unsigned int getMaxPasses() const
Get the number of required traverse passes from Scenegraph.