Debian Codegraph @

avogadro/rendering/curvegeometry.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_CURVEGEOMETRY_H
7 #define AVOGADRO_RENDERING_CURVEGEOMETRY_H
8
9 #include "bufferobject.h"
10 #include "drawable.h"
11 #include "shader.h"
12 #include "shaderprogram.h"
13 #include "vertexarrayobject.h"
14 #include <avogadro/core/vector.h>
15 #include <list>
16 #include <map>
17 #include <vector>
18
19 namespace Avogadro {
20 namespace Rendering {
21
22 struct ShaderInfo
23 {
24 Shader vertexShader;
25 Shader fragmentShader;
26 ShaderProgram program;
27 };
28
29 struct Point
30 {
31 Point(const Vector3f& p, const Vector3ub& c, size_t i)
32 : pos(p), color(c), id(i)
33 {
34 }
35 Vector3f pos;
36 Vector3ub color;
37 size_t id;
38 };
39
40 struct Line
41 {
42 Line() : dirty(true), flat(true), radius(0.0f) {}
43 explicit Line(float r) : dirty(true), radius(r) { flat = r < 0.0f; }
44
45 ~Line()
46 {
47 for (auto& p : points) {
48 delete p;
49 }
50 }
51 void add(Point* point)
52 {
53 points.push_back(point);
54 dirty = true;
55 }
56 std::list<Point*> points;
57 bool dirty;
58 bool flat; // use GL_POINTS
59 float radius;
60 BufferObject vbo;
61 BufferObject ibo; // EBO/IBO
62 VertexArrayObject vao;
63 size_t numberOfVertices;
64 size_t numberOfIndices;
65 };
66
67 class AVOGADRORENDERING_EXPORT CurveGeometry : public Drawable
68 {
69 public:
70 CurveGeometry();
71 CurveGeometry(bool flat);
72 ~CurveGeometry() override;
73 /**
74 * Accept a visit from our friendly visitor.
75 */
76 void accept(Visitor& visitor) override;
77 /**
78 * @brief Render the cylinder geometry.
79 * @param camera The current camera to be used for rendering.
80 */
81 void render(const Camera& camera) override;
82
83 void addPoint(const Vector3f& pos, const Vector3ub& color, float radius,
84 size_t group, size_t id);
85 const std::vector<Line*>& lines() const { return m_lines; };
86
87 const static size_t SKIPPED;
88
89 protected:
90 std::vector<Line*> m_lines;
91 std::map<size_t, size_t> m_indexMap;
92 ShaderInfo m_shaderInfo;
93 bool m_dirty;
94 bool m_canBeFlat;
95
96 virtual void update(int index);
97 virtual Vector3f computeCurvePoint(float t,
98 const std::list<Point*>& points) const = 0;
99 virtual std::vector<ColorNormalVertex> computeCirclePoints(
100 const Eigen::Affine3f& a, const Eigen::Affine3f& b, bool flat) const;
101 virtual float computeScale(size_t index, float t, float scale) const;
102
103 void processShaderError(bool error);
104
105 Core::Array<Identifier> areaHits(const Frustrum& f) const override;
106 };
107
108 } // End namespace Rendering
109 } // End namespace Avogadro
110
111 #endif