Developer Documentation

TriangleNode.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 // CLASS TriangleNode - IMPLEMENTATION
49 //
50 //=============================================================================
51
52
53 //== INCLUDES =================================================================
54
55
56 #include "TriangleNode.hh"
57
58
59 //== NAMESPACES ==============================================================
60
61
62 namespace ACG {
63 namespace SceneGraph {
64
65
66 //== IMPLEMENTATION ==========================================================
67
68
69 TriangleNode::TriangleNode( BaseNode* _parent,
70 const std::string& _name )
71 : BaseNode(_parent, _name)
72 {
73 }
74
75
76 //----------------------------------------------------------------------------
77
78
79 TriangleNode::~TriangleNode()
80 {
81 }
82
83
84 //----------------------------------------------------------------------------
85
86
87 void
88 TriangleNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
89 {
90 Vec3f bbMin(FLT_MAX,FLT_MAX,FLT_MAX);
91 Vec3f bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
92
93 PointVector::const_iterator p_it = point_.begin(),
94 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 TriangleNode::
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 TriangleNode::
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 TriangleNode::
172 draw_vertices()
173 {
174 // glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
175 }
176
177
178 //----------------------------------------------------------------------------
179
180
181 void
182 TriangleNode::draw_faces()
183 {
184 glBegin(GL_TRIANGLES);
185
186 unsigned int i = 0;
187 unsigned int j = 0;
188
189 for ( ; i < point_.size(); i += 3, j += 1 )
190 {
191 glNormal( normal_[j] );
192
193 glVertex( point_[i + 0] );
194 glVertex( point_[i + 1] );
195 glVertex( point_[i + 2] );
196 }
197
198 glEnd();
199 }
200
201
202 //----------------------------------------------------------------------------
203
204
205 void
206 TriangleNode::draw_wireframe()
207 {
208 glBegin(GL_TRIANGLES);
209 for ( unsigned int i = 0; i < point_.size(); ++i )
210 glVertex( point_[i] );
211 glEnd();
212 }
213
214
215 //----------------------------------------------------------------------------
216
217
218 void
219 TriangleNode::pick( GLState & _state, PickTarget /* _target */ )
220 {
221 _state.pick_set_maximum (1);
222 _state.pick_set_name (0);
223 draw_faces();
224 }
225
226
227 //----------------------------------------------------------------------------
228
229 //=============================================================================
230 } // namespace SceneGraph
231 } // namespace ACG
232 //=============================================================================
OpenMesh::VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:563
ACG::SceneGraph::DrawModes::WIREFRAME
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::SceneGraph::TriangleNode::availableDrawModes
DrawModes::DrawMode availableDrawModes() const
Definition: TriangleNode.cc:115
ACG::SceneGraph::ACG::GLState::enable
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
ACG::SceneGraph::TriangleNode::boundingBox
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
Definition: TriangleNode.cc:88
ACG::SceneGraph::ACG::GLState::disable
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
ACG::SceneGraph::ACG::GLState::depthRange
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
ACG::glNormal
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
Definition: gl.hh:125
ACG::glVertex
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
Definition: gl.hh:85
ACG::GLState
Definition: GLState.hh:213
ACG::SceneGraph::DrawModes::HIDDENLINE
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
Definition: DrawModes.cc:80
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
ACG::SceneGraph::ACG::GLState::shadeModel
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
ACG::SceneGraph::DrawModes::NONE
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:84
OpenMesh::VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:535
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
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
ACG::GLState::pick_set_name
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1061