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
armarx::armem::server::obj::instance::visu::LinearPredictions::showAny
bool showAny() const
Definition: LinearPredictionsVisu.cpp:37
armarx::RemoteGui::Client::FloatSpinBox::getValue
float getValue() const
Definition: Widgets.cpp:352
armarx::RemoteGui::Client::ContainerWidget::addChild
void addChild(Widget const &child)
Definition: Widgets.cpp:95
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::timeWindowSeconds
armarx::RemoteGui::Client::FloatSpinBox timeWindowSeconds
Definition: LinearPredictionsVisu.h:46
ice_conversions.h
predictions.h
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::showFrame
armarx::RemoteGui::Client::CheckBox showFrame
Definition: LinearPredictionsVisu.h:42
LinearPredictionsVisu.h
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::group
armarx::RemoteGui::Client::GroupBox group
Definition: LinearPredictionsVisu.h:48
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:51
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:438
armarx::armem::server::obj::instance::visu::LinearPredictions::showArrow
bool showArrow
Definition: LinearPredictionsVisu.h:23
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::showGhost
armarx::RemoteGui::Client::CheckBox showGhost
Definition: LinearPredictionsVisu.h:39
armarx::RemoteGui::Client::FloatSpinBox::setValue
void setValue(float newValue)
Definition: Widgets.cpp:358
armarx::armem::server::obj::instance::visu::LinearPredictions::draw
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
Definition: LinearPredictionsVisu.cpp:43
armarx::RemoteGui::Client::Widget::setName
void setName(std::string const &name)
Definition: Widgets.cpp:19
armarx::RemoteGui::Client::FloatSpinBox::setRange
void setRange(float min, float max)
Definition: Widgets.cpp:330
armarx::viz::Arrow
Definition: Elements.h:196
ice_conversions.h
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::RemoteGui::Client::CheckBox::getValue
bool getValue() const
Definition: Widgets.cpp:246
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:6
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx::viz::Object
Definition: Elements.h:332
armarx::armem::server::obj::instance::visu::LinearPredictions::showGhost
bool showGhost
Definition: LinearPredictionsVisu.h:19
armarx::armem::server::obj::instance::visu::LinearPredictions::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: LinearPredictionsVisu.cpp:18
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::update
void update(LinearPredictions &data)
Definition: LinearPredictionsVisu.cpp:138
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
armarx::core::time::Duration::SecondsDouble
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:78
armarx::viz::Pose
Definition: Elements.h:178
ObjectPose.h
armarx::armem::server::obj::instance::visu::LinearPredictions::showFrame
bool showFrame
Definition: LinearPredictionsVisu.h:22
armarx::RemoteGui::Client::FloatSpinBox::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:338
armarx::armem::server::obj::instance::visu::LinearPredictions::timeWindowSeconds
float timeWindowSeconds
Definition: LinearPredictionsVisu.h:26
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:420
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::setup
void setup(const LinearPredictions &data)
Definition: LinearPredictionsVisu.cpp:90
armarx::RemoteGui::Client::HBoxLayout
Definition: Widgets.h:160
armarx::objpose::ObjectPose::objectID
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition: ObjectPose.h:56
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::showArrow
armarx::RemoteGui::Client::CheckBox showArrow
Definition: LinearPredictionsVisu.h:43
TimeUtil.h
armarx::objpose::ObjectPose::objectPoseGlobal
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition: ObjectPose.h:71
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
PropertyDefinitionContainer.h
armarx::RemoteGui::Client::CheckBox::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:252
armarx::armem::server::obj::instance::visu::LinearPredictions
Visualization control for linear predictions for objects.
Definition: LinearPredictionsVisu.h:17
armarx::armem::server::obj::instance::visu
Definition: LinearPredictionsVisu.cpp:14
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::ghostAlpha
armarx::RemoteGui::Client::FloatSpinBox ghostAlpha
Definition: LinearPredictionsVisu.h:40
armarx::armem::server::obj::instance::visu::LinearPredictions::timeOffsetSeconds
float timeOffsetSeconds
Definition: LinearPredictionsVisu.h:25
armarx::armem::server::obj::instance::visu::LinearPredictions::ghostAlpha
float ghostAlpha
Definition: LinearPredictionsVisu.h:20
armarx::Logging::deactivateSpam
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
armarx::objpose::ObjectPose::objectPoseRobot
Eigen::Matrix4f objectPoseRobot
The object pose in the robot root frame.
Definition: ObjectPose.h:66
armarx::viz::Color::azure
static Color azure(int az=255, int a=255)
2 Blue + 1 Green
Definition: Color.h:160
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::viz::Layer
Definition: Layer.h:12
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:33
armarx::objpose::predictObjectPoseLinear
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.
Definition: predictions.cpp:37
armarx::ObjectID::str
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
Definition: ObjectID.cpp:60
ice_conversions.h
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::timeOffsetSeconds
armarx::RemoteGui::Client::FloatSpinBox timeOffsetSeconds
Definition: LinearPredictionsVisu.h:45