Developer Documentation
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
76 {
77  return DrawModes::WIREFRAME;
78 }
79 
80 //----------------------------------------------------------------------------
81 
82 BoundingBoxNode::BoundingBoxNode( BaseNode* _parent, std::string _name ) :
83 MaterialNode(_parent,
84  _name,
87  box_(0)
88 {
90 
91 
92  box_ = new GLLineBox();
93 }
94 
95 //----------------------------------------------------------------------------
97  delete box_;
98 }
99 
100 //----------------------------------------------------------------------------
101 
102 void BoundingBoxNode::computeAABB( Vec3d* _outMin, Vec3d* _outMax )
103 {
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
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 //=============================================================================
DrawModes::DrawMode availableDrawModes() const
return available draw modes
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition: MeshNode2T.cc:461
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
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
draw with renderobjects
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:84
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
Definition: MeshNode2T.cc:409
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1006
virtual ~BoundingBoxNode()
destructor
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Definition: MeshNode2T.cc:407
GLMatrixd modelview
Modelview transform.
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:531
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
static void disable(GLenum _cap)
replaces glDisable, but supports locking
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
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
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:753
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1022
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
void computeAABB(Vec3d *_outMin, Vec3d *_outMax)
compute aabb of subtree
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:69
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
BoundingBoxNode(BaseNode *_parent=0, std::string _name="<BoundingBoxNode>")
default constructor
Interface class between scenegraph and renderer.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
ShaderGenDesc shaderDesc
Drawmode and other shader params.