Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BoundingBoxNode.cc
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 //
55 // CLASS BoundingBoxNode - IMPLEMENTATION
56 //
57 //=============================================================================
58
59 //== INCLUDES =================================================================
60
61 #include "BoundingBoxNode.hh"
62 #include "SceneGraph.hh"
63 #include "../GL/GLPrimitives.hh"
64
65
66 //== NAMESPACES ===============================================================
67
68 namespace ACG {
69 namespace SceneGraph {
70
71 //== IMPLEMENTATION ==========================================================
72
73 DrawModes::DrawMode
74 BoundingBoxNode::
75 availableDrawModes() const
76 {
77 return DrawModes::WIREFRAME;
78 }
79
80 //----------------------------------------------------------------------------
81
82 BoundingBoxNode::BoundingBoxNode( BaseNode* _parent, std::string _name ) :
83 MaterialNode(_parent,
84 _name,
85 MaterialNode::BaseColor |
86 MaterialNode::LineWidth),
87 box_(0)
88 {
89 drawMode(DrawModes::WIREFRAME);
90
91
92 box_ = new GLLineBox();
93 }
94
95 //----------------------------------------------------------------------------
96 BoundingBoxNode::~BoundingBoxNode() {
97 delete box_;
98 }
99
100 //----------------------------------------------------------------------------
101
102 void BoundingBoxNode::computeAABB( Vec3d* _outMin, Vec3d* _outMax )
103 {
104 ACG::SceneGraph::BoundingBoxAction act;
105 ACG::SceneGraph::traverse(this, act);
106
107 if (_outMin)
108 *_outMin = (ACG::Vec3d) act.bbMin();
109
110 if (_outMax)
111 *_outMax = (ACG::Vec3d) act.bbMax();
112 }
113
114 //----------------------------------------------------------------------------
115
116 void
117 BoundingBoxNode::
118 draw(GLState& _state , const DrawModes::DrawMode& _drawMode)
119 {
120 if (_drawMode & DrawModes::WIREFRAME)
121 {
122 ACG::Vec3d bbmin;
123 ACG::Vec3d bbmax;
124 computeAABB(&bbmin, &bbmax);
125
126 ACG::Vec3d bbcenter = (bbmin + bbmax) * 0.5;
127 ACG::Vec3d bbsize = bbmax - bbmin;
128
129
130 glPushAttrib (GL_ENABLE_BIT);
131
132 ACG::GLState::disable(GL_LIGHTING);
133
134 _state.push_modelview_matrix();
135
136 _state.translate(bbcenter);
137 _state.scale(bbsize[0], bbsize[1], bbsize[2]);
138
139 glColor4f(0.0f,1.0f,0.0f,1.0f);
140
141 box_->draw_primitive();
142
143 _state.pop_modelview_matrix();
144 glPopAttrib ();
145 }
146 }
147
148 //----------------------------------------------------------------------------
149
150 void BoundingBoxNode::getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat)
151 {
152 int dmlayerId = _drawMode.getLayerIndexByPrimitive(DrawModes::PRIMITIVE_WIREFRAME);
153
154 if (dmlayerId >= 0)
155 {
156 ACG::Vec3d bbmin;
157 ACG::Vec3d bbmax;
158 computeAABB(&bbmin, &bbmax);
159
160 ACG::Vec3d bbcenter = (bbmin + bbmax) * 0.5;
161 ACG::Vec3d bbsize = bbmax - bbmin;
162
163 // create renderobject
164 RenderObject ro;
165 ro.initFromState(&_state);
166 ro.depthTest = true;
167 ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
168 ro.emissive = Vec3f(0.0f, 1.0f, 0.0f);
169
170 ro.modelview.translate(bbcenter);
171 ro.modelview.scale(bbsize[0], bbsize[1], bbsize[2]);
172
173 box_->addToRenderer_primitive(_renderer, &ro);
174 }
175 }
176
177 //=============================================================================
178 } // namespace SceneGraph
179 } // namespace ACG
180 //=============================================================================
ACG::GLLineBox
Definition: GLPrimitives.hh:274
ACG::GLState::scale
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:753
ACG::RenderObject::shaderDesc
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Definition: RenderObject.hh:232
ACG::SceneGraph::BoundingBoxNode::getRenderObjects
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
draw with renderobjects
Definition: BoundingBoxNode.cc:150
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
ACG::SceneGraph::DrawModes::DrawMode::getLayerIndexByPrimitive
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
ACG::SceneGraph::ACG::GLState::disable
static void disable(GLenum _cap)
replaces glDisable, but supports locking
ACG::RenderObject
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:105
ACG::GLState::translate
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:531
ACG::RenderObject::initFromState
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:69
ACG::SceneGraph::ACG::SceneGraph::BoundingBoxAction::bbMax
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
Definition: MeshNode2T.cc:409
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
ACG::GLState
Definition: GLState.hh:220
ACG::SceneGraph::ACG::SceneGraph::BaseNode::drawMode
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition: MeshNode2T.cc:406
ACG::SceneGraph::BoundingBoxNode::BoundingBoxNode
BoundingBoxNode(BaseNode *_parent=0, std::string _name="<BoundingBoxNode>")
default constructor
Definition: BoundingBoxNode.cc:82
ACG::GLState::push_modelview_matrix
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1006
ACG::GLMatrixT::translate
void translate(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with translation matrix (x,y,z)
Definition: GLMatrixT.cc:102
ACG::IRenderer
Definition: IRenderer.hh:84
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:294
ACG::SceneGraph::ACG::SceneGraph::Material
Definition: MeshNode2T.cc:85
ACG::GLMatrixT::scale
void scale(Scalar _x, Scalar _y, Scalar _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
multiply self with scaling matrix (x,y,z)
Definition: GLMatrixT.cc:81
ACG::Vec3f
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
ACG::SceneGraph::BoundingBoxNode::~BoundingBoxNode
virtual ~BoundingBoxNode()
destructor
Definition: BoundingBoxNode.cc:96
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::GLState::pop_modelview_matrix
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1022
ACG::SceneGraph::ACG::SceneGraph::BoundingBoxAction
Definition: MeshNode2T.cc:368
SceneGraph.hh
ACG::SceneGraph::BoundingBoxNode::draw
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
Definition: BoundingBoxNode.cc:118
ACG::SceneGraph::DrawModes::WIREFRAME
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:84
ACG::RenderObject::modelview
GLMatrixd modelview
Modelview transform.
Definition: RenderObject.hh:145
ACG::SceneGraph::ACG::SceneGraph::BoundingBoxAction::bbMin
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Definition: MeshNode2T.cc:407
ACG::SceneGraph::BoundingBoxNode::computeAABB
void computeAABB(Vec3d *_outMin, Vec3d *_outMax)
compute aabb of subtree
Definition: BoundingBoxNode.cc:102
ACG::SceneGraph::MaterialNode
Definition: MaterialNode.hh:321
ACG::SceneGraph::traverse
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
ACG::SceneGraph::BoundingBoxNode::availableDrawModes
DrawModes::DrawMode availableDrawModes() const
return available draw modes
Definition: BoundingBoxNode.cc:75