Developer Documentation
Loading...
Searching...
No Matches
LineNode.hh
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 LineNode
50//
51//=============================================================================
52
53
54#ifndef ACG_LINENODE_HH
55#define ACG_LINENODE_HH
56
57
58//== INCLUDES =================================================================
59
60#include <ACG/Scenegraph/MaterialNode.hh>
61#include "DrawModes.hh"
62#include <ACG/GL/VertexDeclaration.hh>
63#include <vector>
64#include <limits>
65
66//== NAMESPACES ===============================================================
67
68namespace ACG {
69namespace SceneGraph {
70
71//== CLASS DEFINITION =========================================================
72
73
74
84class ACGDLLEXPORT LineNode : public MaterialNode
85{
86public:
87
88 // typedefs
89 typedef ACG::Vec3uc Color;
90 typedef ACG::Vec4f Color4f;
91 typedef std::vector<Vec3d> PointVector;
92 typedef PointVector::iterator PointIter;
93 typedef PointVector::const_iterator ConstPointIter;
94 typedef std::vector<ACG::Vec3uc> ColorVector;
95 typedef ColorVector::iterator ColorIter;
96 typedef ColorVector::const_iterator ConstColorIter;
97 typedef std::vector<Color4f> Color4fVector;
98 typedef Color4fVector::iterator Color4fIter;
99 typedef Color4fVector::const_iterator ConstColor4fIter;
100
102 enum LineMode { LineSegmentsMode, PolygonMode };
103
104
105
107 LineNode( LineMode _mode,
108 BaseNode* _parent=0,
109 std::string _name="<LineNode>" );
110
112 ~LineNode();
113
115 void set_line_mode(LineMode _mode);
116
117
120
122 DrawModes::DrawMode availableDrawModes() const override;
123
125 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
126
127
129 void enter(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
130
132 void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
133 void drawCompat(GLState& _state, const DrawModes::DrawMode& _drawMode);
134
136 void leave(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
137
139 void pick(GLState& _state , PickTarget _target) override;
140 void pickCompat(GLState& _state , PickTarget _target);
141
143 void reserve_lines(unsigned int _n) { points_.reserve(2*_n); }
144
146 void reserve_points(unsigned int _n) { points_.reserve(_n); }
147
149 void clear();
150
152 void clear_points();
153
155 void clear_colors();
156
158 void set_color(const Vec4f& _c);
159
161 void add_point(const Vec3d& _v);
162
164 void add_line(const Vec3d& _v0, const Vec3d& _v1);
165
167 void add_color(const ACG::Vec3uc& _c);
168
170 void add_color(const Color4f _c);
171
173 void set_picking_line_width(float _width) { picking_line_width_ = _width; }
175 float picking_line_width() const
176 {
177 return (picking_line_width_ != std::numeric_limits<float>::infinity()) ? picking_line_width_ : line_width();
178 }
179
181 size_t n_points() const { return points_.size(); }
182
188 const PointVector& points() const { return points_; }
189
195 ColorVector& colors() { return colors_; }
196
198 bool& alwaysOnTop() { updateVBO_ = true; return draw_always_on_top; }
199
200 void updateVBO() { updateVBO_ = true; };
201
203 void push_back(const Vec3d& _v) { points_.push_back(_v); updateVBO_ = true; }
204 typedef Vec3d value_type;
205 typedef Vec3d& reference;
206 typedef const Vec3d& const_reference;
207
215 void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) override;
216
217protected:
218
219 void pick_vertices(GLState& _state);
220 void pick_edges (GLState& _state, unsigned int _offset);
221 void pick_edgesCompat (GLState& _state, unsigned int _offset);
222
224 void createVBO();
225
229
230 PointVector points_;
231 ColorVector colors_;
232 Color4fVector colors4f_;
233
234 LineMode line_mode_;
235
236 bool draw_always_on_top;
237 GLint prev_depth_;
238
239 // Vertex buffer object used in this node
240 unsigned int vbo_;
241
242 // True if points changed and the vbo has to be updated
243 bool updateVBO_;
244
245 ACG::VertexDeclaration vertexDecl_;
246
247 std::string lineNodeName_;
248
249};
250
251
252//=============================================================================
253} // namespace SceneGraph
254} // namespace ACG
255//=============================================================================
256#endif // ACG_LINENODE_HH defined
257//=============================================================================
258
float picking_line_width() const
get line width used by the picking renderer. Defaults to line_width().
Definition LineNode.hh:175
LineMode
Line mode: draw line segments (every 2 points) or ONE polyline.
Definition LineNode.hh:102
void set_picking_line_width(float _width)
set line width used by the picking renderer
Definition LineNode.hh:173
void reserve_points(unsigned int _n)
reserve mem for _n points
Definition LineNode.hh:146
bool & alwaysOnTop()
get and set always on top
Definition LineNode.hh:198
void push_back(const Vec3d &_v)
STL conformance.
Definition LineNode.hh:203
ACG_CLASSNAME(LineNode)
static name of this class
void reserve_lines(unsigned int _n)
reserve mem for _n lines
Definition LineNode.hh:143
ColorVector & colors()
get and set color container
Definition LineNode.hh:195
size_t n_points() const
number of points
Definition LineNode.hh:181
const PointVector & points() const
return reference to point vector
Definition LineNode.hh:188
Class to define the vertex input layout.
PickTarget
What target to use for picking.
Definition PickTarget.hh:74
Namespace providing different geometric functions concerning angles.