RayZaler 0.1
The free opto-mechanical simulation framework
RayBeamElement.h
1//
2// Copyright (c) 2024 Gonzalo José Carracedo Carballal
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as
6// published by the Free Software Foundation, either version 3 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public
15// License along with this program. If not, see
16// <http://www.gnu.org/licenses/>
17//
18
19#ifndef _RAY_BEAM_ELEMENT_H
20#define _RAY_BEAM_ELEMENT_H
21
22#include <Element.h>
23#include <RayTracingEngine.h>
24#include <GLHelpers.h>
25#include <Random.h>
26#include <pthread.h>
27#include <map>
28
29namespace RZ {
31 public:
32 virtual void id2color(uint32_t, GLfloat *rgba) const;
33 virtual void id2color(uint32_t, GLfloat alpha, GLfloat *rgba) const;
34 virtual ~RayColoring();
35 };
36
38 GLfloat rgb[3];
39 };
40
42 std::map<uint32_t, CrappyCplusplusColorWrapper> m_colors;
43 GLfloat m_defaultColor[3] = {1., 1., 0};
44
45 public:
46 virtual void id2color(uint32_t, GLfloat *rgb) const override;
47
48 void setColor(uint32_t id, Real r, Real g, Real b);
49 void setDefaultColor(Real r, Real g, Real b);
50 };
51
53 std::vector<GLfloat> vertices;
54 std::vector<GLfloat> colors;
55 GLfloat lineWidth = .25;
56 GLushort stipple = 0xffff;
57
58 void renderOpenGL();
59 void clear();
60 void push(
61 Vec3 const &origin,
62 Vec3 const &dest,
63 const GLfloat *color,
64 const GLfloat *color2 = nullptr);
65 };
66
67 class RayBeamElement : public Element {
68 static RayColoring m_defaultColoring;
69 const RayColoring *m_rayColoring = nullptr;
70 ExprRandomState m_randState;
71 unsigned int m_maxRays = 5000;
72 uint64_t m_strayRays = 0;
73
74 pthread_mutex_t m_rayMutex = PTHREAD_MUTEX_INITIALIZER;
75 std::list<Ray> m_rays;
76 LineVertexSet m_commonRayVert;
77 LineVertexSet m_chiefRayVert;
78 bool m_dynamicAlpha = false;
79 void raysToVertices();
80
81 public:
82 inline uint64_t
83 strayRays() const
84 {
85 return m_strayRays;
86 }
87
90 std::string const &,
92 Element *parent = nullptr);
93 virtual ~RayBeamElement() override;
94
95 void clear();
96 void setList(std::list<Ray> const &);
97 void setRayColoring(RayColoring const *);
98 void setRayColoring(RayColoring const &);
99 void setRayWidth(Real width);
100 void setDynamicAlpha(bool);
101
102 virtual void renderOpenGL() override;
103 };
104
105 RZ_DECLARE_ELEMENT(RayBeamElement);
106}
107
108#endif // _RAY_BEAM_ELEMENT_H
Definition: Element.h:393
Definition: Element.h:173
Definition: Random.h:28
Definition: RayBeamElement.h:41
Definition: RayBeamElement.h:67
Definition: RayBeamElement.h:30
Definition: ReferenceFrame.h:59
Definition: RayBeamElement.h:37
Definition: RayBeamElement.h:52
Definition: Vector.h:66