Decay.cpp
Go to the documentation of this file.
1 #include "Decay.h"
2 
3 #include <SimoxUtility/math/scale_value.h>
4 
7 
8 
10 {
11 
12  void Decay::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix)
13  {
14  defs->optional(enabled, prefix + "enabled",
15  "If true, object poses decay over time when not localized anymore.");
16  defs->optional(delaySeconds, prefix + "delaySeconds",
17  "Duration after latest localization before decay starts.");
18  defs->optional(durationSeconds, prefix + "durationSeconds",
19  "How long to reach minimal confidence.");
20  defs->optional(maxConfidence, prefix + "maxConfidence",
21  "Confidence when decay starts.");
22  defs->optional(minConfidence, prefix + "minConfidence",
23  "Confidence after decay duration.");
24  defs->optional(removeObjectsBelowConfidence, prefix + "removeObjectsBelowConfidence",
25  "Remove objects whose confidence is lower than this value.");
26  }
27 
29  {
30  if (pose.attachment or pose.isStatic)
31  {
32  pose.confidence = 1.0;
33  }
34  else
35  {
36  pose.confidence = calculateConfidence(pose.timestamp, now);
37  }
38  }
39 
40  void Decay::updateConfidences(objpose::ObjectPoseSeq& objectPoses, const DateTime& now) const
41  {
42  for (objpose::ObjectPose& pose : objectPoses)
43  {
44  updateConfidence(pose, now);
45  }
46  }
47 
48  float Decay::calculateConfidence(const DateTime& localization, const DateTime& now) const
49  {
50  const float duration = static_cast<float>((now - localization).toSecondsDouble());
51  if (duration < delaySeconds)
52  {
53  return maxConfidence;
54  }
55  else if (duration > delaySeconds + this->durationSeconds)
56  {
57  return minConfidence;
58  }
59  else
60  {
61  return simox::math::scale_value_from_to(
62  duration,
65  }
66  }
67 
68 
69 
70  void Decay::RemoteGui::setup(const Decay& decay)
71  {
72  using namespace armarx::RemoteGui::Client;
73 
74  enabled.setValue(decay.enabled);
75  {
76  float max = 1e6;
79  delaySeconds.setSteps(int(10 * max)); // = 0.1 steps
81  }
82  {
83  float max = 1e6;
86  durationSeconds.setSteps(int(10 * max)); // = 0.1 steps
88  }
89  {
90  maxConfidence.setRange(0, 1);
93  }
94  {
95  minConfidence.setRange(0, 1);
98  }
99  {
103  }
104 
105  GridLayout grid;
106  int row = 0;
107  grid.add(Label("Enabled"), {row, 0}).add(enabled, {row, 1});
108  row++;
109  grid.add(Label("Delay [sec]"), {row, 0}).add(delaySeconds, {row, 1});
110  row++;
111  grid.add(Label("Duration [sec]"), {row, 0}).add(durationSeconds, {row, 1});
112  row++;
113  grid.add(Label("Max Confidence"), {row, 0}).add(maxConfidence, {row, 1});
114  row++;
115  grid.add(Label("Min Confidence"), {row, 0}).add(minConfidence, {row, 1});
116  row++;
117  grid.add(Label("Remove Objects with Confidence < "), {row, 0}).add(removeObjectsBelowConfidence, {row, 1});
118  row++;
119 
120  group.setLabel("Decay");
121  group.addChild(grid);
122  }
123 
125  {
126  decay.enabled = enabled.getValue();
132  }
133 
134 }
armarx::armem::server::obj::instance::Decay::RemoteGui::maxConfidence
armarx::RemoteGui::Client::FloatSlider maxConfidence
Definition: Decay.h:56
armarx::armem::server::obj::instance::Decay::minConfidence
float minConfidence
Definition: Decay.h:43
armarx::RemoteGui::Client::FloatSpinBox::getValue
float getValue() const
Definition: Widgets.cpp:332
armarx::RemoteGui::Client::ContainerWidget::addChild
void addChild(Widget const &child)
Definition: Widgets.cpp:95
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
armarx::armem::server::obj::instance::Decay::RemoteGui::update
void update(Decay &decay)
Definition: Decay.cpp:124
armarx::armem::server::obj::instance::Decay::updateConfidence
void updateConfidence(objpose::ObjectPose &pose, const DateTime &now) const
Definition: Decay.cpp:28
armarx::armem::server::obj::instance::Decay::updateConfidences
void updateConfidences(objpose::ObjectPoseSeq &objectPoses, const DateTime &now) const
Definition: Decay.cpp:40
armarx::armem::server::obj::instance::Decay
Models decay of object localizations by decreasing the confidence the longer the object was not local...
Definition: Decay.h:19
DateTime.h
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:412
armarx::RemoteGui::Client::FloatSpinBox::setValue
void setValue(float newValue)
Definition: Widgets.cpp:337
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::RemoteGui::Client::FloatSpinBox::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:313
Decay.h
armarx::RemoteGui::Client::FloatSlider::setValue
void setValue(float newValue)
Definition: Widgets.cpp:371
armarx::armem::server::obj::instance::Decay::removeObjectsBelowConfidence
float removeObjectsBelowConfidence
Definition: Decay.h:45
armarx::armem::server::obj::instance::Decay::RemoteGui::enabled
armarx::RemoteGui::Client::CheckBox enabled
Definition: Decay.h:52
armarx::armem::server::obj::instance
Definition: ArticulatedObjectVisu.cpp:16
armarx::armem::server::obj::instance::Decay::RemoteGui::minConfidence
armarx::RemoteGui::Client::FloatSlider minConfidence
Definition: Decay.h:57
armarx::RemoteGui::Client::CheckBox::getValue
bool getValue() const
Definition: Widgets.cpp:237
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
armarx::objpose::ObjectPose::isStatic
bool isStatic
Whether object is static. Static objects don't decay.
Definition: ObjectPose.h:65
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx::armem::server::obj::instance::Decay::delaySeconds
float delaySeconds
Duration after latest localization before decay starts.
Definition: Decay.h:38
armarx::armem::server::obj::instance::Decay::RemoteGui::delaySeconds
armarx::RemoteGui::Client::FloatSpinBox delaySeconds
Definition: Decay.h:54
armarx::RemoteGui::Client::FloatSlider::getValue
float getValue() const
Definition: Widgets.cpp:366
armarx::armem::server::obj::instance::Decay::enabled
bool enabled
Definition: Decay.h:35
armarx::armem::server::obj::instance::Decay::durationSeconds
float durationSeconds
How long to reach minConfidence.
Definition: Decay.h:40
armarx::RemoteGui::Client::FloatSpinBox::setDecimals
void setDecimals(int decimals)
Definition: Widgets.cpp:326
armarx::RemoteGui::Client::FloatSpinBox::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:320
armarx::armem::server::obj::instance::Decay::RemoteGui::setup
void setup(const Decay &decay)
Definition: Decay.cpp:70
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:395
armarx::RemoteGui::Client::FloatSlider::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:353
armarx::armem::server::obj::instance::Decay::maxConfidence
float maxConfidence
Definition: Decay.h:42
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::server::obj::instance::Decay::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="decay.")
Definition: Decay.cpp:12
armarx::armem::server::obj::instance::Decay::RemoteGui::durationSeconds
armarx::RemoteGui::Client::FloatSpinBox durationSeconds
Definition: Decay.h:55
TimeUtil.h
armarx::RemoteGui::Client::CheckBox::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:242
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::objpose::ObjectPose::attachment
std::optional< ObjectAttachmentInfo > attachment
Attachment information.
Definition: ObjectPose.h:95
armarx::armem::server::obj::instance::Decay::RemoteGui::group
armarx::RemoteGui::Client::GroupBox group
Definition: Decay.h:50
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::objpose::ObjectPose::confidence
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
Definition: ObjectPose.h:98
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:36
armarx::armem::server::obj::instance::Decay::RemoteGui::removeObjectsBelowConfidence
armarx::RemoteGui::Client::FloatSlider removeObjectsBelowConfidence
Definition: Decay.h:59
armarx::objpose::ObjectPose::timestamp
DateTime timestamp
Source timestamp.
Definition: ObjectPose.h:100
armarx::RemoteGui::Client::FloatSlider::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:360