Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SliceNode.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 #include "SliceNode.hh"
56 
57 //=============================================================================
58 
59 namespace ACG {
60 namespace SceneGraph {
61 
62 //=============================================================================
63 
64 
65 SliceNode::SliceNode( BaseNode * _parent,
66  std::string _name ) :
67  BaseNode( _parent, _name ),
68  view_frame_(false),
69  enabled_(NONE)
70 {
71  set_visible_box( Vec3f( 0, 0, 0 ),
72  Vec3f( 1, 1, 1 ) );
73 
74  set_texture_box( Vec3f( 0, 0, 0 ),
75  Vec3f( 1, 1, 1 ) );
76 
77  set_cursor( Vec3f( 0.5, 0.5, 0.5 ) );
78 }
79 
80 
81 //----------------------------------------------------------------------------
82 
83 
84 SliceNode::~SliceNode()
85 {
86 }
87 
88 
89 //----------------------------------------------------------------------------
90 
91 
92 void
93 SliceNode::view_frame( bool _view_frame )
94 {
95  view_frame_ = _view_frame;
96 }
97 
98 
99 //----------------------------------------------------------------------------
100 
101 
102 void
103 SliceNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
104 {
105  _bbMin.minimize( visible_min_ );
106  _bbMax.maximize( visible_max_ );
107 }
108 
109 
110 //----------------------------------------------------------------------------
111 
112 
115 {
116  return 0;
117  /*
118  return ( DrawModes::POINTS |
119  DrawModes::WIREFRAME |
120  DrawModes::HIDDENLINE |
121  DrawModes::SOLID_FLAT_SHADED |
122  DrawModes::SOLID_SMOOTH_SHADED );
123 */
124 }
125 
126 
127 //----------------------------------------------------------------------------
128 
129 
130 void
131 SliceNode::draw( GLState & /* _state */ , const DrawModes::DrawMode& /* _drawMode */ )
132 {
133 
134  if ( is_enabled( NONE ) )
135  return;
136 
137  glPushAttrib(GL_LIGHTING_BIT);
138  glPushAttrib(GL_ENABLE_BIT);
139  glPushAttrib(GL_COLOR_BUFFER_BIT);
140 
141  if ( view_frame_ )
142  draw_frame();
143 
144  ACG::GLState::enable( GL_LIGHTING );
145  glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
146 
147  ACG::GLState::enable( GL_TEXTURE_3D );
148 
149  ACG::GLState::enable( GL_BLEND );
150  ACG::GLState::blendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
151 
152  draw_planes();
153 
154  ACG::GLState::disable( GL_BLEND );
155  ACG::GLState::disable( GL_TEXTURE_3D );
156  ACG::GLState::disable( GL_LIGHTING );
157 
158  glPopAttrib();
159  glPopAttrib();
160  glPopAttrib();
161 
162 }
163 
164 
165 //----------------------------------------------------------------------------
166 
167 
168 void
169 SliceNode::draw_frame() const
170 {
171  ACG::GLState::disable( GL_BLEND );
172  ACG::GLState::disable( GL_TEXTURE_3D );
173  ACG::GLState::disable( GL_LIGHTING );
174 
175  glBegin( GL_LINES );
176 
177  glColor3f( 1, 1, 1 );
178 
179  glVertex3f( visible_min_[0], visible_min_[1], visible_min_[2] );
180  glVertex3f( visible_min_[0], visible_min_[1], visible_max_[2] );
181  glVertex3f( visible_min_[0], visible_max_[1], visible_min_[2] );
182  glVertex3f( visible_min_[0], visible_max_[1], visible_max_[2] );
183  glVertex3f( visible_max_[0], visible_max_[1], visible_min_[2] );
184  glVertex3f( visible_max_[0], visible_max_[1], visible_max_[2] );
185  glVertex3f( visible_max_[0], visible_min_[1], visible_min_[2] );
186  glVertex3f( visible_max_[0], visible_min_[1], visible_max_[2] );
187 
188  glVertex3f( visible_min_[0], visible_min_[1], visible_min_[2] );
189  glVertex3f( visible_min_[0], visible_max_[1], visible_min_[2] );
190  glVertex3f( visible_min_[0], visible_min_[1], visible_max_[2] );
191  glVertex3f( visible_min_[0], visible_max_[1], visible_max_[2] );
192  glVertex3f( visible_max_[0], visible_min_[1], visible_min_[2] );
193  glVertex3f( visible_max_[0], visible_max_[1], visible_min_[2] );
194  glVertex3f( visible_max_[0], visible_min_[1], visible_max_[2] );
195  glVertex3f( visible_max_[0], visible_max_[1], visible_max_[2] );
196 
197  glVertex3f( visible_min_[0], visible_min_[1], visible_min_[2] );
198  glVertex3f( visible_max_[0], visible_min_[1], visible_min_[2] );
199  glVertex3f( visible_min_[0], visible_min_[1], visible_max_[2] );
200  glVertex3f( visible_max_[0], visible_min_[1], visible_max_[2] );
201  glVertex3f( visible_min_[0], visible_max_[1], visible_min_[2] );
202  glVertex3f( visible_max_[0], visible_max_[1], visible_min_[2] );
203  glVertex3f( visible_min_[0], visible_max_[1], visible_max_[2] );
204  glVertex3f( visible_max_[0], visible_max_[1], visible_max_[2] );
205 
206  glEnd();
207 
208  glBegin( GL_LINES );
209 
210  glColor3f( 1, 1, 1 );
211 
212  if ( is_enabled( XY_PLANE ) )
213  {
214  glVertex3f( visible_min_[0], visible_min_[1], cursor_[2] );
215  glVertex3f( visible_max_[0], visible_min_[1], cursor_[2] );
216  glVertex3f( visible_max_[0], visible_min_[1], cursor_[2] );
217  glVertex3f( visible_max_[0], visible_max_[1], cursor_[2] );
218  glVertex3f( visible_max_[0], visible_max_[1], cursor_[2] );
219  glVertex3f( visible_min_[0], visible_max_[1], cursor_[2] );
220  glVertex3f( visible_min_[0], visible_max_[1], cursor_[2] );
221  glVertex3f( visible_min_[0], visible_min_[1], cursor_[2] );
222  }
223 
224 
225  if ( is_enabled( YZ_PLANE ) )
226  {
227  glVertex3f( cursor_[0], visible_min_[1], visible_min_[2] );
228  glVertex3f( cursor_[0], visible_min_[1], visible_max_[2] );
229  glVertex3f( cursor_[0], visible_min_[1], visible_max_[2] );
230  glVertex3f( cursor_[0], visible_max_[1], visible_max_[2] );
231  glVertex3f( cursor_[0], visible_max_[1], visible_max_[2] );
232  glVertex3f( cursor_[0], visible_max_[1], visible_min_[2] );
233  glVertex3f( cursor_[0], visible_max_[1], visible_min_[2] );
234  glVertex3f( cursor_[0], visible_min_[1], visible_min_[2] );
235  }
236 
237 
238  if ( is_enabled( XZ_PLANE ) )
239  {
240  glVertex3f( visible_min_[0], cursor_[1], visible_min_[2] );
241  glVertex3f( visible_max_[0], cursor_[1], visible_min_[2] );
242  glVertex3f( visible_max_[0], cursor_[1], visible_min_[2] );
243  glVertex3f( visible_max_[0], cursor_[1], visible_max_[2] );
244  glVertex3f( visible_max_[0], cursor_[1], visible_max_[2] );
245  glVertex3f( visible_min_[0], cursor_[1], visible_max_[2] );
246  glVertex3f( visible_min_[0], cursor_[1], visible_max_[2] );
247  glVertex3f( visible_min_[0], cursor_[1], visible_min_[2] );
248  }
249 
250  glEnd();
251 }
252 
253 
254 //----------------------------------------------------------------------------
255 
256 
257 void
258 SliceNode::draw_planes() const
259 {
260  ACG::GLState::shadeModel( GL_FLAT );
261 
262 
263  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
264 
265  ACG::GLState::depthRange(0.01, 1.0);
266 
267  Vec3f rel;
268  Vec3f tcmin;
269  Vec3f tcmax;
270 
271  for ( int i = 0; i < 3; ++i )
272  {
273  rel[i] = ( cursor_[i]-texture_min_[i] ) / ( texture_max_[i] - texture_min_[i] );
274  tcmin[i] = ( visible_min_[i] - texture_min_[i] )
275  / ( texture_max_[i] - texture_min_[i] );
276  tcmax[i] = ( visible_max_[i] - texture_min_[i] )
277  / ( texture_max_[i] - texture_min_[i] );
278  }
279 
280  if ( cursor_[2] >= visible_min_[2] &&
281  cursor_[2] <= visible_max_[2] &&
282  is_enabled( XY_PLANE ) )
283  {
284  glBegin( GL_QUADS );
285 
286  glNormal3f( 0, 0, 1 );
287 
288  glTexCoord3f( tcmin[0], tcmin[1], rel[2] );
289  glVertex3f( visible_min_[0], visible_min_[1], cursor_[2] );
290 
291  glTexCoord3f( tcmax[0], tcmin[1], rel[2] );
292  glVertex3f( visible_max_[0], visible_min_[1], cursor_[2] );
293 
294  glTexCoord3f( tcmax[0], tcmax[1], rel[2] );
295  glVertex3f( visible_max_[0], visible_max_[1], cursor_[2] );
296 
297  glTexCoord3f( tcmin[0], tcmax[1], rel[2] );
298  glVertex3f( visible_min_[0], visible_max_[1], cursor_[2] );
299 
300  glEnd();
301  }
302 
303  if ( cursor_[0] >= visible_min_[0] &&
304  cursor_[0] <= visible_max_[0] &&
305  is_enabled( YZ_PLANE ) )
306  {
307  glBegin( GL_QUADS );
308 
309  glNormal3f( -1, 0, 0 );
310 
311  glTexCoord3f( rel[0], tcmin[1], tcmin[2] );
312  glVertex3f( cursor_[0], visible_min_[1], visible_min_[2] );
313 
314  glTexCoord3f( rel[0], tcmin[1], tcmax[2] );
315  glVertex3f( cursor_[0], visible_min_[1], visible_max_[2] );
316 
317  glTexCoord3f( rel[0], tcmax[1], tcmax[2] );
318  glVertex3f( cursor_[0], visible_max_[1], visible_max_[2] );
319 
320  glTexCoord3f( rel[0], tcmax[1], tcmin[2] );
321  glVertex3f( cursor_[0], visible_max_[1], visible_min_[2] );
322 
323  glEnd();
324  }
325 
326  if ( cursor_[1] >= visible_min_[1] &&
327  cursor_[1] <= visible_max_[1] &&
328  is_enabled( XZ_PLANE ) )
329  {
330  glBegin( GL_QUADS );
331 
332  glNormal3f( 0, -1, 0 );
333 
334  glTexCoord3f( tcmin[0], rel[1], tcmin[2] );
335  glVertex3f( visible_min_[0], cursor_[1], visible_min_[2] );
336 
337  glTexCoord3f( tcmax[0], rel[1], tcmin[2] );
338  glVertex3f( visible_max_[0], cursor_[1], visible_min_[2] );
339 
340  glTexCoord3f( tcmax[0], rel[1], tcmax[2] );
341  glVertex3f( visible_max_[0], cursor_[1], visible_max_[2] );
342 
343  glTexCoord3f( tcmin[0], rel[1], tcmax[2] );
344  glVertex3f( visible_min_[0], cursor_[1], visible_max_[2] );
345 
346  glEnd();
347  }
348 
349 
350  ACG::GLState::depthRange(0.0, 1.0);
351 }
352 
353 //----------------------------------------------------------------------------
354 
355 
357 SliceNode::cursor() const
358 {
359  return cursor_;
360 }
361 
362 
363 //----------------------------------------------------------------------------
364 
365 
366 void
367 SliceNode::set_cursor( const Vec3f & _cursor )
368 {
369  cursor_ = _cursor;
370 }
371 
372 
373 //----------------------------------------------------------------------------
374 
375 
376 bool
377 SliceNode::is_enabled( Plane _plane ) const
378 {
379  return enabled_ == _plane;
380 }
381 
382 
383 //----------------------------------------------------------------------------
384 
385 
386 void
387 SliceNode::set_enabled( Plane _plane )
388 {
389  enabled_ = _plane;
390 }
391 
392 
393 //----------------------------------------------------------------------------
394 
395 
396 void
397 SliceNode::set_visible_box( const Vec3f & _box_min,
398  const Vec3f & _box_max )
399 {
400  visible_min_ = _box_min;
401  visible_max_ = _box_max;
402 }
403 
404 
405 //----------------------------------------------------------------------------
406 
407 
408 void
409 SliceNode::set_texture_box( const Vec3f & _box_min,
410  const Vec3f & _box_max )
411 {
412  texture_min_ = _box_min;
413  texture_max_ = _box_max;
414 }
415 
416 
417 //----------------------------------------------------------------------------
418 
419 
420 void
421 SliceNode::pick( GLState & _state, PickTarget /* _target */ )
422 {
423  _state.pick_set_maximum (1);
424  _state.pick_set_name (0);
425  ACG::GLState::disable(GL_LIGHTING);
426  glPushMatrix();
427  draw_planes();
428  glPopMatrix();
429 }
430 
431 
432 //=============================================================================
433 } // namespace SceneGraph
434 } // namespace ACG
435 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
static void enable(GLenum _cap)
replaces glEnable, but supports locking
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
static void disable(GLenum _cap)
replaces glDisable, but supports locking
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
Definition: SliceNode.cc:103
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
DrawModes::DrawMode availableDrawModes() const
Definition: SliceNode.cc:114
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: MeshNode2T.cc:314
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:77