Developer Documentation
PolyLineNodeT.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 PolyLineNodeT
50 //
51 // Author: David Bommes <bommes@cs.rwth-aachen.de>
52 //
53 //=============================================================================
54 
55 
56 #ifndef ACG_POLYLINENODET_HH
57 #define ACG_POLYLINENODET_HH
58 
59 
60 //== INCLUDES =================================================================
61 
62 #include <ACG/Scenegraph/BaseNode.hh>
63 #include <ACG/Scenegraph/DrawModes.hh>
64 #include <ACG/GL/VertexDeclaration.hh>
65 #include <ACG/GL/IRenderer.hh>
66 #include <ACG/GL/GLPrimitives.hh>
67 #include <ACG/GL/globjects.hh>
68 
69 //== FORWARDDECLARATIONS ======================================================
70 
71 //== NAMESPACES ===============================================================
72 
73 namespace ACG {
74 namespace SceneGraph {
75 
76 //== CLASS DEFINITION =========================================================
77 
78 
79 
80 
88 template <class PolyLine>
89 class PolyLineNodeT : public BaseNode
90 {
91 public:
92 
93  // typedefs for easy access
94  typedef typename PolyLine::Point Point;
95 
97  PolyLineNodeT(PolyLine& _pl, BaseNode* _parent = 0, std::string _name = "<PolyLineNode>");
98 
100  ~PolyLineNodeT();
101 
102  PolyLine& polyline() { return polyline_; }
103 
106 
109 
111  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
112 
114  void draw(GLState& /*_state*/,const DrawModes::DrawMode& _drawMode);
115 
117  void pick(GLState& _state, PickTarget _target);
118 
126  void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
127 
129  void update() { updateVBO_ = true; };
130 
131 
164  int addCustomBuffer(const ACG::VertexElement& _desc, const void* _buffer);
165 
166 
172  void setCustomBuffer(int _id, const void* _buffer);
173 
174 
175 
184  void setupVertexDeclaration(VertexDeclaration* _dst, int _colorSource) const;
185 
186 
199  size_t fillVertexBuffer(void* _buf, size_t _bufSize, bool _addLineStripEndVertex);
200 
201 private:
202 
203  void pick_vertices ( GLState& _state );
204  void pick_spheres ( GLState& _state );
205  void pick_spheres_screen ( GLState& _state );
206  void pick_edges ( GLState& _state, unsigned int _offset);
207 
209  PolyLineNodeT(const PolyLineNodeT& _rhs);
210 
212  PolyLineNodeT& operator=(const PolyLineNodeT& _rhs);
213 
216 
219 
222 
224  std::vector< std::pair<ACG::VertexElement, const void*> > customBuffers_;
225 
227  std::map< typename PolyLine::CustomPropertyHandle, int> polylinePropMap_;
228 
234  void updateVBO();
235 
241  void writeVertex(unsigned int _vertex, void* _dst);
242 
249  void writeVertexColor(unsigned int _vertex, bool _colorSourceVertex, void* _dst) const;
250 
251 private:
252 
255 
257  GeometryBuffer vbo_;
258 
260  std::vector<unsigned int> selectedVertexIndexBuffer_;
261 
263  std::vector<unsigned int> selectedEdgeIndexBuffer_;
264 
267 
270 
273 
276 };
277 
278 
279 //=============================================================================
280 } // namespace SceneGraph
281 } // namespace ACG
282 //=============================================================================
283 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_POLYLINENODET_C)
284 #define ACG_POLYLINENODET_TEMPLATES
285 #include "PolyLineNodeT_impl.hh"
286 #endif
287 //=============================================================================
288 #endif // ACG_POLYLINENODET_HH defined
289 //=============================================================================
290 
void update()
Trigger an update of the vbo.
std::vector< unsigned int > selectedVertexIndexBuffer_
Index buffer for selected vertices.
Namespace providing different geometric functions concerning angles.
Class to define the vertex input layout.
void updateVBO()
Trigger an update of the vbo.
void writeVertexColor(unsigned int _vertex, bool _colorSourceVertex, void *_dst) const
Write color for rendering to a buffer.
GeometryBuffer vbo_
VBO used to render the poly line.
int addCustomBuffer(const ACG::VertexElement &_desc, const void *_buffer)
DrawModes::DrawMode availableDrawModes() const
return available draw modes
PolyLine & polyline_
The associated poly line.
void writeVertex(unsigned int _vertex, void *_dst)
Write vertex data for rendering to a buffer.
void setCustomBuffer(int _id, const void *_buffer)
std::map< typename PolyLine::CustomPropertyHandle, int > polylinePropMap_
Map from custom properties in PolyLine to id in customBuffers_.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void pick(GLState &_state, PickTarget _target)
picking
void draw(GLState &, const DrawModes::DrawMode &_drawMode)
draw lines and normals
void setupVertexDeclaration(VertexDeclaration *_dst, int _colorSource) const
Create the vertex declaration.
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
DrawModes::DrawMode POINTS_SPHERES_SCREEN
This defines a local point spheres draw mode for all polyLine nodes with constant screen size...
GLSphere * sphere_
Sphere for VertexSphere DrawMode.
Description of one vertex element.
std::vector< std::pair< ACG::VertexElement, const void * > > customBuffers_
Custom vertex data for shader based rendering.
std::vector< unsigned int > selectedEdgeIndexBuffer_
Index buffer for selected edges.
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
size_t fillVertexBuffer(void *_buf, size_t _bufSize, bool _addLineStripEndVertex)
Fill a buffer with vertex data.
bool updateVBO_
Flag to trigger update of vbo.
ACG::VertexDeclaration vertexDecl_
Vertex layout without vertex colors.
PolyLineNodeT(PolyLine &_pl, BaseNode *_parent=0, std::string _name="<PolyLineNode>")
Constructor.
PolyLineNodeT & operator=(const PolyLineNodeT &_rhs)
Assignment operator (not used)
ACG_CLASSNAME(PolyLineNodeT)
static name of this class
DrawModes::DrawMode POINTS_SPHERES
This defines a local point spheres draw mode for all polyLine nodes.
ACG::VertexDeclaration vertexDeclECol_
Vertex layout with edge colors.
ACG::VertexDeclaration vertexDeclVCol_
Vertex layout with vertex colors.