Debian Codegraph @

avogadro/rendering/ambientocclusionspheregeometry.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_AMBIENTOCCLUSIONSPHEREGEOMETRY_H
7 #define AVOGADRO_RENDERING_AMBIENTOCCLUSIONSPHEREGEOMETRY_H
8
9 #include "drawable.h"
10
11 #include <avogadro/core/array.h>
12 #include <avogadro/core/vector.h>
13 #include <avogadro/rendering/spheregeometry.h>
14
15 namespace Avogadro {
16 namespace Rendering {
17
18 /**
19 * @class AmbientOcclusionSphereGeometry ambientocclusionspheregeometry.h
20 * <avogadro/rendering/ambientocclusionspheregeometry.h>
21 * @brief The AmbientOcclusionSphereGeometry class contains one or more spheres.
22 * @author Tim Vandermeersch
23 *
24 * This Drawable is capable of storing the geometry for one or more spheres.
25 * A sphere is defined by a center point, a radius and a color. If the
26 * spheres are not a densely packed one-to-one mapping with the objects indices
27 * they can also optionally use an identifier that will point to some numeric
28 * ID for the purposes of picking.
29 *
30 * Unlike the SphereGeometry class, this class also supports ambient occlusion.
31 */
32
33 class AVOGADRORENDERING_EXPORT AmbientOcclusionSphereGeometry : public Drawable
34 {
35 public:
36 AmbientOcclusionSphereGeometry();
37 AmbientOcclusionSphereGeometry(const AmbientOcclusionSphereGeometry& other);
38 ~AmbientOcclusionSphereGeometry() override;
39
40 AmbientOcclusionSphereGeometry& operator=(AmbientOcclusionSphereGeometry);
41 friend void swap(AmbientOcclusionSphereGeometry& lhs,
42 AmbientOcclusionSphereGeometry& rhs);
43
44 /**
45 * Accept a visit from our friendly visitor.
46 */
47 void accept(Visitor&) override;
48
49 /**
50 * @brief Update the VBOs, IBOs etc ready for rendering.
51 */
52 void update();
53
54 /**
55 * @brief Render the sphere geometry.
56 * @param camera The current camera to be used for rendering.
57 */
58 void render(const Camera& camera) override;
59
60 /**
61 * Return the primitives that are hit by the ray.
62 * @param rayOrigin Origin of the ray.
63 * @param rayEnd End point of the ray.
64 * @param rayDirection Normalized direction of the ray.
65 * @return Sorted collection of primitives that were hit.
66 */
67 std::multimap<float, Identifier> hits(
68 const Vector3f& rayOrigin, const Vector3f& rayEnd,
69 const Vector3f& rayDirection) const override;
70
71 /**
72 * Add a sphere to the geometry object.
73 */
74 void addSphere(const Vector3f& position, const Vector3ub& color, float radius,
75 size_t index = MaxIndex);
76
77 /**
78 * Get a reference to the spheres.
79 */
80 Core::Array<SphereColor>& spheres() { return m_spheres; }
81 const Core::Array<SphereColor>& spheres() const { return m_spheres; }
82
83 /**
84 * Clear the contents of the node.
85 */
86 void clear() override;
87
88 /**
89 * Get the number of spheres in the node object.
90 */
91 size_t size() const { return m_spheres.size(); }
92
93 private:
94 Core::Array<SphereColor> m_spheres;
95 Core::Array<size_t> m_indices;
96
97 bool m_dirty;
98
99 class Private;
100 Private* d;
101 };
102
103 inline AmbientOcclusionSphereGeometry&
104 AmbientOcclusionSphereGeometry::operator=(AmbientOcclusionSphereGeometry other)
105 {
106 using std::swap;
107 swap(*this, other);
108 return *this;
109 }
110
111 inline void swap(AmbientOcclusionSphereGeometry& lhs,
112 AmbientOcclusionSphereGeometry& rhs)
113 {
114 using std::swap;
115 swap(static_cast<Drawable&>(lhs), static_cast<Drawable&>(rhs));
116 swap(lhs.m_spheres, rhs.m_spheres);
117 swap(lhs.m_indices, rhs.m_indices);
118 lhs.m_dirty = rhs.m_dirty = true;
119 }
120
121 } // End namespace Rendering
122 } // End namespace Avogadro
123
124 #endif // AVOGADRO_RENDERING_AMBIENTOCCLUSIONSPHEREGEOMETRY_H