Developer Documentation
BaseNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS BaseNode
55 //
56 //=============================================================================
57 
58 
59 #ifndef ACG_BASE_NODE_HH
60 #define ACG_BASE_NODE_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 // ACG
66 #include "../Math/VectorT.hh"
67 #include "../GL/GLState.hh"
68 #include "../Config/ACGDefines.hh"
69 
70 // Qt
71 //#include <qgl.h>
72 #include <QMouseEvent>
73 
74 // stdc++
75 #include <vector>
76 #include <string>
77 #include <algorithm>
78 #include <iostream>
79 #include <ACG/Scenegraph/DrawModes.hh>
80 #include <ACG/GL/RenderObject.hh>
81 
82 //== NAMESPACES ===============================================================
83 
84 
85 namespace ACG {
86 
87 class IRenderer;
88 
89 namespace SceneGraph {
90 
91 // prototype declaration to avoid include-loop
92 class Material;
93 
94 
95 //== CLASS DEFINITION =========================================================
96 
97 
100 {
111 
116 
119 };
120 
121 
123 #define ACG_CLASSNAME(_className) \
124  virtual const std::string& className() const { \
125  static std::string cname( #_className ); return cname; \
126 }
127 
128 
135 class ACGDLLEXPORT BaseNode
136 {
137 public:
138 
139 
141  BaseNode(BaseNode* _parent=0, std::string _name="<unknown>");
142 
144  BaseNode(BaseNode* _parent, BaseNode* _child, std::string _name="<unknown>");
145 
147  virtual ~BaseNode();
148 
157  void delete_subtree();
158 
159 
160  // --- basic interface ---
161 
163  virtual const std::string& className() const = 0;
164 
168 
174  virtual void boundingBox(Vec3d& /* _bbMin */, Vec3d& /*_bbMax*/ ) {}
175 
191  virtual void enter(GLState& /*_state */, const DrawModes::DrawMode& /*_drawMode*/ ) {}
192 
209  virtual void enter(IRenderer* /*_renderer*/, GLState& _state, const DrawModes::DrawMode& _drawMode) {
210  enter(_state, _drawMode);
211  }
212 
223  virtual void draw(GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
224 
241  virtual void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat) {}
242 
254  virtual void leave(GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
255 
270  virtual void leave(IRenderer* /*_renderer*/, GLState& _state, const DrawModes::DrawMode& _drawMode) {
271  leave(_state, _drawMode);
272  }
273 
279  virtual void enterPick(GLState& _state , PickTarget _target, const DrawModes::DrawMode& _drawMode );
280 
285  virtual void pick(GLState& /* _state */, PickTarget /* _target */ ) {}
286 
291  virtual void leavePick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode );
292 
296  void enablePicking(bool _enable) { pickingEnabled_ = _enable; };
297 
300  bool pickingEnabled() { return pickingEnabled_; };
301 
303  virtual void mouseEvent(GLState& /* _state */, QMouseEvent* /* _event */ ) {}
304 
306  void setDirty (bool _dirty = true) { dirty_ = _dirty; }
307 
309  bool isDirty () const { return dirty_; }
310 
311 
312  // --- iterators ---
313 
315  typedef std::vector<BaseNode*>::const_iterator ConstChildIter;
317  typedef std::vector<BaseNode*>::iterator ChildIter;
318 
320  typedef std::vector<BaseNode*>::const_reverse_iterator ConstChildRIter;
322  typedef std::vector<BaseNode*>::reverse_iterator ChildRIter;
323 
325  ChildIter childrenBegin() { return children_.begin(); }
327  ConstChildIter childrenBegin() const { return children_.begin(); }
329  ChildIter childrenEnd() { return children_.end(); }
331  ConstChildIter childrenEnd() const { return children_.end(); }
332 
334  ChildRIter childrenRBegin() { return children_.rbegin(); }
336  ConstChildRIter childrenRBegin() const { return children_.rbegin(); }
338  ChildRIter childrenREnd() { return children_.rend(); }
340  ConstChildRIter childrenREnd() const { return children_.rend(); }
341 
342 
343 
344 
345 
346  // --- insert / remove ---
347 
349  void push_back(BaseNode* _node)
350  {
351  if (_node)
352  {
353  children_.push_back(_node);
354  _node->parent_=this;
355  }
356  }
357 
361  void remove(ChildIter _pos)
362  {
363  if (_pos == childrenEnd()) return;
364  //(*_pos)->parent_=0;
365  children_.erase(_pos);
366  }
367 
369  size_t nChildren() const { return children_.size(); }
370 
377  ChildIter find(BaseNode* _node)
378  {
379  ChildIter i=std::find(children_.begin(),children_.end(),_node);
380  return i;
381  }
382 
383 
386  BaseNode * find( const std::string & _name )
387  {
388  if ( name() == _name )
389  return this;
390 
391  for ( BaseNode::ChildIter cIt = childrenBegin();
392  cIt != childrenEnd(); ++cIt )
393  {
394  BaseNode * n = (*cIt)->find( _name );
395  if ( n ) return n;
396  }
397 
398  return 0;
399  }
400 
401 
403  BaseNode* parent() { return parent_; }
404 
406  const BaseNode* parent() const { return parent_; }
407 
413  void set_parent(BaseNode* _parent);
414 
415 
416  // --- status info ---
417 
418 
421  {
423  Active = 0x1,
425  HideNode = 0x2,
427  HideChildren = 0x4,
429  HideSubtree = 0x8
430  };
432  StatusMode status() const { return status_; }
434  void set_status(StatusMode _s) { status_ = _s; }
436  void hide() { set_status(HideNode); }
438  void show() { set_status(Active); }
440  bool visible() { return status_ == Active; }
442  bool hidden() { return status_ != Active; }
443 
444 
446  std::string name() const { return name_; }
448  void name(const std::string& _name) { name_ = _name; }
449 
450 
454  unsigned int id() const { return id_; }
455 
456 
457 
458  //--- draw mode ---
459 
461  DrawModes::DrawMode drawMode() const { return drawMode_; }
464  void drawMode(DrawModes::DrawMode _drawMode) { drawMode_ = _drawMode; }
465 
466  //--- traverse type ---
467 
470  {
472  NodeFirst = 0x1,
474  ChildrenFirst = 0x2,
476  SecondPass = 0x4
477  };
478 
480  unsigned int traverseMode () const { return traverseMode_; }
481 
483  void setTraverseMode(unsigned int _mode) { traverseMode_ = _mode; }
484 
485  //===========================================================================
495  //===========================================================================
496 
497 public:
498 
500  typedef unsigned int MultipassBitMask;
501 
502 
504  enum PASSES {
505  NOPASS = 0,
506  ALLPASSES = 1 << 0,
507  PASS_1 = 1 << 1,
508  PASS_2 = 1 << 2,
509  PASS_3 = 1 << 3,
510  PASS_4 = 1 << 4,
511  PASS_5 = 1 << 5,
512  PASS_6 = 1 << 6,
513  PASS_7 = 1 << 7,
514  PASS_8 = 1 << 8
515  };
516 
524  MultipassBitMask multipassStatus() const {return multipassStatus_;};
525 
526 
536  void setMultipassStatus(const MultipassBitMask _passStatus) { multipassStatus_ = _passStatus; };
537 
547  void multipassStatusSetActive(const unsigned int _i, bool _active);
548 
557  bool multipassStatusActive(const unsigned int _i) const;
558 
559 
560 
568  MultipassBitMask multipassNode() const {return multipassNode_;};
569 
570 
571 
580  void setMultipassNode(const MultipassBitMask _passNode) { multipassNode_ = _passNode; };
581 
591  void multipassNodeSetActive(const unsigned int _i , bool _active);
592 
601  bool multipassNodeActive(const unsigned int _i) const;
602 
603 
604  //===========================================================================
611  //===========================================================================
612 
613 public:
614 
633  void setRenderObjectShaders(const std::string& _vertexShaderFile, const std::string& _geometryShaderFile, const std::string& _fragmentShaderFile, bool _relativePaths = true, DrawModes::DrawModePrimitive _primitiveType = DrawModes::PRIMITIVE_POLYGON);
634 
655  void setRenderObjectShaders(const std::string& _vertexShaderFile, const std::string& _tessControlShaderFile, const std::string& _tessEvalShaderFile, const std::string& _geometryShaderFile, const std::string& _fragmentShaderFile, bool _relativePaths = true, DrawModes::DrawModePrimitive _primitiveType = DrawModes::PRIMITIVE_POLYGON);
656 
657 
667  void setRenderObjectUniformPool(const GLSL::UniformPool* _pool) {uniformPool_ = _pool;}
668 
672  const GLSL::UniformPool* getRenderObjectUniformPool() {return uniformPool_;}
673 
685  void setRenderObjectTexture(int _samplerSlot, GLuint _texId, GLenum _texType = GL_TEXTURE_2D);
686 
687 
696  void setRenderObjectModifier(RenderObjectModifier* _modifier) {renderModifier_ = _modifier;}
697 
701  RenderObjectModifier* getRenderObjectModifier() {return renderModifier_;}
702 
703 
704 
713  void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject* _obj) const;
714 
715 private:
716 
721  MultipassBitMask multipassStatus_;
722 
727  MultipassBitMask multipassNode_;
728 
731 private:
732 
734  BaseNode(const BaseNode&);
735 
737  void operator=(const BaseNode&);
738 
739 
742 
744  std::string name_;
745 
748 
750  std::vector<BaseNode*> children_;
751 
753  static unsigned int last_id_used__;
754 
756  unsigned int id_;
757 
760 
765 
767  bool dirty_;
768 
770  unsigned int traverseMode_;
771 
772 
773  // settings for shader-based rendering with render-objects
774 private:
775 
776  struct ShaderSet
777  {
778  // shader filenames
779 
781  std::string vs_;
782 
784  std::string tcs_;
785 
787  std::string tes_;
788 
790  std::string gs_;
791 
793  std::string fs_;
794 
797  };
798 
800  std::map<DrawModes::DrawModePrimitive, ShaderSet> shaderSettings_;
801 
803  std::map<int, RenderObject::Texture> textureSettings_;
804 
807 
810 };
811 
812 
813 //=============================================================================
814 } // namespace SceneGraph
815 } // namespace ACG
816 //=============================================================================
817 #endif // ACG_BASE_NODE_HH defined
818 //=============================================================================
StatusMode status() const
Get node&#39;s status.
Definition: BaseNode.hh:432
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:329
virtual void enter(GLState &, const DrawModes::DrawMode &)
Definition: BaseNode.hh:191
unsigned int MultipassBitMask
Multipass pass bit mask type.
Definition: BaseNode.hh:500
void enablePicking(bool _enable)
Definition: BaseNode.hh:296
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
Definition: BaseNode.hh:524
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:317
virtual DrawModes::DrawMode availableDrawModes() const
Definition: BaseNode.hh:167
ConstChildRIter childrenRBegin() const
Same but const.
Definition: BaseNode.hh:336
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
Definition: BaseNode.hh:223
picks only visible front edges (may not be implemented for all nodes)
Definition: BaseNode.hh:113
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition: BaseNode.hh:461
BaseNode * parent()
Get the nodes parent node.
Definition: BaseNode.hh:403
MultipassBitMask multipassStatus_
Definition: BaseNode.hh:721
StatusMode status_
node status()
Definition: BaseNode.hh:747
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
Definition: BaseNode.hh:568
virtual void pick(GLState &, PickTarget)
Definition: BaseNode.hh:285
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:446
RenderObjectModifier * renderModifier_
render-object modifier
Definition: BaseNode.hh:809
Interface for modifying render objects.
void setRenderObjectUniformPool(const GLSL::UniformPool *_pool)
Set uniforms for shader based rendering.
Definition: BaseNode.hh:667
void setRenderObjectModifier(RenderObjectModifier *_modifier)
Set modifier for render objects.
Definition: BaseNode.hh:696
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:377
virtual void enter(IRenderer *, GLState &_state, const DrawModes::DrawMode &_drawMode)
Definition: BaseNode.hh:209
PASSES
This enum should be used to enable rendering of a node in different.
Definition: BaseNode.hh:504
BaseNode * parent_
pointer to parent node
Definition: BaseNode.hh:741
void set_status(StatusMode _s)
Set the status of this node.
Definition: BaseNode.hh:434
unsigned int id() const
Definition: BaseNode.hh:454
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
std::string name_
name of node
Definition: BaseNode.hh:744
const GLSL::UniformPool * uniformPool_
user provided uniform pool for shader constants
Definition: BaseNode.hh:806
size_t nChildren() const
number of children
Definition: BaseNode.hh:369
bool hidden()
Is node not visible (status != Active)?
Definition: BaseNode.hh:442
bool relativePaths_
rel or abs path
Definition: BaseNode.hh:796
virtual void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Deferred draw call with shader based renderer.
Definition: BaseNode.hh:241
ConstChildIter childrenBegin() const
Same but cont.
Definition: BaseNode.hh:327
ConstChildRIter childrenREnd() const
Same but const.
Definition: BaseNode.hh:340
std::vector< BaseNode * >::const_iterator ConstChildIter
allows to iterate over children
Definition: BaseNode.hh:315
void name(const std::string &_name)
rename a node
Definition: BaseNode.hh:448
std::vector< BaseNode * > children_
list of children
Definition: BaseNode.hh:750
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
Definition: BaseNode.hh:303
void hide()
Hide Node: set status to HideNode.
Definition: BaseNode.hh:436
std::string tes_
tess-eval
Definition: BaseNode.hh:787
void setMultipassStatus(const MultipassBitMask _passStatus)
Set multipass settings for the nodes status functions.
Definition: BaseNode.hh:536
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:325
unsigned int id_
ID of node.
Definition: BaseNode.hh:756
StatusMode
Status modi.
Definition: BaseNode.hh:420
unsigned int traverseMode_
traverse mode
Definition: BaseNode.hh:770
ChildRIter childrenRBegin()
Returns: reverse begin-iterator of children.
Definition: BaseNode.hh:334
bool dirty_
Flag indicating that the node has to be redrawn.
Definition: BaseNode.hh:767
virtual void leave(GLState &, const DrawModes::DrawMode &)
Definition: BaseNode.hh:254
TraverseMode
Node traverse types.
Definition: BaseNode.hh:469
DrawModePrimitive
Primitive mode of a mesh.
Definition: DrawModes.hh:124
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
RenderObjectModifier * getRenderObjectModifier()
Get render-object modifier.
Definition: BaseNode.hh:701
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
Pick spline curve or surface (picks u or u,v coords respectively)
Definition: BaseNode.hh:118
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:77
picks only visible front verices (may not be implemented for all nodes)
Definition: BaseNode.hh:115
void show()
Show node: set status to Active.
Definition: BaseNode.hh:438
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: BaseNode.hh:349
const BaseNode * parent() const
Get the nodes parent node.
Definition: BaseNode.hh:406
picks edges (may not be implemented for all nodes)
Definition: BaseNode.hh:106
const GLSL::UniformPool * getRenderObjectUniformPool()
Get uniforms for shader based rendering.
Definition: BaseNode.hh:672
bool isDirty() const
Check if node should be redrawn.
Definition: BaseNode.hh:309
virtual void leave(IRenderer *, GLState &_state, const DrawModes::DrawMode &_drawMode)
Definition: BaseNode.hh:270
std::vector< BaseNode * >::reverse_iterator ChildRIter
allows to reverse iterate over children
Definition: BaseNode.hh:322
void setDirty(bool _dirty=true)
mark node for redrawn
Definition: BaseNode.hh:306
MultipassBitMask multipassNode_
Definition: BaseNode.hh:727
std::vector< BaseNode * >::const_reverse_iterator ConstChildRIter
allows to reverse iterate over children
Definition: BaseNode.hh:320
void setTraverseMode(unsigned int _mode)
Set traverse mode for node.
Definition: BaseNode.hh:483
void setMultipassNode(const MultipassBitMask _passNode)
Set multipass settings for the node.
Definition: BaseNode.hh:580
BaseNode * find(const std::string &_name)
Definition: BaseNode.hh:386
picks faces (may not be implemented for all nodes)
Definition: BaseNode.hh:102
static unsigned int last_id_used__
used to provide unique IDs to nodes
Definition: BaseNode.hh:753
bool visible()
Is node visible (status == Active)?
Definition: BaseNode.hh:440
void drawMode(DrawModes::DrawMode _drawMode)
Definition: BaseNode.hh:464
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
std::map< DrawModes::DrawModePrimitive, ShaderSet > shaderSettings_
shader settings for primitive modes
Definition: BaseNode.hh:800
DrawModes::DrawMode drawMode_
private draw mode
Definition: BaseNode.hh:759
Interface class between scenegraph and renderer.
unsigned int traverseMode() const
Return how the node should be traversed.
Definition: BaseNode.hh:480
virtual void boundingBox(Vec3d &, Vec3d &)
Definition: BaseNode.hh:174
ChildRIter childrenREnd()
Returns: reverse end-iterator of children.
Definition: BaseNode.hh:338
ConstChildIter childrenEnd() const
Same but const.
Definition: BaseNode.hh:331
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
std::string vs_
vertex shader
Definition: BaseNode.hh:781
std::map< int, RenderObject::Texture > textureSettings_
texture settings for shader based rendering
Definition: BaseNode.hh:803
ACG::SceneGraph::BaseNode BaseNode
Base Node.
std::string tcs_
tess-control
Definition: BaseNode.hh:784