Developer Documentation
Loading...
Searching...
No Matches
CoordFrameNode.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
45
46
47//=============================================================================
48//
49// CLASS CoordFrameNode - IMPLEMENTATION
50//
51//=============================================================================
52
53//== INCLUDES =================================================================
54
55
56#include "CoordFrameNode.hh"
57#include "SceneGraph.hh"
58#include "../GL/stipple_alpha.hh"
59
60#include <cstdio>
61
62
63//== NAMESPACES ===============================================================
64
65
66namespace ACG {
67namespace SceneGraph {
68
69
70//== IMPLEMENTATION ==========================================================
71
72
74CoordFrameNode(BaseNode* _parent, const std::string& _name)
75 : MaterialNode(_parent, _name),
76 bb_min_(Vec3f(0,0,0)),
77 bb_max_(Vec3f(0,0,0))
78{
79}
80
81
82//-----------------------------------------------------------------------------
83
84
91
92
93//-----------------------------------------------------------------------------
94
95
96void
98{
99 _bbMin.minimize(bb_min_);
100 _bbMax.maximize(bb_max_);
101}
102
103
104//-----------------------------------------------------------------------------
105
106
107void
108CoordFrameNode::draw(GLState& /* _state */ , const DrawModes::DrawMode& /* _drawMode */ )
109{
110 // draw bounding box
111
112 ACG::GLState::disable(GL_LIGHTING);
114
115 glBegin(GL_LINE_LOOP);
116 glVertex3f(bb_min_[0], bb_min_[1], bb_min_[2]);
117 glVertex3f(bb_max_[0], bb_min_[1], bb_min_[2]);
118 glVertex3f(bb_max_[0], bb_max_[1], bb_min_[2]);
119 glVertex3f(bb_min_[0], bb_max_[1], bb_min_[2]);
120 glEnd();
121
122 glBegin(GL_LINE_LOOP);
123 glVertex3f(bb_min_[0], bb_min_[1], bb_max_[2]);
124 glVertex3f(bb_max_[0], bb_min_[1], bb_max_[2]);
125 glVertex3f(bb_max_[0], bb_max_[1], bb_max_[2]);
126 glVertex3f(bb_min_[0], bb_max_[1], bb_max_[2]);
127 glEnd();
128
129 glBegin(GL_LINES);
130 glVertex3f(bb_min_[0], bb_min_[1], bb_min_[2]);
131 glVertex3f(bb_min_[0], bb_min_[1], bb_max_[2]);
132 glVertex3f(bb_max_[0], bb_min_[1], bb_min_[2]);
133 glVertex3f(bb_max_[0], bb_min_[1], bb_max_[2]);
134 glVertex3f(bb_max_[0], bb_max_[1], bb_min_[2]);
135 glVertex3f(bb_max_[0], bb_max_[1], bb_max_[2]);
136 glVertex3f(bb_min_[0], bb_max_[1], bb_min_[2]);
137 glVertex3f(bb_min_[0], bb_max_[1], bb_max_[2]);
138 glEnd();
139
140
141
142 // draw planes: transparently filled
143 Vec3f v0, v1, v2, v3;
144
145
146 stipple_alpha(0.25);
147
148 std::vector<float>::const_iterator p_it = x_planes_.begin();
149 std::vector<float>::const_iterator p_end = x_planes_.end();
150 char axis = 'x';
151
152 for (bool finished(false); !finished; )
153 {
154 // break check
155 if (p_it == p_end)
156 {
157 switch (axis)
158 {
159 case 'x':
160 p_it = y_planes_.begin();
161 p_end = y_planes_.end();
162 axis = 'y';
163 break;
164
165 case 'y':
166 p_it = z_planes_.begin();
167 p_end = z_planes_.end();
168 axis = 'z';
169 break;
170
171 default:
172 finished = true;
173 break;
174 }
175 continue;
176 }
177
178
179 switch (axis)
180 {
181 case 'x':
182 v0 = Vec3f(*p_it, bb_min_[1], bb_min_[2]);
183 v1 = Vec3f(*p_it, bb_max_[1], bb_min_[2]);
184 v2 = Vec3f(*p_it, bb_max_[1], bb_max_[2]);
185 v3 = Vec3f(*p_it, bb_min_[1], bb_max_[2]);
186 break;
187
188 case 'y':
189 v0 = Vec3f(bb_min_[0], *p_it, bb_min_[2]);
190 v1 = Vec3f(bb_max_[0], *p_it, bb_min_[2]);
191 v2 = Vec3f(bb_max_[0], *p_it, bb_max_[2]);
192 v3 = Vec3f(bb_min_[0], *p_it, bb_max_[2]);
193 break;
194
195 case 'z':
196 v0 = Vec3f(bb_min_[0], bb_min_[1], *p_it);
197 v1 = Vec3f(bb_max_[0], bb_min_[1], *p_it);
198 v2 = Vec3f(bb_max_[0], bb_max_[1], *p_it);
199 v3 = Vec3f(bb_min_[0], bb_max_[1], *p_it);
200 break;
201 };
202
203
204 // quads
205 glBegin(GL_QUADS);
206 glVertex(v0); glVertex(v1); glVertex(v2); glVertex(v3);
207 glEnd();
208
209
210 // outlines
211 glBegin(GL_LINE_LOOP);
212 glVertex(v0); glVertex(v1); glVertex(v2); glVertex(v3);
213 glEnd();
214
215
216 // text
217 //sprintf(s, "%c=%f", axis, *p_it);
218 //glText(v0, s); glText(v1, s); glText(v2, s); glText(v3, s);
219
220
221 ++p_it;
222 }
223
224
225 stipple_alpha(1.0);
226}
227
228
229//-----------------------------------------------------------------------------
230
231
232void
234{
235 BoundingBoxAction bb_action;
236 traverse(this, bb_action);
237
238 bb_min_ = bb_action.bbMin();
239 bb_max_ = bb_action.bbMax();
240}
241
242
243//-----------------------------------------------------------------------------
244
245
246void
247CoordFrameNode::set_bounding_box(const Vec3f& _bb_min, const Vec3f& _bb_max)
248{
249 bb_min_ = _bb_min;
250 bb_max_ = _bb_max;
251}
252
253
254//=============================================================================
255} // namespace SceneGraph
256} // namespace ACG
257//=============================================================================
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
Definition GLState.cc:1527
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
Definition GLState.cc:1729
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
void update_bounding_box()
update bounding box (compute in from BB of children)
CoordFrameNode(BaseNode *_parent=0, const std::string &_name="<CoordFrameNode>")
Default constructor.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
void set_bounding_box(const Vec3f &_bb_min, const Vec3f &_bb_max)
set bounding box
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
drawing the primitive
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition Vector11T.hh:588
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition Vector11T.hh:560
DrawMode WIREFRAME
draw wireframe
Definition DrawModes.cc:78
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition DrawModes.cc:81
void traverse(BaseNode *_node, Action &_action)
Namespace providing different geometric functions concerning angles.
VectorT< float, 3 > Vec3f
Definition VectorT.hh:119
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
Definition gl.hh:95