Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <list>
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 
182  virtual void enter(GLState& /*_state */, const DrawModes::DrawMode& /*_drawMode*/ ) {}
183 
194  virtual void draw(GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
195 
212  virtual void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat) {}
213 
217  virtual void leave(GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
218 
224  virtual void enterPick(GLState& _state , PickTarget _target, const DrawModes::DrawMode& _drawMode );
225 
230  virtual void pick(GLState& /* _state */, PickTarget /* _target */ ) {}
231 
236  virtual void leavePick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode );
237 
241  void enablePicking(bool _enable) { pickingEnabled_ = _enable; };
242 
245  bool pickingEnabled() { return pickingEnabled_; };
246 
248  virtual void mouseEvent(GLState& /* _state */, QMouseEvent* /* _event */ ) {}
249 
251  void setDirty (bool _dirty = true) { dirty_ = _dirty; }
252 
254  bool isDirty () const { return dirty_; }
255 
256 
257  // --- iterators ---
258 
260  typedef std::list<BaseNode*>::const_iterator ConstChildIter;
262  typedef std::list<BaseNode*>::iterator ChildIter;
263 
265  typedef std::list<BaseNode*>::const_reverse_iterator ConstChildRIter;
267  typedef std::list<BaseNode*>::reverse_iterator ChildRIter;
268 
270  ChildIter childrenBegin() { return children_.begin(); }
272  ConstChildIter childrenBegin() const { return children_.begin(); }
274  ChildIter childrenEnd() { return children_.end(); }
276  ConstChildIter childrenEnd() const { return children_.end(); }
277 
279  ChildRIter childrenRBegin() { return children_.rbegin(); }
281  ConstChildRIter childrenRBegin() const { return children_.rbegin(); }
283  ChildRIter childrenREnd() { return children_.rend(); }
285  ConstChildRIter childrenREnd() const { return children_.rend(); }
286 
287 
288 
289 
290 
291  // --- insert / remove ---
292 
294  void push_back(BaseNode* _node)
295  {
296  if (_node)
297  {
298  children_.push_back(_node);
299  _node->parent_=this;
300  }
301  }
302 
306  void remove(ChildIter _pos)
307  {
308  if (_pos == childrenEnd()) return;
309  //(*_pos)->parent_=0;
310  children_.erase(_pos);
311  }
312 
314  size_t nChildren() const { return children_.size(); }
315 
322  ChildIter find(BaseNode* _node)
323  {
324  ChildIter i=std::find(children_.begin(),children_.end(),_node);
325  return i;
326  }
327 
328 
331  BaseNode * find( const std::string & _name )
332  {
333  if ( name() == _name )
334  return this;
335 
336  for ( BaseNode::ChildIter cIt = childrenBegin();
337  cIt != childrenEnd(); ++cIt )
338  {
339  BaseNode * n = (*cIt)->find( _name );
340  if ( n ) return n;
341  }
342 
343  return 0;
344  }
345 
346 
348  BaseNode* parent() { return parent_; }
349 
351  const BaseNode* parent() const { return parent_; }
352 
358  void set_parent(BaseNode* _parent);
359 
360 
361  // --- status info ---
362 
363 
366  {
368  Active = 0x1,
370  HideNode = 0x2,
372  HideChildren = 0x4,
374  HideSubtree = 0x8
375  };
377  StatusMode status() const { return status_; }
379  void set_status(StatusMode _s) { status_ = _s; }
381  void hide() { set_status(HideNode); }
383  void show() { set_status(Active); }
385  bool visible() { return status_ == Active; }
387  bool hidden() { return status_ != Active; }
388 
389 
391  std::string name() const { return name_; }
393  void name(const std::string& _name) { name_ = _name; }
394 
395 
399  unsigned int id() const { return id_; }
400 
401 
402 
403  //--- draw mode ---
404 
406  DrawModes::DrawMode drawMode() const { return drawMode_; }
409  void drawMode(DrawModes::DrawMode _drawMode) { drawMode_ = _drawMode; }
410 
411  //--- traverse type ---
412 
415  {
417  NodeFirst = 0x1,
419  ChildrenFirst = 0x2,
421  SecondPass = 0x4
422  };
423 
425  unsigned int traverseMode () const { return traverseMode_; }
426 
428  void setTraverseMode(unsigned int _mode) { traverseMode_ = _mode; }
429 
430  //===========================================================================
440  //===========================================================================
441 
442 public:
443 
445  typedef unsigned int MultipassBitMask;
446 
447 
449  enum PASSES {
450  NOPASS = 0,
451  ALLPASSES = 1 << 0,
452  PASS_1 = 1 << 1,
453  PASS_2 = 1 << 2,
454  PASS_3 = 1 << 3,
455  PASS_4 = 1 << 4,
456  PASS_5 = 1 << 5,
457  PASS_6 = 1 << 6,
458  PASS_7 = 1 << 7,
459  PASS_8 = 1 << 8
460  };
461 
469  MultipassBitMask multipassStatus() const {return multipassStatus_;};
470 
471 
481  void setMultipassStatus(const MultipassBitMask _passStatus) { multipassStatus_ = _passStatus; };
482 
492  void multipassStatusSetActive(const unsigned int _i, bool _active);
493 
502  bool multipassStatusActive(const unsigned int _i) const;
503 
504 
505 
513  MultipassBitMask multipassNode() const {return multipassNode_;};
514 
515 
516 
525  void setMultipassNode(const MultipassBitMask _passNode) { multipassNode_ = _passNode; };
526 
536  void multipassNodeSetActive(const unsigned int _i , bool _active);
537 
546  bool multipassNodeActive(const unsigned int _i) const;
547 
548 
549  //===========================================================================
556  //===========================================================================
557 
558 public:
559 
578  void setRenderObjectShaders(const std::string& _vertexShaderFile, const std::string& _geometryShaderFile, const std::string& _fragmentShaderFile, bool _relativePaths = true, DrawModes::DrawModePrimitive _primitiveType = DrawModes::PRIMITIVE_POLYGON);
579 
600  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);
601 
602 
612  void setRenderObjectUniformPool(const GLSL::UniformPool* _pool) {uniformPool_ = _pool;}
613 
617  const GLSL::UniformPool* getRenderObjectUniformPool() {return uniformPool_;}
618 
630  void setRenderObjectTexture(int _samplerSlot, GLuint _texId, GLenum _texType = GL_TEXTURE_2D);
631 
632 
641  void setRenderObjectModifier(RenderObjectModifier* _modifier) {renderModifier_ = _modifier;}
642 
646  RenderObjectModifier* getRenderObjectModifier() {return renderModifier_;}
647 
648 
649 
658  void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject* _obj) const;
659 
660 private:
661 
666  MultipassBitMask multipassStatus_;
667 
672  MultipassBitMask multipassNode_;
673 
676 private:
677 
679  BaseNode(const BaseNode&);
680 
682  void operator=(const BaseNode&);
683 
684 
687 
689  std::string name_;
690 
693 
695  std::list<BaseNode*> children_;
696 
698  static unsigned int last_id_used__;
699 
701  unsigned int id_;
702 
705 
710 
712  bool dirty_;
713 
715  unsigned int traverseMode_;
716 
717 
718  // settings for shader-based rendering with render-objects
719 private:
720 
721  struct ShaderSet
722  {
723  // shader filenames
724 
726  std::string vs_;
727 
729  std::string tcs_;
730 
732  std::string tes_;
733 
735  std::string gs_;
736 
738  std::string fs_;
739 
742  };
743 
745  std::map<DrawModes::DrawModePrimitive, ShaderSet> shaderSettings_;
746 
748  std::map<int, RenderObject::Texture> textureSettings_;
749 
752 
755 };
756 
757 
758 //=============================================================================
759 } // namespace SceneGraph
760 } // namespace ACG
761 //=============================================================================
762 #endif // ACG_BASE_NODE_HH defined
763 //=============================================================================
Pick spline curve or surface (picks u or u,v coords respectively)
Definition: BaseNode.hh:118
ConstChildIter childrenEnd() const
Same but const.
Definition: BaseNode.hh:276
std::map< int, RenderObject::Texture > textureSettings_
texture settings for shader based rendering
Definition: BaseNode.hh:748
BaseNode * parent_
pointer to parent node
Definition: BaseNode.hh:686
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
unsigned int id() const
Definition: BaseNode.hh:399
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: BaseNode.hh:294
bool visible()
Is node visible (status == Active)?
Definition: BaseNode.hh:385
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
const GLSL::UniformPool * getRenderObjectUniformPool()
Get uniforms for shader based rendering.
Definition: BaseNode.hh:617
void drawMode(DrawModes::DrawMode _drawMode)
Definition: BaseNode.hh:409
std::map< DrawModes::DrawModePrimitive, ShaderSet > shaderSettings_
shader settings for primitive modes
Definition: BaseNode.hh:745
BaseNode * find(const std::string &_name)
Definition: BaseNode.hh:331
size_t nChildren() const
number of children
Definition: BaseNode.hh:314
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
Definition: BaseNode.hh:194
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
virtual void pick(GLState &, PickTarget)
Definition: BaseNode.hh:230
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
bool relativePaths_
rel or abs path
Definition: BaseNode.hh:741
bool isDirty() const
Check if node should be redrawn.
Definition: BaseNode.hh:254
Interface class between scenegraph and renderer.
unsigned int MultipassBitMask
Multipass pass bit mask type.
Definition: BaseNode.hh:445
void name(const std::string &_name)
rename a node
Definition: BaseNode.hh:393
void setTraverseMode(unsigned int _mode)
Set traverse mode for node.
Definition: BaseNode.hh:428
ChildRIter childrenRBegin()
Returns: reverse begin-iterator of children.
Definition: BaseNode.hh:279
TraverseMode
Node traverse types.
Definition: BaseNode.hh:414
StatusMode status_
node status()
Definition: BaseNode.hh:692
PASSES
This enum should be used to enable rendering of a node in different.
Definition: BaseNode.hh:449
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:270
void setMultipassStatus(const MultipassBitMask _passStatus)
Set multipass settings for the nodes status functions.
Definition: BaseNode.hh:481
virtual void enter(GLState &, const DrawModes::DrawMode &)
Definition: BaseNode.hh:182
RenderObjectModifier * renderModifier_
render-object modifier
Definition: BaseNode.hh:754
ConstChildIter childrenBegin() const
Same but cont.
Definition: BaseNode.hh:272
std::string vs_
vertex shader
Definition: BaseNode.hh:726
virtual void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Deferred draw call with shader based renderer.
Definition: BaseNode.hh:212
bool dirty_
Flag indicating that the node has to be redrawn.
Definition: BaseNode.hh:712
void show()
Show node: set status to Active.
Definition: BaseNode.hh:383
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
DrawModePrimitive
Primitive mode of a mesh.
Definition: DrawModes.hh:124
unsigned int traverseMode_
traverse mode
Definition: BaseNode.hh:715
ConstChildRIter childrenREnd() const
Same but const.
Definition: BaseNode.hh:285
picks edges (may not be implemented for all nodes)
Definition: BaseNode.hh:106
picks only visible front verices (may not be implemented for all nodes)
Definition: BaseNode.hh:115
ConstChildRIter childrenRBegin() const
Same but const.
Definition: BaseNode.hh:281
DrawModes::DrawMode drawMode_
private draw mode
Definition: BaseNode.hh:704
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:262
bool hidden()
Is node not visible (status != Active)?
Definition: BaseNode.hh:387
const BaseNode * parent() const
Get the nodes parent node.
Definition: BaseNode.hh:351
static unsigned int last_id_used__
used to provide unique IDs to nodes
Definition: BaseNode.hh:698
const GLSL::UniformPool * uniformPool_
user provided uniform pool for shader constants
Definition: BaseNode.hh:751
StatusMode
Status modi.
Definition: BaseNode.hh:365
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:391
RenderObjectModifier * getRenderObjectModifier()
Get render-object modifier.
Definition: BaseNode.hh:646
std::list< BaseNode * > children_
list of children
Definition: BaseNode.hh:695
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition: BaseNode.hh:406
ChildRIter childrenREnd()
Returns: reverse end-iterator of children.
Definition: BaseNode.hh:283
MultipassBitMask multipassStatus_
Definition: BaseNode.hh:666
virtual DrawModes::DrawMode availableDrawModes() const
Definition: BaseNode.hh:167
StatusMode status() const
Get node's status.
Definition: BaseNode.hh:377
std::list< BaseNode * >::const_iterator ConstChildIter
allows to iterate over children
Definition: BaseNode.hh:260
virtual void boundingBox(Vec3d &, Vec3d &)
Definition: BaseNode.hh:174
std::string name_
name of node
Definition: BaseNode.hh:689
void hide()
Hide Node: set status to HideNode.
Definition: BaseNode.hh:381
void setDirty(bool _dirty=true)
mark node for redrawn
Definition: BaseNode.hh:251
ACG::SceneGraph::BaseNode BaseNode
Base Node.
picks faces (may not be implemented for all nodes)
Definition: BaseNode.hh:102
MultipassBitMask multipassNode_
Definition: BaseNode.hh:672
void enablePicking(bool _enable)
Definition: BaseNode.hh:241
unsigned int id_
ID of node.
Definition: BaseNode.hh:701
void set_status(StatusMode _s)
Set the status of this node.
Definition: BaseNode.hh:379
std::string tes_
tess-eval
Definition: BaseNode.hh:732
void setRenderObjectModifier(RenderObjectModifier *_modifier)
Set modifier for render objects.
Definition: BaseNode.hh:641
BaseNode * parent()
Get the nodes parent node.
Definition: BaseNode.hh:348
std::string tcs_
tess-control
Definition: BaseNode.hh:729
Interface for modifying render objects.
std::list< BaseNode * >::const_reverse_iterator ConstChildRIter
allows to reverse iterate over children
Definition: BaseNode.hh:265
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
Definition: BaseNode.hh:248
void setMultipassNode(const MultipassBitMask _passNode)
Set multipass settings for the node.
Definition: BaseNode.hh:525
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
Definition: BaseNode.hh:513
picks only visible front edges (may not be implemented for all nodes)
Definition: BaseNode.hh:113
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
Definition: BaseNode.hh:469
void setRenderObjectUniformPool(const GLSL::UniformPool *_pool)
Set uniforms for shader based rendering.
Definition: BaseNode.hh:612
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:274
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:77
unsigned int traverseMode() const
Return how the node should be traversed.
Definition: BaseNode.hh:425
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:322
std::list< BaseNode * >::reverse_iterator ChildRIter
allows to reverse iterate over children
Definition: BaseNode.hh:267
virtual void leave(GLState &, const DrawModes::DrawMode &)
Definition: BaseNode.hh:217