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
CartesianClippingNode.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 "CartesianClippingNode.hh"
56
57 //=============================================================================
58
59 namespace ACG {
60 namespace SceneGraph {
61
62 //=============================================================================
63
64
65 CartesianClippingNode::CartesianClippingNode( BaseNode* _parent,
66 const std::string& _name )
67 : BaseNode( _parent, _name )
68 {
69 set_cursor( Vec3f( 0, 0, 0 ) );
70 enabled_ = NONE;
71 }
72
73 //-----------------------------------------------------------------------------
74
75
76 void
77 CartesianClippingNode::enter( GLState & _state, const DrawModes::DrawMode& /* _drawmode */ )
78 {
79 Vec3d eye = _state.eye();
80
81 if ( is_enabled( XY_PLANE ) )
82 {
83 GLdouble xy_plane[4];
84 if ( eye[2] > 0 )
85 {
86 xy_plane[0] = 0;
87 xy_plane[1] = 0;
88 xy_plane[2] = -1;
89 xy_plane[3] = cursor_[2];
90 }
91 else
92 {
93 xy_plane[0] = 0;
94 xy_plane[1] = 0;
95 xy_plane[2] = 1;
96 xy_plane[3] = -cursor_[2];
97 }
98
99 glClipPlane( GL_CLIP_PLANE0, xy_plane );
100 ACG::GLState::enable( GL_CLIP_PLANE0 );
101 }
102
103 if ( is_enabled( YZ_PLANE ) )
104 {
105 GLdouble yz_plane[4];
106 if ( eye[0] > 0 )
107 {
108 yz_plane[0] = -1;
109 yz_plane[1] = 0;
110 yz_plane[2] = 0;
111 yz_plane[3] = cursor_[0];
112 }
113 else
114 {
115 yz_plane[0] = 1;
116 yz_plane[1] = 0;
117 yz_plane[2] = 0;
118 yz_plane[3] = -cursor_[0];
119 }
120
121 glClipPlane( GL_CLIP_PLANE1, yz_plane );
122 ACG::GLState::enable( GL_CLIP_PLANE1 );
123 }
124
125 if ( is_enabled( XZ_PLANE ) )
126 {
127 GLdouble xz_plane[4];
128 if ( eye[1] > 0 )
129 {
130 xz_plane[0] = 0;
131 xz_plane[1] = -1;
132 xz_plane[2] = 0;
133 xz_plane[3] = cursor_[1];
134 }
135 else
136 {
137 xz_plane[0] = 0;
138 xz_plane[1] = 1;
139 xz_plane[2] = 0;
140 xz_plane[3] = -cursor_[1];
141 }
142
143 glClipPlane( GL_CLIP_PLANE2, xz_plane );
144 ACG::GLState::enable( GL_CLIP_PLANE2 );
145 }
146
147
148
149 }
150
151
152 //-----------------------------------------------------------------------------
153
154
155 void
156 CartesianClippingNode::leave( GLState & /* _state */ , const DrawModes::DrawMode& /* _drawmode */ )
157 {
158 ACG::GLState::disable( GL_CLIP_PLANE0 );
159 ACG::GLState::disable( GL_CLIP_PLANE1 );
160 ACG::GLState::disable( GL_CLIP_PLANE2 );
161 }
162
163
164 //-----------------------------------------------------------------------------
165
166
167 void
168 CartesianClippingNode::set_cursor( const Vec3f & _cursor )
169 {
170 cursor_ = _cursor;
171
172 }
173
174
175 //-----------------------------------------------------------------------------
176
177
178 const
179 Vec3f &
180 CartesianClippingNode::cursor() const
181 {
182 return cursor_;
183 }
184
185
186 //-----------------------------------------------------------------------------
187
188
189 void
190 CartesianClippingNode::set_enabled( Plane _plane )
191 {
192 enabled_ = _plane;
193 }
194
195
196 //-----------------------------------------------------------------------------
197
198
199 bool
200 CartesianClippingNode::is_enabled( Plane _plane ) const
201 {
202 return ( enabled_ == _plane );
203 }
204
205
206 //=============================================================================
207 } // namespace SceneGraph
208 } // namespace ACG
209 //=============================================================================
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::ACG::GLState::enable
static void enable(GLenum _cap)
replaces glEnable, but supports locking
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
ACG::SceneGraph::ACG::GLState::disable
static void disable(GLenum _cap)
replaces glDisable, but supports locking
ACG::GLState
Definition: GLState.hh:220
ACG::SceneGraph::CartesianClippingNode::leave
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
stop clipping
Definition: CartesianClippingNode.cc:156
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:294
Plane
Definition: PlaneType.hh:77
ACG::SceneGraph::CartesianClippingNode::enter
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
begin clipping
Definition: CartesianClippingNode.cc:77
ACG::SceneGraph::CartesianClippingNode::cursor
const Vec3f & cursor() const
get position
Definition: CartesianClippingNode.cc:180
ACG::Vec3f
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::CartesianClippingNode::set_cursor
void set_cursor(const Vec3f &_pos)
set position
Definition: CartesianClippingNode.cc:168
ACG::GLState::eye
Vec3d eye() const
get eye point
Definition: GLState.cc:882
ACG::SceneGraph::DrawModes::NONE
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:77