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