Debian Codegraph @

avogadro/rendering/cylindergeometry.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_CYLINDERGEOMETRY_H
7 #define AVOGADRO_RENDERING_CYLINDERGEOMETRY_H
8
9 #include "drawable.h"
10
11 #include <vector>
12
13 namespace Avogadro {
14 namespace Rendering {
15
16 struct CylinderColor
17 {
18 CylinderColor(const Vector3f& pos1, const Vector3f& pos2, float r,
19 const Vector3ub& c, const Vector3ub& c2 = Vector3ub::Zero())
20 : end1(pos1), end2(pos2), radius(r), color(c), color2(c2)
21 {
22 }
23
24 Vector3f end1;
25 Vector3f end2;
26 float radius;
27 Vector3ub color;
28 Vector3ub color2;
29 };
30
31 /**
32 * @class CylinderGeometry cylindergeometry.h
33 * <avogadro/rendering/cylindergeometry.h>
34 * @brief The CylinderGeometry contains one or more cylinders.
35 * @author Marcus D. Hanwell
36 */
37
38 class AVOGADRORENDERING_EXPORT CylinderGeometry : public Drawable
39 {
40 public:
41 CylinderGeometry();
42 CylinderGeometry(const CylinderGeometry& other);
43 ~CylinderGeometry() override;
44
45 CylinderGeometry& operator=(CylinderGeometry);
46 friend void swap(CylinderGeometry& lhs, CylinderGeometry& rhs);
47
48 /**
49 * Accept a visit from our friendly visitor.
50 */
51 void accept(Visitor&) override;
52
53 /**
54 * @brief Update the VBOs, IBOs etc ready for rendering.
55 */
56 void update();
57
58 /**
59 * @brief Render the cylinder geometry.
60 * @param camera The current camera to be used for rendering.
61 */
62 void render(const Camera& camera) override;
63
64 /**
65 * Return the primitives that are hit by the ray.
66 * @param rayOrigin Origin of the ray.
67 * @param rayEnd End point of the ray.
68 * @param rayDirection Normalized direction of the ray.
69 * @return Sorted collection of primitives that were hit.
70 */
71 std::multimap<float, Identifier> hits(
72 const Vector3f& rayOrigin, const Vector3f& rayEnd,
73 const Vector3f& rayDirection) const override;
74
75 /**
76 * @brief Add a cylinder to the geometry object.
77 * @param pos1 Base of the cylinder axis.
78 * @param pos2 Top of the cylinder axis.
79 * @param radius Radius of the cylinder.
80 * @param color Color the cylinder will be rendered.
81 */
82 void addCylinder(const Vector3f& pos1, const Vector3f& pos2, float radius,
83 const Vector3ub& color);
84
85 /**
86 * @brief Add a cylinder to the geometry object.
87 * @param pos1 Base of the cylinder axis.
88 * @param pos2 Top of the cylinder axis.
89 * @param radius Radius of the cylinder.
90 * @param color1 Color the start of the base of the cylinder.
91 * @param color2 Color of the end of the cylinder.
92 */
93 void addCylinder(const Vector3f& pos1, const Vector3f& pos2, float radius,
94 const Vector3ub& color1, const Vector3ub& color2);
95
96 /**
97 * @brief Add a cylinder to the geometry object.
98 * @param pos1 Base of the cylinder axis.
99 * @param pos2 Top of the cylinder axis.
100 * @param radius Radius of the cylinder.
101 * @param color Color the cylinder will be rendered.
102 * @param index The index of the cylinder being added.
103 */
104 void addCylinder(const Vector3f& pos1, const Vector3f& pos2, float radius,
105 const Vector3ub& color, size_t index);
106
107 /**
108 * @brief Add a cylinder to the geometry object.
109 * @param pos1 Base of the cylinder axis.
110 * @param pos2 Top of the cylinder axis.
111 * @param radius Radius of the cylinder.
112 * @param color Color the start of the base of the cylinder.
113 * @param color2 Color of the end of the cylinder.
114 * @param index The index of the cylinder being added.
115 */
116 void addCylinder(const Vector3f& pos1, const Vector3f& pos2, float radius,
117 const Vector3ub& color, const Vector3ub& color2,
118 size_t index);
119
120 /**
121 * Get a reference to the cylinders.
122 */
123 std::vector<CylinderColor>& cylinders() { return m_cylinders; }
124 const std::vector<CylinderColor>& cylinders() const { return m_cylinders; }
125
126 /**
127 * Clear the contents of the node.
128 */
129 void clear() override;
130
131 /**
132 * Get the number of cylinders in the node object.
133 */
134 size_t size() const { return m_cylinders.size(); }
135
136 /**
137 * Set the opacity of the cylinders in this group.
138 */
139 void setOpacity(float o)
140 {
141 m_opacity = o;
142 if (o < 1.0f)
143 setRenderPass(TranslucentPass);
144 }
145
146 private:
147 std::vector<CylinderColor> m_cylinders;
148 std::vector<size_t> m_indices;
149 std::map<size_t, size_t> m_indexMap;
150 float m_opacity = 1.0f;
151
152 bool m_dirty;
153
154 class Private;
155 Private* d;
156 };
157
158 inline CylinderGeometry& CylinderGeometry::operator=(CylinderGeometry other)
159 {
160 using std::swap;
161 swap(*this, other);
162 return *this;
163 }
164
165 inline void swap(CylinderGeometry& lhs, CylinderGeometry& rhs)
166 {
167 using std::swap;
168 swap(static_cast<Drawable&>(lhs), static_cast<Drawable&>(rhs));
169 swap(lhs.m_cylinders, rhs.m_cylinders);
170 swap(lhs.m_indices, rhs.m_indices);
171 swap(lhs.m_indexMap, rhs.m_indexMap);
172 lhs.m_dirty = rhs.m_dirty = true;
173 }
174
175 } // End namespace Rendering
176 } // End namespace Avogadro
177
178 #endif // AVOGADRO_RENDERING_CYLINDERGEOMETRY_H