Decay.cpp
Go to the documentation of this file.
1#include "Decay.h"
2
3#include <SimoxUtility/math/scale_value.h>
4
7
9{
10
11 void
13 {
14 defs->optional(enabled,
15 prefix + "enabled",
16 "If true, object poses decay over time when not localized anymore.");
17 defs->optional(delaySeconds,
18 prefix + "delaySeconds",
19 "Duration after latest localization before decay starts.");
20 defs->optional(
21 durationSeconds, prefix + "durationSeconds", "How long to reach minimal confidence.");
22 defs->optional(maxConfidence, prefix + "maxConfidence", "Confidence when decay starts.");
23 defs->optional(minConfidence, prefix + "minConfidence", "Confidence after decay duration.");
24 defs->optional(removeObjectsBelowConfidence,
25 prefix + "removeObjectsBelowConfidence",
26 "Remove objects whose confidence is lower than this value.");
27 }
28
29 void
31 {
32 if (pose.attachment or pose.isStatic)
33 {
34 pose.confidence = 1.0;
35 }
36 else
37 {
38 pose.confidence = calculateConfidence(pose.timestamp, now);
39 }
40 }
41
42 void
44 {
45 for (objpose::ObjectPose& pose : objectPoses)
46 {
47 updateConfidence(pose, now);
48 }
49 }
50
51 float
52 Decay::calculateConfidence(const DateTime& localization, const DateTime& now) const
53 {
54 const float duration = static_cast<float>((now - localization).toSecondsDouble());
55 if (duration < delaySeconds)
56 {
57 return maxConfidence;
58 }
59 else if (duration > delaySeconds + this->durationSeconds)
60 {
61 return minConfidence;
62 }
63 else
64 {
65 return simox::math::scale_value_from_to(duration,
70 }
71 }
72
73 void
75 {
76 using namespace armarx::RemoteGui::Client;
77
78 enabled.setValue(decay.enabled);
79 {
80 float max = 1e6;
81 delaySeconds.setRange(0, max);
82 delaySeconds.setDecimals(2);
83 delaySeconds.setSteps(int(10 * max)); // = 0.1 steps
84 delaySeconds.setValue(decay.delaySeconds);
85 }
86 {
87 float max = 1e6;
88 durationSeconds.setRange(0, max);
89 durationSeconds.setDecimals(2);
90 durationSeconds.setSteps(int(10 * max)); // = 0.1 steps
91 durationSeconds.setValue(decay.durationSeconds);
92 }
93 {
94 maxConfidence.setRange(0, 1);
95 maxConfidence.setSteps(100);
96 maxConfidence.setValue(decay.maxConfidence);
97 }
98 {
99 minConfidence.setRange(0, 1);
100 minConfidence.setSteps(100);
101 minConfidence.setValue(decay.minConfidence);
102 }
103 {
104 removeObjectsBelowConfidence.setRange(0, 1);
105 removeObjectsBelowConfidence.setSteps(100);
107 }
108
109 GridLayout grid;
110 int row = 0;
111 grid.add(Label("Enabled"), {row, 0}).add(enabled, {row, 1});
112 row++;
113 grid.add(Label("Delay [sec]"), {row, 0}).add(delaySeconds, {row, 1});
114 row++;
115 grid.add(Label("Duration [sec]"), {row, 0}).add(durationSeconds, {row, 1});
116 row++;
117 grid.add(Label("Max Confidence"), {row, 0}).add(maxConfidence, {row, 1});
118 row++;
119 grid.add(Label("Min Confidence"), {row, 0}).add(minConfidence, {row, 1});
120 row++;
121 grid.add(Label("Remove Objects with Confidence < "), {row, 0})
122 .add(removeObjectsBelowConfidence, {row, 1});
123 row++;
124
125 group.setLabel("Decay");
126 group.addChild(grid);
127 }
128
129 void
131 {
132 decay.enabled = enabled.getValue();
133 decay.delaySeconds = delaySeconds.getValue();
134 decay.durationSeconds = durationSeconds.getValue();
135 decay.maxConfidence = maxConfidence.getValue();
136 decay.minConfidence = minConfidence.getValue();
138 }
139
140} // namespace armarx::armem::server::obj::familiar_object_instance
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
Models decay of object localizations by decreasing the confidence the longer the object was not local...
Definition Decay.h:19
float durationSeconds
How long to reach minConfidence.
Definition Decay.h:37
void updateConfidence(objpose::ObjectPose &pose, const DateTime &now) const
Definition Decay.cpp:30
float delaySeconds
Duration after latest localization before decay starts.
Definition Decay.h:35
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="decay.")
Definition Decay.cpp:12
void updateConfidences(objpose::ObjectPoseSeq &objectPoses, const DateTime &now) const
Definition Decay.cpp:43
Represents a point in time.
Definition DateTime.h:25
std::vector< ObjectPose > ObjectPoseSeq
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition Widgets.cpp:438
armarx::RemoteGui::Client::FloatSpinBox delaySeconds
Definition Decay.h:50
armarx::RemoteGui::Client::FloatSpinBox durationSeconds
Definition Decay.h:51
armarx::RemoteGui::Client::FloatSlider removeObjectsBelowConfidence
Definition Decay.h:55
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
Definition ObjectPose.h:96
std::optional< ObjectAttachmentInfo > attachment
Attachment information.
Definition ObjectPose.h:93
bool isStatic
Whether object is static. Static objects don't decay.
Definition ObjectPose.h:63
DateTime timestamp
Source timestamp.
Definition ObjectPose.h:98