Developer Documentation
Loading...
Searching...
No Matches
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
45
46//=============================================================================
47//
48// CLASS BaseNode
49//
50//=============================================================================
51
52
53#ifndef ACG_BASE_NODE_HH
54#define ACG_BASE_NODE_HH
55
56
57//== INCLUDES =================================================================
58
59// ACG
60#include "../Math/VectorT.hh"
61#include "../GL/GLState.hh"
62#include "../Config/ACGDefines.hh"
63#include "PickTarget.hh"
64
65// Qt
66//#include <qgl.h>
67#include <QMouseEvent>
68
69// stdc++
70#include <vector>
71#include <string>
72#include <ACG/Scenegraph/DrawModes.hh>
73#include <ACG/GL/RenderObject.hh>
74
75//== NAMESPACES ===============================================================
76
77
78namespace ACG {
79
80class IRenderer;
81
82namespace SceneGraph {
83
84// prototype declaration to avoid include-loop
85class Material;
86
87
88//== CLASS DEFINITION =========================================================
89
90
92#define ACG_CLASSNAME(_className) \
93 virtual const std::string& className() const override { \
94 static std::string cname( #_className ); return cname; \
95}
96
97
104class ACGDLLEXPORT BaseNode
105{
106public:
107
108
110 BaseNode(BaseNode* _parent=0, std::string _name="<unknown>");
111
113 BaseNode(BaseNode* _parent, BaseNode* _child, std::string _name="<unknown>");
114
116 virtual ~BaseNode();
117
126 void delete_subtree();
127
128
129 // --- basic interface ---
130
132 virtual const std::string& className() const = 0;
133
136 virtual DrawModes::DrawMode availableDrawModes() const { return DrawModes::NONE; }
137
143 virtual void boundingBox(Vec3d& /* _bbMin */, Vec3d& /*_bbMax*/ ) {}
144
160 virtual void enter(GLState& /*_state */, const DrawModes::DrawMode& /*_drawMode*/ ) {}
161
178 virtual void enter(IRenderer* /*_renderer*/, GLState& _state, const DrawModes::DrawMode& _drawMode) {
179 enter(_state, _drawMode);
180 }
181
192 virtual void draw(GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
193
210 virtual void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat) {}
211
223 virtual void leave(GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
224
239 virtual void leave(IRenderer* /*_renderer*/, GLState& _state, const DrawModes::DrawMode& _drawMode) {
240 leave(_state, _drawMode);
241 }
242
248 virtual void enterPick(GLState& _state , PickTarget _target, const DrawModes::DrawMode& _drawMode );
249
254 virtual void pick(GLState& /* _state */, PickTarget /* _target */ ) {}
255
260 virtual void leavePick(GLState& _state, PickTarget _target, const DrawModes::DrawMode& _drawMode );
261
265 void enablePicking(bool _enable) { pickingEnabled_ = _enable; };
266
269 bool pickingEnabled() { return pickingEnabled_; };
270
272 virtual void mouseEvent(GLState& /* _state */, QMouseEvent* /* _event */ ) {}
273
275 void setDirty (bool _dirty = true) { dirty_ = _dirty; }
276
278 bool isDirty () const { return dirty_; }
279
280
281 // --- iterators ---
282
284 typedef std::vector<BaseNode*>::const_iterator ConstChildIter;
286 typedef std::vector<BaseNode*>::iterator ChildIter;
287
289 typedef std::vector<BaseNode*>::const_reverse_iterator ConstChildRIter;
291 typedef std::vector<BaseNode*>::reverse_iterator ChildRIter;
292
294 ChildIter childrenBegin() { return children_.begin(); }
296 ConstChildIter childrenBegin() const { return children_.begin(); }
298 ChildIter childrenEnd() { return children_.end(); }
300 ConstChildIter childrenEnd() const { return children_.end(); }
301
303 ChildRIter childrenRBegin() { return children_.rbegin(); }
305 ConstChildRIter childrenRBegin() const { return children_.rbegin(); }
307 ChildRIter childrenREnd() { return children_.rend(); }
309 ConstChildRIter childrenREnd() const { return children_.rend(); }
310
311
312
313
314
315 // --- insert / remove ---
316
318 void push_back(BaseNode* _node)
319 {
320 if (_node)
321 {
322 children_.push_back(_node);
323 _node->parent_=this;
324 }
325 }
326
330 void remove(ChildIter _pos)
331 {
332 if (_pos == childrenEnd()) return;
333 //(*_pos)->parent_=0;
334 children_.erase(_pos);
335 }
336
338 size_t nChildren() const { return children_.size(); }
339
347 {
348 ChildIter i=std::find(children_.begin(),children_.end(),_node);
349 return i;
350 }
351
352
355 BaseNode * find( const std::string & _name )
356 {
357 if ( name() == _name )
358 return this;
359
360 for ( BaseNode::ChildIter cIt = childrenBegin();
361 cIt != childrenEnd(); ++cIt )
362 {
363 BaseNode * n = (*cIt)->find( _name );
364 if ( n ) return n;
365 }
366
367 return 0;
368 }
369
370
372 BaseNode* parent() { return parent_; }
373
375 const BaseNode* parent() const { return parent_; }
376
382 void set_parent(BaseNode* _parent);
383
384
385 // --- status info ---
386
387
390 {
392 Active = 0x1,
394 HideNode = 0x2,
396 HideChildren = 0x4,
398 HideSubtree = 0x8
399 };
401 StatusMode status() const { return status_; }
403 void set_status(StatusMode _s) { status_ = _s; }
405 void hide() { set_status(HideNode); }
407 void show() { set_status(Active); }
409 bool visible() { return status_ == Active; }
411 bool hidden() { return status_ != Active; }
412
413
415 std::string name() const { return name_; }
417 void name(const std::string& _name) { name_ = _name; }
418
419
423 unsigned int id() const { return id_; }
424
425
426
427 //--- draw mode ---
428
430 DrawModes::DrawMode drawMode() const { return drawMode_; }
433 void drawMode(DrawModes::DrawMode _drawMode) { drawMode_ = _drawMode; }
434
435 //--- traverse type ---
436
439 {
441 NodeFirst = 0x1,
443 ChildrenFirst = 0x2,
445 SecondPass = 0x4
446 };
447
449 unsigned int traverseMode () const { return traverseMode_; }
450
452 void setTraverseMode(unsigned int _mode) { traverseMode_ = _mode; }
453
454 //===========================================================================
464 //===========================================================================
465
466public:
467
469 typedef unsigned int MultipassBitMask;
470
471
473 enum PASSES {
474 NOPASS = 0,
475 ALLPASSES = 1 << 0,
476 PASS_1 = 1 << 1,
477 PASS_2 = 1 << 2,
478 PASS_3 = 1 << 3,
479 PASS_4 = 1 << 4,
480 PASS_5 = 1 << 5,
481 PASS_6 = 1 << 6,
482 PASS_7 = 1 << 7,
483 PASS_8 = 1 << 8
484 };
485
493 MultipassBitMask multipassStatus() const {return multipassStatus_;};
494
495
505 void setMultipassStatus(const MultipassBitMask _passStatus) { multipassStatus_ = _passStatus; };
506
516 void multipassStatusSetActive(const unsigned int _i, bool _active);
517
526 bool multipassStatusActive(const unsigned int _i) const;
527
528
529
537 MultipassBitMask multipassNode() const {return multipassNode_;};
538
539
540
549 void setMultipassNode(const MultipassBitMask _passNode) { multipassNode_ = _passNode; };
550
560 void multipassNodeSetActive(const unsigned int _i , bool _active);
561
570 bool multipassNodeActive(const unsigned int _i) const;
571
572
573 //===========================================================================
580 //===========================================================================
581
582public:
583
602 void setRenderObjectShaders(const std::string& _vertexShaderFile, const std::string& _geometryShaderFile, const std::string& _fragmentShaderFile, bool _relativePaths = true, DrawModes::DrawModePrimitive _primitiveType = DrawModes::PRIMITIVE_POLYGON);
603
624 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);
625
626
636 void setRenderObjectUniformPool(const GLSL::UniformPool* _pool) {uniformPool_ = _pool;}
637
641 const GLSL::UniformPool* getRenderObjectUniformPool() {return uniformPool_;}
642
654 void setRenderObjectTexture(int _samplerSlot, GLuint _texId, GLenum _texType = GL_TEXTURE_2D);
655
656
665 void setRenderObjectModifier(RenderObjectModifier* _modifier) {renderModifier_ = _modifier;}
666
671
672
673
682 void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject* _obj) const;
683
684private:
685
691
697
700private:
701
704
706 void operator=(const BaseNode&);
707
708
711
713 std::string name_;
714
717
719 std::vector<BaseNode*> children_;
720
722 static unsigned int last_id_used__;
723
725 unsigned int id_;
726
729
734
736 bool dirty_;
737
739 unsigned int traverseMode_;
740
741
742 // settings for shader-based rendering with render-objects
743private:
744
745 struct ShaderSet
746 {
747 // shader filenames
748
750 std::string vs_;
751
753 std::string tcs_;
754
756 std::string tes_;
757
759 std::string gs_;
760
762 std::string fs_;
763
766 };
767
769 std::map<DrawModes::DrawModePrimitive, ShaderSet> shaderSettings_;
770
772 std::map<int, RenderObject::Texture> textureSettings_;
773
776
779};
780
781
782//=============================================================================
783} // namespace SceneGraph
784} // namespace ACG
785//=============================================================================
786#endif // ACG_BASE_NODE_HH defined
787//=============================================================================
ACG::SceneGraph::BaseNode BaseNode
Base Node.
Interface for modifying render objects.
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition BaseNode.hh:294
std::vector< BaseNode * >::reverse_iterator ChildRIter
allows to reverse iterate over children
Definition BaseNode.hh:291
bool hidden()
Is node not visible (status != Active)?
Definition BaseNode.hh:411
bool isDirty() const
Check if node should be redrawn.
Definition BaseNode.hh:278
BaseNode * parent_
pointer to parent node
Definition BaseNode.hh:710
bool dirty_
Flag indicating that the node has to be redrawn.
Definition BaseNode.hh:736
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition BaseNode.hh:298
RenderObjectModifier * renderModifier_
render-object modifier
Definition BaseNode.hh:778
unsigned int traverseMode_
traverse mode
Definition BaseNode.hh:739
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition BaseNode.hh:430
size_t nChildren() const
number of children
Definition BaseNode.hh:338
unsigned int traverseMode() const
Return how the node should be traversed.
Definition BaseNode.hh:449
MultipassBitMask multipassStatus_
Definition BaseNode.hh:690
void operator=(const BaseNode &)
Assignment operator. Disabled.
ConstChildRIter childrenRBegin() const
Same but const.
Definition BaseNode.hh:305
void enablePicking(bool _enable)
Definition BaseNode.hh:265
void drawMode(DrawModes::DrawMode _drawMode)
Definition BaseNode.hh:433
RenderObjectModifier * getRenderObjectModifier()
Get render-object modifier.
Definition BaseNode.hh:670
void setMultipassStatus(const MultipassBitMask _passStatus)
Set multipass settings for the nodes status functions.
Definition BaseNode.hh:505
std::vector< BaseNode * >::const_reverse_iterator ConstChildRIter
allows to reverse iterate over children
Definition BaseNode.hh:289
TraverseMode
Node traverse types.
Definition BaseNode.hh:439
std::vector< BaseNode * >::const_iterator ConstChildIter
allows to iterate over children
Definition BaseNode.hh:284
ConstChildRIter childrenREnd() const
Same but const.
Definition BaseNode.hh:309
unsigned int MultipassBitMask
Multipass pass bit mask type.
Definition BaseNode.hh:469
void name(const std::string &_name)
rename a node
Definition BaseNode.hh:417
static unsigned int last_id_used__
used to provide unique IDs to nodes
Definition BaseNode.hh:722
void hide()
Hide Node: set status to HideNode.
Definition BaseNode.hh:405
MultipassBitMask multipassNode_
Definition BaseNode.hh:696
const GLSL::UniformPool * uniformPool_
user provided uniform pool for shader constants
Definition BaseNode.hh:775
virtual void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Deferred draw call with shader based renderer.
Definition BaseNode.hh:210
ConstChildIter childrenBegin() const
Same but cont.
Definition BaseNode.hh:296
BaseNode * parent()
Get the nodes parent node.
Definition BaseNode.hh:372
MultipassBitMask multipassNode() const
Get the current multipass settings for the node.
Definition BaseNode.hh:537
ChildRIter childrenREnd()
Returns: reverse end-iterator of children.
Definition BaseNode.hh:307
ConstChildIter childrenEnd() const
Same but const.
Definition BaseNode.hh:300
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition BaseNode.hh:286
virtual void enter(IRenderer *, GLState &_state, const DrawModes::DrawMode &_drawMode)
Definition BaseNode.hh:178
PASSES
This enum should be used to enable rendering of a node in different.
Definition BaseNode.hh:473
void setTraverseMode(unsigned int _mode)
Set traverse mode for node.
Definition BaseNode.hh:452
std::string name_
name of node
Definition BaseNode.hh:713
unsigned int id_
ID of node.
Definition BaseNode.hh:725
virtual void boundingBox(Vec3d &, Vec3d &)
Definition BaseNode.hh:143
void setDirty(bool _dirty=true)
mark node for redrawn
Definition BaseNode.hh:275
DrawModes::DrawMode drawMode_
private draw mode
Definition BaseNode.hh:728
ChildRIter childrenRBegin()
Returns: reverse begin-iterator of children.
Definition BaseNode.hh:303
MultipassBitMask multipassStatus() const
Get the current multipass settings for the nodes status functions.
Definition BaseNode.hh:493
StatusMode status() const
Get node's status.
Definition BaseNode.hh:401
void set_status(StatusMode _s)
Set the status of this node.
Definition BaseNode.hh:403
void setMultipassNode(const MultipassBitMask _passNode)
Set multipass settings for the node.
Definition BaseNode.hh:549
std::map< int, RenderObject::Texture > textureSettings_
texture settings for shader based rendering
Definition BaseNode.hh:772
virtual const std::string & className() const =0
Return class name (implemented by the ACG_CLASSNAME macro)
virtual void leave(GLState &, const DrawModes::DrawMode &)
Definition BaseNode.hh:223
virtual DrawModes::DrawMode availableDrawModes() const
Definition BaseNode.hh:136
std::map< DrawModes::DrawModePrimitive, ShaderSet > shaderSettings_
shader settings for primitive modes
Definition BaseNode.hh:769
unsigned int id() const
Definition BaseNode.hh:423
std::string name() const
Returns: name of node (needs not be unique)
Definition BaseNode.hh:415
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition BaseNode.hh:318
virtual void leave(IRenderer *, GLState &_state, const DrawModes::DrawMode &_drawMode)
Definition BaseNode.hh:239
void setRenderObjectUniformPool(const GLSL::UniformPool *_pool)
Set uniforms for shader based rendering.
Definition BaseNode.hh:636
void remove(ChildIter _pos)
Definition BaseNode.hh:330
BaseNode * find(const std::string &_name)
Definition BaseNode.hh:355
const GLSL::UniformPool * getRenderObjectUniformPool()
Get uniforms for shader based rendering.
Definition BaseNode.hh:641
virtual void pick(GLState &, PickTarget)
Definition BaseNode.hh:254
std::vector< BaseNode * > children_
list of children
Definition BaseNode.hh:719
const BaseNode * parent() const
Get the nodes parent node.
Definition BaseNode.hh:375
void show()
Show node: set status to Active.
Definition BaseNode.hh:407
StatusMode status_
node status()
Definition BaseNode.hh:716
BaseNode(const BaseNode &)
Copy constructor. Disabled.
virtual void draw(GLState &, const DrawModes::DrawMode &)
Draw this node using the draw modes _drawMode.
Definition BaseNode.hh:192
virtual void enter(GLState &, const DrawModes::DrawMode &)
Definition BaseNode.hh:160
void setRenderObjectModifier(RenderObjectModifier *_modifier)
Set modifier for render objects.
Definition BaseNode.hh:665
virtual void mouseEvent(GLState &, QMouseEvent *)
Handle mouse event (some interaction, e.g. modeling)
Definition BaseNode.hh:272
bool visible()
Is node visible (status == Active)?
Definition BaseNode.hh:409
ChildIter find(BaseNode *_node)
Definition BaseNode.hh:346
GLSL uniform pool.
DrawModePrimitive
Primitive mode of a mesh.
Definition DrawModes.hh:119
PickTarget
What target to use for picking.
Definition PickTarget.hh:74
Namespace providing different geometric functions concerning angles.
Interface class between scenegraph and renderer.
bool relativePaths_
rel or abs path
Definition BaseNode.hh:765
std::string vs_
vertex shader
Definition BaseNode.hh:750
std::string tcs_
tess-control
Definition BaseNode.hh:753