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