LinearPredictionsVisu.cpp
Go to the documentation of this file.
2
3#include <SimoxUtility/math/pose.h>
4
9
13
15{
16
17 void
19 {
20 defs->optional(
21 showGhost, prefix + "showGhost", "Show ghosts at linearly predicted object poses.");
22 defs->optional(ghostAlpha, prefix + "ghostAlpha", "Alpha of linear prediction ghosts.");
23 defs->optional(
24 showFrame, prefix + "showFrame", "Show frames at linearly predicted object poses.");
25 defs->optional(showArrow,
26 prefix + "showArrow",
27 "Show arrows from current object poses to the linearly predicted ones.");
28 defs->optional(timeOffsetSeconds,
29 prefix + "timeOffset",
30 "The offset (in seconds) to the current time to make predictions for.");
31 defs->optional(timeWindowSeconds,
32 prefix + "timeWindow",
33 "The time window (in seconds) into the past to perform the regression on.");
34 }
35
36 bool
38 {
39 return showGhost or showFrame or showArrow;
40 }
41
42 void
44 std::function<viz::Object(const std::string& key)> makeObjectFn,
45 const objpose::ObjectPose& objectPose,
46 const std::map<DateTime, objpose::ObjectPose>& poseHistory,
47 bool inGlobalFrame) const
48 {
49 const std::string key = objectPose.objectID.str();
50 const Eigen::Matrix4f pose =
51 inGlobalFrame ? objectPose.objectPoseGlobal : objectPose.objectPoseRobot;
52
53 auto predictionResult = objpose::predictObjectPoseLinear(
54 poseHistory, DateTime::Now() + Duration::SecondsDouble(timeOffsetSeconds), objectPose);
55 if (predictionResult.success)
56 {
57 auto predictedObjectPose =
58 armarx::fromIce<objpose::ObjectPose>(predictionResult.prediction);
59 const Eigen::Matrix4f& predictedPose = inGlobalFrame
60 ? predictedObjectPose.objectPoseGlobal
61 : predictedObjectPose.objectPoseRobot;
62
63 if (showGhost)
64 {
65 layer.add(makeObjectFn(key + " Linear Prediction Ghost")
66 .pose(predictedPose)
67 .overrideColor(simox::Color::white().with_alpha(ghostAlpha)));
68 }
69 if (showFrame)
70 {
71 layer.add(viz::Pose(key + " Linear Prediction Pose").pose(predictedPose));
72 }
73 if (showArrow)
74 {
75 layer.add(
76 viz::Arrow(key + " Linear Prediction Arrw")
77 .fromTo(simox::math::position(pose), simox::math::position(predictedPose))
78 .width(10)
79 .color(viz::Color::azure()));
80 }
81 }
82 else
83 {
84 ARMARX_INFO << deactivateSpam(60) << "Linear prediction for visualization failed: "
85 << predictionResult.errorMessage;
86 }
87 }
88
89 void
91 {
92 using namespace armarx::RemoteGui::Client;
93
94 showGhost.setName("Show Ghost");
95 showGhost.setValue(data.showGhost);
96 showFrame.setValue(data.showFrame);
97 showArrow.setValue(data.showArrow);
98
99 ghostAlpha.setRange(0, 1);
100 ghostAlpha.setValue(0.5);
101
102 timeOffsetSeconds.setValue(data.timeOffsetSeconds);
103 timeOffsetSeconds.setRange(-1e6, 1e6);
104 timeOffsetSeconds.setSteps(2 * 2 * 1000 * 1000);
105
106 timeWindowSeconds.setValue(data.timeWindowSeconds);
107 timeWindowSeconds.setRange(0, 1e6);
108 timeWindowSeconds.setSteps(2 * 1000 * 1000);
109
110 GridLayout grid;
111 int row = 0;
112
113 HBoxLayout showBoxes({Label("Ghost"),
114 showGhost,
115 Label(" Frame"),
116 showFrame,
117 Label(" Arrow"),
118 showArrow,
119 Label(" Ghost Alpha"),
120 ghostAlpha});
121 grid.add(showBoxes, {row, 0}, {1, 2});
122 row++;
123
124 grid.add(Label("Prediction time (sec from now):"), {row, 0})
125 .add(timeOffsetSeconds, {row, 1});
126 row++;
127
128 grid.add(Label("Model time window (sec before now):"), {row, 0})
129 .add(timeWindowSeconds, {row, 1});
130 row++;
131
132 group = GroupBox();
133 group.setLabel("Linear Predictions");
134 group.addChild(grid);
135 }
136
137 void
139 {
140 data.showGhost = showGhost.getValue();
141 data.ghostAlpha = ghostAlpha.getValue();
142 data.showFrame = showFrame.getValue();
143 data.showArrow = showArrow.getValue();
144 data.timeOffsetSeconds = timeOffsetSeconds.getValue();
145 data.timeWindowSeconds = timeWindowSeconds.getValue();
146 }
147
148} // namespace armarx::armem::server::obj::instance::visu
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
static DateTime Now()
Definition DateTime.cpp:51
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition Logging.cpp:99
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
Definition ObjectID.cpp:60
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
Definition Duration.cpp:78
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
objpose::ObjectPosePredictionResult predictObjectPoseLinear(const std::map< DateTime, ObjectPose > &poses, const DateTime &time, const ObjectPose &latestPose)
Predict the pose of an object given a history of poses based on a linear regression.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition Widgets.cpp:438
Visualization control for linear predictions for objects.
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix)
void draw(viz::Layer &layer, std::function< viz::Object(const std::string &key)> makeObjectFn, const objpose::ObjectPose &objectPose, const std::map< DateTime, objpose::ObjectPose > &poseHistory, bool inGlobalFrame) const
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition ObjectPose.h:56
Eigen::Matrix4f objectPoseRobot
The object pose in the robot root frame.
Definition ObjectPose.h:66
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition ObjectPose.h:71
void add(ElementT const &element)
Definition Layer.h:31