Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ClippingNode.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 ClippingNode - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 
60 //== INCLUDES =================================================================
61 
62 
63 #include "ClippingNode.hh"
64 
65 #include <QImage>
66 
67 
68 //== NAMESPACES ===============================================================
69 
70 
71 namespace ACG {
72 namespace SceneGraph {
73 
74 
75 //== IMPLEMENTATION ==========================================================
76 
77 
78 void
79 ClippingNode::set_plane(const Vec3f& _position,
80  const Vec3f& _normal,
81  float _eps)
82 {
83  position_ = _position;
84  normal_ = _normal; normal_.normalize();
85  slice_width_ = _eps;
86 
87 
88  // one clipping plane
89  if (slice_width_ == 0.0)
90  {
91  plane0_[0] = normal_[0];
92  plane0_[1] = normal_[1];
93  plane0_[2] = normal_[2];
94  plane0_[3] = -(normal_|position_);
95  }
96 
97 
98  // two planes -> slice
99  else
100  {
101  float d = -(normal_|position_);
102  if (d > 0) { normal_ = -normal_; d = -d; }
103 
104  plane0_[0] = normal_[0];
105  plane0_[1] = normal_[1];
106  plane0_[2] = normal_[2];
107  plane0_[3] = d + 0.5f*slice_width_;
108 
109  plane1_[0] = -normal_[0];
110  plane1_[1] = -normal_[1];
111  plane1_[2] = -normal_[2];
112  plane1_[3] = -(d - 0.5f*slice_width_);
113  }
114 
115 
116  set_offset(offset_);
117 }
118 
119 
120 //----------------------------------------------------------------------------
121 
122 
123 void
125 {
126  offset_ = _offset;
127 
128  offset_plane0_[0] = plane0_[0];
129  offset_plane0_[1] = plane0_[1];
130  offset_plane0_[2] = plane0_[2];
131  offset_plane0_[3] = plane0_[3] - offset_;
132 
133  offset_plane1_[0] = plane1_[0];
134  offset_plane1_[1] = plane1_[1];
135  offset_plane1_[2] = plane1_[2];
136  offset_plane1_[3] = plane1_[3] + offset_;
137 }
138 
139 
140 //----------------------------------------------------------------------------
141 
142 
143 void ClippingNode::enter(GLState& /* _state */ , const DrawModes::DrawMode& /* _drawmode */ )
144 {
145  // one clipping plane
146  if (slice_width_ == 0.0)
147  {
148  glClipPlane(GL_CLIP_PLANE0, offset_plane0_);
149  ACG::GLState::enable(GL_CLIP_PLANE0);
150  }
151 
152 
153  // two planes -> slice
154  else
155  {
156  glClipPlane(GL_CLIP_PLANE0, offset_plane0_);
157  ACG::GLState::enable(GL_CLIP_PLANE0);
158  glClipPlane(GL_CLIP_PLANE1, offset_plane1_);
159  ACG::GLState::enable(GL_CLIP_PLANE1);
160  }
161 }
162 
163 
164 //----------------------------------------------------------------------------
165 
166 
167 void ClippingNode::leave(GLState& /* _state */ , const DrawModes::DrawMode& /* _drawmode */ )
168 {
169  ACG::GLState::disable(GL_CLIP_PLANE0);
170  if (slice_width_ > 0.0)
171  ACG::GLState::disable(GL_CLIP_PLANE1);
172 }
173 
174 
175 //=============================================================================
176 } // namespace SceneGraph
177 } // namespace ACG
178 //=============================================================================
void set_plane(const Vec3f &_position, const Vec3f &_normal, float _eps=0.0)
set position and normal of plane
Definition: ClippingNode.cc:79
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
static void enable(GLenum _cap)
replaces glEnable, but supports locking
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set texture
void set_offset(float _dist)
sweep plane along normal by _dist
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restores original texture (or no-texture)