Debian Codegraph @

avogadro/rendering/arrowgeometry.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_RENDERING_ARROWGEOMETRY_H
7 #define AVOGADRO_RENDERING_ARROWGEOMETRY_H
8
9 #include "drawable.h"
10
11 #include <avogadro/core/array.h>
12
13 namespace Avogadro {
14 namespace Rendering {
15
16 /**
17 * @class ArrowGeometry arrowgeometry.h
18 * <avogadro/rendering/arrowgeometry.h>
19 * @brief The ArrowGeometry class is used to store sets of line strips.
20 */
21
22 class AVOGADRORENDERING_EXPORT ArrowGeometry : public Drawable
23 {
24 public:
25 /** Data for a single arrow. */
26 struct Arrow
27 {
28 Vector3f start;
29 Vector3f end;
30 Vector3ub color;
31
32 Arrow(const Vector3f& s, const Vector3f& e, const Vector3ub& c)
33 : start(s), end(e), color(c)
34 {
35 }
36 };
37
38 static const size_t InvalidIndex;
39
40 ArrowGeometry();
41 ArrowGeometry(const ArrowGeometry& other);
42 ~ArrowGeometry() override;
43
44 ArrowGeometry& operator=(ArrowGeometry);
45 friend void swap(ArrowGeometry& lhs, ArrowGeometry& rhs);
46
47 /**
48 * Accept a visit from our friendly visitor.
49 */
50 void accept(Visitor&) override;
51
52 /**
53 * @brief Render the arrows.
54 * @param camera The current camera to be used for rendering.
55 */
56 void render(const Camera& camera) override;
57
58 /**
59 * Clear the contents of the node.
60 */
61 void clear() override;
62
63 /**
64 * Add a single arrow object with a specific color.
65 * @param pos1 The start coordinate of the arrow.
66 * @param pos2 The end coordinate of the arrow.
67 * @param color The color of this arrow.
68 */
69 void addSingleArrow(const Vector3f& pos1, const Vector3f& pos2,
70 const Vector3ub& color);
71
72 /**
73 * Add a single arrow object using the default color.
74 * @param pos1 The start coordinate of the arrow.
75 * @param pos2 The end coordinate of the arrow.
76 */
77 void addSingleArrow(const Vector3f& pos1, const Vector3f& pos2);
78
79 /** The arrow array. */
80 const Core::Array<Arrow>& arrows() const { return m_arrows; }
81
82 /** Set the default color for arrows added without explicit color. */
83 void setColor(const Vector3ub& c) { m_color = c; }
84
85 /** Set a scale factor for arrow radii (default 1.0). */
86 void setRadiusScale(float scale)
87 {
88 m_radiusScale = scale;
89 m_dirty = true;
90 }
91
92 /** Get the current radius scale factor. */
93 float radiusScale() const { return m_radiusScale; }
94
95 private:
96 /**
97 * @brief Update the shaders ready for rendering.
98 */
99 void update();
100
101 Core::Array<Arrow> m_arrows;
102 Vector3ub m_color;
103 float m_radiusScale;
104
105 bool m_dirty;
106
107 class Private;
108 Private* d;
109 };
110
111 inline ArrowGeometry& ArrowGeometry::operator=(ArrowGeometry other)
112 {
113 using std::swap;
114 swap(*this, other);
115 return *this;
116 }
117
118 inline void swap(ArrowGeometry& lhs, ArrowGeometry& rhs)
119 {
120 using std::swap;
121 swap(static_cast<Drawable&>(lhs), static_cast<Drawable&>(rhs));
122 swap(lhs.m_arrows, rhs.m_arrows);
123 swap(lhs.m_color, rhs.m_color);
124 swap(lhs.m_radiusScale, rhs.m_radiusScale);
125 lhs.m_dirty = rhs.m_dirty = true;
126 }
127
128 } // End namespace Rendering
129 } // End namespace Avogadro
130
131 #endif // AVOGADRO_RENDERING_ARROWGEOMETRY_H