Developer Documentation

QuadNode.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 QuadNode - IMPLEMENTATION
50 //
51 //=============================================================================
52
53
54 //== INCLUDES =================================================================
55
56
57 #include "QuadNode.hh"
58
59
60 //== NAMESPACES ==============================================================
61
62
63 namespace ACG {
64 namespace SceneGraph {
65
66
67 //== IMPLEMENTATION ==========================================================
68
69
70 QuadNode::QuadNode( BaseNode* _parent,
71 const std::string& _name )
72 : BaseNode(_parent, _name)
73 {
74 }
75
76
77 //----------------------------------------------------------------------------
78
79
80 QuadNode::~QuadNode()
81 {
82 }
83
84
85 //----------------------------------------------------------------------------
86
87
88 void
89 QuadNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
90 {
91 Vec3f bbMin(FLT_MAX,FLT_MAX,FLT_MAX);
92 Vec3f bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
93
94 PointVector::const_iterator p_it = point_.begin(), p_end = point_.end();
95
96 for ( ; p_it != p_end; ++p_it )
97 {
98 bbMin.minimize( *p_it );
99 bbMax.maximize( *p_it );
100 }
101
102 Vec3d bbMind = ACG::Vec3d(bbMin);
103 Vec3d bbMaxd = ACG::Vec3d(bbMax);
104
105 _bbMin.minimize(bbMind);
106 _bbMax.maximize(bbMaxd);
107 }
108
109
110 //----------------------------------------------------------------------------
111
112
113 DrawModes::DrawMode
114 QuadNode::
115 availableDrawModes() const
116 {
117 DrawModes::DrawMode drawModes(DrawModes::NONE);
118
119 drawModes |= DrawModes::WIREFRAME;
120 drawModes |= DrawModes::HIDDENLINE;
121 drawModes |= DrawModes::SOLID_FLAT_SHADED;
122 // drawModes |= DrawModes::SOLID_FACES_COLORED;
123
124 return drawModes;
125 }
126
127
128 //----------------------------------------------------------------------------
129
130
131 void
132 QuadNode::
133 draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode)
134 {
135 if (_drawMode & DrawModes::WIREFRAME ||
136 _drawMode & DrawModes::HIDDENLINE )
137 {
138 ACG::GLState::disable(GL_LIGHTING);
139 ACG::GLState::shadeModel(GL_FLAT);
140 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
141 draw_wireframe();
142 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
143 }
144
145
146 if (_drawMode & DrawModes::SOLID_FLAT_SHADED ||
147 _drawMode & DrawModes::HIDDENLINE )
148 {
149 ACG::GLState::enable(GL_LIGHTING);
150 ACG::GLState::shadeModel(GL_FLAT);
151 ACG::GLState::depthRange(0.01, 1.0);
152 draw_faces();
153 ACG::GLState::depthRange(0.0, 1.0);
154 }
155
156 if (_drawMode & DrawModes::SOLID_FACES_COLORED)
157 {
158 ACG::GLState::disable(GL_LIGHTING);
159 ACG::GLState::shadeModel(GL_FLAT);
160 ACG::GLState::depthRange(0.01, 1.0);
161 draw_faces();
162 ACG::GLState::depthRange(0.0, 1.0);
163 }
164 }
165
166
167 //----------------------------------------------------------------------------
168
169
170 void
171 QuadNode::
172 draw_vertices()
173 {
174 // glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
175 }
176
177
178 //----------------------------------------------------------------------------
179
180
181 void
182 QuadNode::draw_faces()
183 {
184 glBegin(GL_QUADS);
185
186 unsigned int i = 0;
187 unsigned int j = 0;
188
189 for ( ; i < point_.size(); i += 4, j += 1 )
190 {
191 glNormal( normal_[j] );
192
193 glVertex( point_[i + 0] );
194 glVertex( point_[i + 1] );
195 glVertex( point_[i + 2] );
196 glVertex( point_[i + 3] );
197 }
198
199 glEnd();
200 }
201
202
203 //----------------------------------------------------------------------------
204
205
206 void
207 QuadNode::draw_wireframe()
208 {
209 glBegin(GL_QUADS);
210 for ( unsigned int i = 0; i < point_.size(); ++i )
211 glVertex( point_[i] );
212 glEnd();
213 }
214
215
216 //----------------------------------------------------------------------------
217
218
219 void
220 QuadNode::pick( GLState & _state, PickTarget /* _target */ )
221 {
222 _state.pick_set_maximum (1);
223 _state.pick_set_name (0);
224 draw_faces();
225 }
226
227
228 //----------------------------------------------------------------------------
229
230 //=============================================================================
231 } // namespace SceneGraph
232 } // namespace ACG
233 //=============================================================================
ACG::glNormal
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
Definition: gl.hh:135
ACG::GLState
Definition: GLState.hh:213
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::SceneGraph::ACG::GLState::disable
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::DrawModes::HIDDENLINE
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
Definition: DrawModes.cc:80
OpenMesh::VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:568
ACG::SceneGraph::QuadNode::boundingBox
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
Definition: QuadNode.cc:89
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
ACG::GLState::pick_set_maximum
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
Definition: GLState.cc:1051
OpenMesh::VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:540
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
ACG::glVertex
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
Definition: gl.hh:95
ACG::SceneGraph::DrawModes::NONE
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
ACG::SceneGraph::QuadNode::availableDrawModes
DrawModes::DrawMode availableDrawModes() const override
Definition: QuadNode.cc:115
ACG::SceneGraph::DrawModes::WIREFRAME
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:84
ACG::GLState::pick_set_name
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1061
ACG::SceneGraph::ACG::GLState::enable
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
ACG::SceneGraph::ACG::GLState::depthRange
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
ACG::SceneGraph::ACG::GLState::shadeModel
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121