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