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