LinearPredictionsVisu.cpp
Go to the documentation of this file.
2 
3 #include <SimoxUtility/math/pose.h>
4 
9 
13 
14 
16 {
17 
18  void LinearPredictions::defineProperties(PropertyDefinitionsPtr defs, const std::string& prefix)
19  {
20  defs->optional(showGhost, prefix + "showGhost",
21  "Show ghosts at linearly predicted object poses.");
22  defs->optional(ghostAlpha, prefix + "ghostAlpha",
23  "Alpha of linear prediction ghosts.");
24  defs->optional(showFrame, prefix + "showFrame",
25  "Show frames at linearly predicted object poses.");
26  defs->optional(showArrow, prefix + "showArrow",
27  "Show arrows from current object poses to the linearly predicted ones.");
28  defs->optional(timeOffsetSeconds, prefix + "timeOffset",
29  "The offset (in seconds) to the current time to make predictions for.");
30  defs->optional(timeWindowSeconds, prefix + "timeWindow",
31  "The time window (in seconds) into the past to perform the regression on.");
32 
33  }
34 
35 
37  {
38  return showGhost or showFrame or showArrow;
39  }
40 
42  viz::Layer& layer,
43  std::function<viz::Object(const std::string& key)> makeObjectFn,
44  const objpose::ObjectPose& objectPose,
45  const std::map<DateTime, objpose::ObjectPose>& poseHistory,
46  bool inGlobalFrame
47  ) const
48  {
49  const std::string key = objectPose.objectID.str();
50  const Eigen::Matrix4f pose = inGlobalFrame ? objectPose.objectPoseGlobal : objectPose.objectPoseRobot;
51 
52  auto predictionResult = objpose::predictObjectPoseLinear(
53  poseHistory,
55  objectPose);
56  if (predictionResult.success)
57  {
58  auto predictedObjectPose =
59  armarx::fromIce<objpose::ObjectPose>(predictionResult.prediction);
60  const Eigen::Matrix4f& predictedPose =
61  inGlobalFrame ? predictedObjectPose.objectPoseGlobal : 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")
72  .pose(predictedPose));
73  }
74  if (showArrow)
75  {
76  layer.add(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 
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(
114  {Label("Ghost"), showGhost,
115  Label(" Frame"), showFrame,
116  Label(" Arrow"), showArrow,
117  Label(" Ghost Alpha"), ghostAlpha
118  });
119  grid.add(showBoxes, {row, 0}, {1, 2});
120  row++;
121 
122  grid.add(Label("Prediction time (sec from now):"), {row, 0})
123  .add(timeOffsetSeconds, {row, 1});
124  row++;
125 
126  grid.add(Label("Model time window (sec before now):"), {row, 0})
127  .add(timeWindowSeconds, {row, 1});
128  row++;
129 
130  group = GroupBox();
131  group.setLabel("Linear Predictions");
132  group.addChild(grid);
133  }
134 
135 
137  {
138  data.showGhost = showGhost.getValue();
139  data.ghostAlpha = ghostAlpha.getValue();
140  data.showFrame = showFrame.getValue();
141  data.showArrow = showArrow.getValue();
142  data.timeOffsetSeconds = timeOffsetSeconds.getValue();
143  data.timeWindowSeconds = timeWindowSeconds.getValue();
144  }
145 
146 }
armarx::armem::server::obj::instance::visu::LinearPredictions::showAny
bool showAny() const
Definition: LinearPredictionsVisu.cpp:36
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::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::timeWindowSeconds
armarx::RemoteGui::Client::FloatSpinBox timeWindowSeconds
Definition: LinearPredictionsVisu.h:48
ice_conversions.h
predictions.h
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::showFrame
armarx::RemoteGui::Client::CheckBox showFrame
Definition: LinearPredictionsVisu.h:44
LinearPredictionsVisu.h
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::group
armarx::RemoteGui::Client::GroupBox group
Definition: LinearPredictionsVisu.h:50
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:412
armarx::armem::server::obj::instance::visu::LinearPredictions::showArrow
bool showArrow
Definition: LinearPredictionsVisu.h:24
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::showGhost
armarx::RemoteGui::Client::CheckBox showGhost
Definition: LinearPredictionsVisu.h:41
armarx::RemoteGui::Client::FloatSpinBox::setValue
void setValue(float newValue)
Definition: Widgets.cpp:337
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:41
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:313
armarx::viz::Arrow
Definition: Elements.h:198
ice_conversions.h
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:29
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::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx::viz::Object
Definition: Elements.h:321
armarx::armem::server::obj::instance::visu::LinearPredictions::showGhost
bool showGhost
Definition: LinearPredictionsVisu.h:20
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:136
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:90
armarx::viz::Pose
Definition: Elements.h:179
ObjectPose.h
armarx::armem::server::obj::instance::visu::LinearPredictions::showFrame
bool showFrame
Definition: LinearPredictionsVisu.h:23
armarx::RemoteGui::Client::FloatSpinBox::setSteps
void setSteps(int steps)
Definition: Widgets.cpp:320
armarx::armem::server::obj::instance::visu::LinearPredictions::timeWindowSeconds
float timeWindowSeconds
Definition: LinearPredictionsVisu.h:27
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:395
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:58
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::showArrow
armarx::RemoteGui::Client::CheckBox showArrow
Definition: LinearPredictionsVisu.h:45
TimeUtil.h
armarx::objpose::ObjectPose::objectPoseGlobal
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition: ObjectPose.h:73
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
PropertyDefinitionContainer.h
armarx::RemoteGui::Client::CheckBox::setValue
void setValue(bool newValue)
Definition: Widgets.cpp:242
armarx::armem::server::obj::instance::visu::LinearPredictions
Visualization control for linear predictions for objects.
Definition: LinearPredictionsVisu.h:18
armarx::armem::server::obj::instance::visu
Definition: LinearPredictionsVisu.cpp:15
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::ghostAlpha
armarx::RemoteGui::Client::FloatSpinBox ghostAlpha
Definition: LinearPredictionsVisu.h:42
armarx::armem::server::obj::instance::visu::LinearPredictions::timeOffsetSeconds
float timeOffsetSeconds
Definition: LinearPredictionsVisu.h:26
armarx::armem::server::obj::instance::visu::LinearPredictions::ghostAlpha
float ghostAlpha
Definition: LinearPredictionsVisu.h:21
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:92
armarx::objpose::ObjectPose::objectPoseRobot
Eigen::Matrix4f objectPoseRobot
The object pose in the robot root frame.
Definition: ObjectPose.h:68
armarx::viz::Color::azure
static Color azure(int az=255, int a=255)
2 Blue + 1 Green
Definition: Color.h:143
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:36
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:55
ice_conversions.h
armarx::armem::server::obj::instance::visu::LinearPredictions::RemoteGui::timeOffsetSeconds
armarx::RemoteGui::Client::FloatSpinBox timeOffsetSeconds
Definition: LinearPredictionsVisu.h:47