Developer Documentation
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS LineNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_LINENODE_HH
61 #define ACG_LINENODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 #include <ACG/Scenegraph/MaterialNode.hh>
67 #include "DrawModes.hh"
68 #include <ACG/GL/VertexDeclaration.hh>
69 #include <vector>
70 #include <limits>
71 
72 //== NAMESPACES ===============================================================
73 
74 namespace ACG {
75 namespace SceneGraph {
76 
77 //== CLASS DEFINITION =========================================================
78 
79 
80 
90 class ACGDLLEXPORT LineNode : public MaterialNode
91 {
92 public:
93 
94  // typedefs
95  typedef ACG::Vec3uc Color;
96  typedef ACG::Vec4f Color4f;
97  typedef std::vector<Vec3d> PointVector;
98  typedef PointVector::iterator PointIter;
99  typedef PointVector::const_iterator ConstPointIter;
100  typedef std::vector<ACG::Vec3uc> ColorVector;
101  typedef ColorVector::iterator ColorIter;
102  typedef ColorVector::const_iterator ConstColorIter;
103  typedef std::vector<Color4f> Color4fVector;
104  typedef Color4fVector::iterator Color4fIter;
105  typedef Color4fVector::const_iterator ConstColor4fIter;
106 
108  enum LineMode { LineSegmentsMode, PolygonMode };
109 
110 
111 
113  LineNode( LineMode _mode,
114  BaseNode* _parent=0,
115  std::string _name="<LineNode>" );
116 
118  ~LineNode();
119 
121  void set_line_mode(LineMode _mode);
122 
123 
125  ACG_CLASSNAME(LineNode);
126 
128  DrawModes::DrawMode availableDrawModes() const;
129 
131  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
132 
133 
135  void enter(GLState& _state, const DrawModes::DrawMode& _drawMode);
136 
138  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
139 
141  void leave(GLState& _state, const DrawModes::DrawMode& _drawMode);
142 
144  void pick(GLState& _state , PickTarget _target);
145 
147  void reserve_lines(unsigned int _n) { points_.reserve(2*_n); }
148 
150  void reserve_points(unsigned int _n) { points_.reserve(_n); }
151 
153  void clear();
154 
156  void clear_points();
157 
159  void clear_colors();
160 
162  void set_color(const Vec4f& _c);
163 
165  void add_point(const Vec3d& _v);
166 
168  void add_line(const Vec3d& _v0, const Vec3d& _v1);
169 
171  void add_color(const ACG::Vec3uc& _c);
172 
174  void add_color(const Color4f _c);
175 
177  void set_picking_line_width(float _width) { picking_line_width_ = _width; }
179  float picking_line_width() const
180  {
181  return (picking_line_width_ != std::numeric_limits<float>::infinity()) ? picking_line_width_ : line_width();
182  }
183 
185  size_t n_points() const { return points_.size(); }
186 
192  const PointVector& points() const { return points_; }
193 
199  ColorVector& colors() { return colors_; }
200 
202  bool& alwaysOnTop() { updateVBO_ = true; return draw_always_on_top; }
203 
204  void updateVBO() { updateVBO_ = true; };
205 
207  void push_back(const Vec3d& _v) { points_.push_back(_v); updateVBO_ = true; }
208  typedef Vec3d value_type;
209  typedef Vec3d& reference;
210  typedef const Vec3d& const_reference;
211 
219  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
220 
221 protected:
222 
223  void pick_vertices(GLState& _state);
224  void pick_edges (GLState& _state, unsigned int _offset);
225 
227  void createVBO();
228 
232 
233  PointVector points_;
234  ColorVector colors_;
235  Color4fVector colors4f_;
236 
237  LineMode line_mode_;
238 
239  bool draw_always_on_top;
240  GLint prev_depth_;
241 
242  // Vertex buffer object used in this node
243  unsigned int vbo_;
244 
245  // True if points changed and the vbo has to be updated
246  bool updateVBO_;
247 
248  ACG::VertexDeclaration vertexDecl_;
249 
250  std::string lineNodeName_;
251 
252 };
253 
254 
255 //=============================================================================
256 } // namespace SceneGraph
257 } // namespace ACG
258 //=============================================================================
259 #endif // ACG_LINENODE_HH defined
260 //=============================================================================
261 
Class to define the vertex input layout.
Definition: MeshNode2T.cc:266
bool & alwaysOnTop()
get and set always on top
Definition: LineNode.hh:202
size_t n_points() const
number of points
Definition: LineNode.hh:185
void set_picking_line_width(float _width)
set line width used by the picking renderer
Definition: LineNode.hh:177
void reserve_points(unsigned int _n)
reserve mem for _n points
Definition: LineNode.hh:150
const PointVector & points() const
return reference to point vector
Definition: LineNode.hh:192
void reserve_lines(unsigned int _n)
reserve mem for _n lines
Definition: LineNode.hh:147
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
ColorVector & colors()
get and set color container
Definition: LineNode.hh:199
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
LineMode
Line mode: draw line segments (every 2 points) or ONE polyline.
Definition: LineNode.hh:108
void push_back(const Vec3d &_v)
STL conformance.
Definition: LineNode.hh:207
float picking_line_width() const
get line width used by the picking renderer. Defaults to line_width().
Definition: LineNode.hh:179