TAMSVIZ
Visualization and annotation tool for ROS
light.cpp
1 // TAMSVIZ
2 // (c) 2020 Philipp Ruppel
3 
4 #include "light.h"
5 
6 #include "../core/log.h"
7 
9  virtual void renderSync(const RenderSyncContext &context) override {
10  LightDisplayBase::renderSync(context);
11  if (visible()) {
12  LightBlock light;
13  light.color = color().toLinearVector4f().head(3) * (float)brightness();
14  light.type = (uint32_t)LightType::Ambient;
15  context.render_list->push(light);
16  }
17  }
18 };
19 DECLARE_TYPE_C(AmbientLight, LightDisplayBase, Light);
20 
22  virtual void renderSync(const RenderSyncContext &context) override {
23  LightDisplayBase::renderSync(context);
24  if (visible()) {
25  auto pose = context.pose;
26  if (viewSpace()) {
27  pose = this->transform().toIsometry3d();
28  }
29  LightBlock light;
30  light.position.head(3) = pose.translation().cast<float>();
31  light.pose = pose.inverse().matrix().cast<float>();
32  light.color = color().toLinearVector4f().head(3) * (float)brightness();
33  light.type =
34  (uint32_t(LightType::Directional) |
35  (viewSpace() ? uint32_t(LightType::ViewSpace) : uint32_t(0)));
36  context.render_list->push(light);
37  }
38  }
39 };
40 DECLARE_TYPE_C(DirectionalLight, LightDisplayBase, Light);
41 
43  virtual void renderSync(const RenderSyncContext &context) override {
44  LightDisplayBase::renderSync(context);
45  if (visible()) {
46  auto pose = context.pose;
47  if (viewSpace()) {
48  pose = this->transform().toIsometry3d();
49  }
50  LightBlock light;
51  light.position.head(3) = pose.translation().cast<float>();
52  light.pose = pose.inverse().matrix().cast<float>();
53  light.color = color().toLinearVector4f().head(3) * (float)brightness();
54  light.type =
55  (uint32_t(LightType::Point) |
56  (viewSpace() ? uint32_t(LightType::ViewSpace) : uint32_t(0)));
57  context.render_list->push(light);
58  }
59  }
60 };
61 DECLARE_TYPE_C(PointLight, LightDisplayBase, Light);
62 
64  PROPERTY(double, softness, 0.5, min = 0.0, max = 1.0);
65  PROPERTY(double, angle, 90, min = 0.0, max = 180);
66  virtual void renderSync(const RenderSyncContext &context) override {
67  LightDisplayBase::renderSync(context);
68  if (visible()) {
69  auto pose = context.pose;
70  if (viewSpace()) {
71  pose = this->transform().toIsometry3d();
72  }
73  LightBlock light;
74  light.position.head(3) = pose.translation().cast<float>();
75  light.pose =
76  (projectionMatrix(std::max(1e-6, std::min(180.0 - 1e-3, angle())) *
77  M_PI / 180.0,
78  1.0, 0.01, 100.0) *
79  pose.inverse().matrix())
80  .cast<float>();
81  light.color = color().toLinearVector4f().head(3) * (float)brightness();
82  light.type =
83  (uint32_t(LightType::Spot) |
84  (viewSpace() ? uint32_t(LightType::ViewSpace) : uint32_t(0)));
85  light.softness = std::max(0.0001f, std::min(1.0f, (float)softness()));
86  context.render_list->push(light);
87  }
88  }
89 };
90 DECLARE_TYPE_C(SpotLight, LightDisplayBase, Light);