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