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 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]))
383 bbMin_.minimize(state_.modelview().transform_point (bbMinimum));
384 bbMin_.minimize(state_.modelview().transform_point (bbMaximum));
385 bbMax_.maximize(state_.modelview().transform_point (bbMinimum));
386 bbMax_.maximize(state_.modelview().transform_point (bbMaximum));
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 DrawModes::DrawMode drawModes() const
Get the collected draw modes.
unsigned int MultipassBitMask
Multipass pass bit mask type.
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
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)
virtual void leavePick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Namespace providing different geometric functions concerning angles.
void setDirty(bool _dirty=true)
mark node for redrawn
virtual void leave(GLState &, const DrawModes::DrawMode &)
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
Draw node in second pass.
Hide this node and its children.
bool isDirty() const
Check if node should be redrawn.
bool multipassNodeActive(const unsigned int _i) const
Get Node status to traverse in a specific pass.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
StatusMode status() const
Get node's status.
virtual void enter(GLState &, const DrawModes::DrawMode &)
unsigned int getNodePasses()
Get the number of required node traversals from Scenegraph.
PickTarget
What target to use for picking.
void traverse_all(BaseNode *_node, Action &_action)
BaseNode * node_ptr()
Get the pointer of the node (is 0 if node was not found)
ChildIter childrenBegin()
Returns: begin-iterator of children.
unsigned int traverseMode() const
Return how the node should be traversed.
void reset_render_pass()
reset render pass counter
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
PickAction(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawmode)
constructor: what picking target to use
virtual void enterPick(GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
DrawAction(const DrawModes::DrawMode &_drawMode, GLState &_state, bool _blending)
Constructor: draws the scenegraph using _drawMode.
unsigned int getStatusPasses()
Get the number of required status traversals from Scenegraph.
void next_render_pass()
increment render pass counter
DrawMode NONE
not a valid draw mode
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
virtual DrawModes::DrawMode availableDrawModes() const
unsigned int getMaxPasses() const
Get the number of required traverse passes from Scenegraph.
BaseNode * find_hidden_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
Execute action on node first and then on its children.
ChildIter childrenEnd()
Returns: end-iterator of children.
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Draw this node, but hide children.
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
virtual void boundingBox(Vec3d &, Vec3d &)
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.
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
Hide this node, but draw children.
SetDrawModesAction(const DrawModes::DrawMode &_mode, bool _force=false)
Set draw modes for all nodes traversed with this action.
unsigned int max_render_passes() const
get maximum number of render passes
void traverse(BaseNode *_node, Action &_action)