Debian Codegraph @

avogadro/rendering/geometrynode.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_GEOMETRYNODE_H
7 #define AVOGADRO_RENDERING_GEOMETRYNODE_H
8
9 #include "node.h"
10
11 #include "primitive.h"
12
13 #include <avogadro/core/array.h>
14 #include <avogadro/core/vector.h>
15
16 #include <map>
17 #include <vector>
18
19 namespace Avogadro {
20 namespace Rendering {
21
22 class Camera;
23 class Drawable;
24
25 /**
26 * @class GeometryNode geometrynode.h <avogadro/rendering/geometrynode.h>
27 * @brief The GeometryNode class is the common base of all geometry nodes.
28 * @author Marcus D. Hanwell
29 *
30 * The GeometryNode contains any Drawable objects, and is the only node type
31 * that results in anything being rendered to the screen.
32 */
33
34 class AVOGADRORENDERING_EXPORT GeometryNode : public Node
35 {
36 public:
37 GeometryNode();
38 ~GeometryNode() override;
39
40 /**
41 * Accept a visit from our friendly visitor.
42 */
43 void accept(Visitor&) override;
44
45 /**
46 * @brief Add a drawable object to the geometry node.
47 * @param object Drawable object to be added.
48 */
49 void addDrawable(Drawable* object);
50
51 /**
52 * @brief Remove child node, this node will no longer be deleted.
53 * @param node Node to be removed.
54 * @return True if the node was removed, false if it was not found.
55 */
56 bool removeDrawable(Drawable* node);
57
58 /**
59 * @brief Get the child Node at the specified index.
60 * @param index The index of the child.
61 * @return A pointer to the child node, or nullptr if the index is out of
62 * range.
63 */
64 Drawable* drawable(size_t index);
65
66 /**
67 * @brief Get a reference to the child nodes list.
68 */
69 std::vector<Drawable*>& drawables() { return m_drawables; }
70 const std::vector<Drawable*> drawables() const { return m_drawables; }
71
72 /**
73 * @brief Remove all drawable objects.
74 */
75 void clearDrawables();
76
77 /**
78 * @brief Render the drawables in the geometry node.
79 */
80 void render(const Camera& camera);
81
82 /**
83 * Return the primitives that are hit by the ray.
84 * @param rayOrigin Origin of the ray.
85 * @param rayEnd End point of the ray.
86 * @param rayDirection Normalized direction of the ray.
87 * @return Sorted collection of primitives that were hit.
88 */
89 std::multimap<float, Identifier> hits(const Vector3f& rayOrigin,
90 const Vector3f& rayEnd,
91 const Vector3f& rayDirection) const;
92
93 /**
94 * Return the primitives within the supplied frustrum.
95 */
96 Core::Array<Identifier> areaHits(const Frustrum& frustrum) const;
97
98 protected:
99 std::vector<Drawable*> m_drawables;
100 };
101
102 } // End namespace Rendering
103 } // End namespace Avogadro
104
105 #endif // AVOGADRO_RENDERING_GEOMETRYNODE_H