Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ArrowNode.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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS ArrowNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_ARROWNODE_HH
61 #define ACG_ARROWNODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 #include <ACG/Scenegraph/MaterialNode.hh>
67 #include <ACG/GL/globjects.hh>
68 #include <ACG/GL/VertexDeclaration.hh>
69 
70 //== NAMESPACES ===============================================================
71 
72 namespace ACG {
73 namespace SceneGraph {
74 
75 //== CLASS DEFINITION =========================================================
76 
77 
78 
84 class ACGDLLEXPORT ArrowNode : public MaterialNode
85 {
86 public:
87 
89  ArrowNode(BaseNode* _parent = 0,
90  std::string _name="<ArrowNode>" );
91 
93  ~ArrowNode();
94 
95 
97  ACG_CLASSNAME(ArrowNode);
98 
100  DrawModes::DrawMode availableDrawModes() const;
101 
103  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
104 
106  void reserve(int _n);
107 
117  int addArrow(const Vec3f& _start, const Vec3f& _dir, const Vec3f& _normal = Vec3f(0.0f, 1.0f, 0.0f), const Vec3f& _scale = Vec3f(1.0f, 1.0f, 1.0f), const Vec4uc& _color = Vec4uc(82, 82, 82, 255));
118 
128  int addArrow(const Vec3f& _start, const Vec3f& _dir, const Vec3f& _normal, const Vec3f& _scale, const Vec4f& _color);
129 
139  int addArrow(const Vec3d& _start, const Vec3d& _dir, const Vec3d& _normal = Vec3d(0.0, 1.0, 0.0), const Vec3d& _scale = Vec3d(1.0, 1.0, 1.0), const Vec4uc& _color = Vec4uc(82, 82, 82, 255));
140 
150  int addArrow(const Vec3d& _start, const Vec3d& _dir, const Vec3d& _normal, const Vec3d& _scale, const Vec4f& _color);
151 
157  Vec3f arrowStart(int _arrowID) const;
158 
164  void arrowStart(int _arrowID, const Vec3f& _start);
165 
166 
172  Vec3f arrowDir(int _arrowID) const;
173 
179  void arrowDir(int _arrowID, const Vec3f& _dir);
180 
181 
187  Vec3f arrowNormal(int _arrowID) const;
188 
194  void arrowNormal(int _arrowID, const Vec3f& _normal);
195 
202  Vec3f arrowScale(int _arrowID) const;
203 
210  void arrowScale(int _arrowID, const Vec3f& _scale);
211 
217  Vec4uc arrowColor(int _arrowID) const;
218 
224  void arrowColor(int _arrowID, const Vec4uc& _color);
225 
227  void clear();
228 
230  int n_arrows() const;
231 
233  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
234 
242  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
243 
244 
245 private:
246  void createArrowMesh();
247 
248 
249  GLMatrixf computeWorldMatrix(int _arrow) const;
250  GLMatrixf readWorldMatrix(int _arrow) const;
251  void updateInstanceData();
252 
253  void updateInstanceBuffer();
254 
255  // arrow instances
256 
257  struct Arrow
258  {
259  Vec3f start, dir;
260  Vec3f normal;
261  Vec3f scale; // width, length, height
262  Vec4uc color;
263 
264  void orthonormalize();
265  };
266 
267  std::vector<Arrow> arrows_;
268 
269  // arrow mesh:
270  int numVertices_;
271  int numIndices_;
272  GeometryBuffer vertexBuffer_;
273  IndexBuffer indexBuffer_;
274  VertexDeclaration vertexDecl_;
275  Vec3f localArrowMin_;
276  Vec3f localArrowMax_;
277 
278 
279  // instance data:
280  // float4x3 world transform
281  // ubyte4_norm color
282 
283  // dword offset of the instance data of an arrow ( modify this if more data gets appended )
284  int instanceDataOffset(int _arrow) const {return _arrow * (4*3 + 3*3 +1);}
285 
286  // size in dwords of instance data ( modify this if more data gets appended )
287  int instanceDataSize() const {return 4*3 + 3*3 + 1;}
288 
289 
290  std::vector<float> instanceData_;
291 
292  // instance vbo
293  GeometryBuffer instanceBuffer_;
294  VertexDeclaration vertexDeclInstanced_;
295 
296 
297  bool invalidateInstanceData_;
298  bool invalidateInstanceBuffer_;
299  int supportsInstancing_;
300 };
301 
302 
303 //=============================================================================
304 } // namespace SceneGraph
305 } // namespace ACG
306 //=============================================================================
307 #endif // ACG_ARROWNODE_HH defined
308 //=============================================================================
309 
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
VectorT< unsigned char, 4 > Vec4uc
Definition: VectorT.hh:134
Class to define the vertex input layout.