ice_conversions.cpp
Go to the documentation of this file.
1 #include "ice_conversions.h"
2 
3 #include <VirtualRobot/Robot.h>
4 #include <VirtualRobot/RobotConfig.h>
5 
6 #include <SimoxUtility/algorithm/string.h>
7 #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
8 #include <SimoxUtility/shapes/OrientedBox.h>
9 
11 
14 
17 
18 
19 namespace armarx
20 {
21  std::ostream& data::operator<<(std::ostream& os, const ObjectID& id)
22  {
23  os << "'" << id.dataset << "/" << id.className;
24  if (!id.instanceName.empty())
25  {
26  os << "/" << id.instanceName;
27  }
28  return os << "'";
29  }
30 
31 }
32 
34 {
35  id = fromIce(ice);
36 }
37 
39 {
40  return { ice.dataset, ice.className, ice.instanceName };
41 }
42 
43 void armarx::toIce(data::ObjectID& ice, const ObjectID& id)
44 {
45  ice.dataset = id.dataset();
46  ice.className = id.className();
47  ice.instanceName = id.instanceName();
48 }
49 
51 {
52  data::ObjectID ice;
53  toIce(ice, id);
54  return ice;
55 }
56 
57 void armarx::fromIce(const data::ObjectIDSeq& ice, std::vector<ObjectID>& ids)
58 {
59  ids.clear();
60  std::transform(ice.begin(), ice.end(), std::back_inserter(ids),
61  static_cast<ObjectID(*)(const data::ObjectID&)>(&fromIce));
62 }
63 
64 std::vector<armarx::ObjectID> armarx::fromIce(const data::ObjectIDSeq& ice)
65 {
66  std::vector<ObjectID> ids;
67  fromIce(ice, ids);
68  return ids;
69 }
70 
71 void armarx::toIce(data::ObjectIDSeq& ice, const std::vector<ObjectID>& ids)
72 {
73  ice.clear();
74  std::transform(ids.begin(), ids.end(), std::back_inserter(ice),
75  static_cast<data::ObjectID(*)(const ObjectID&)>(&toIce));
76 }
77 
78 armarx::data::ObjectIDSeq armarx::toIce(const std::vector<ObjectID>& ids)
79 {
80  data::ObjectIDSeq ice;
81  toIce(ice, ids);
82  return ice;
83 }
84 
85 namespace armarx
86 {
87  const simox::meta::EnumNames<objpose::ObjectType> objpose::ObjectTypeNames =
88  {
89  { objpose::ObjectType::AnyObject, "AnyObject" },
90  { objpose::ObjectType::KnownObject, "KnownObject" },
91  { objpose::ObjectType::UnknownObject, "UnknownObject" }
92  };
93 
94  objpose::AABB objpose::toIce(const simox::AxisAlignedBoundingBox& aabb)
95  {
96  objpose::AABB ice;
97  ice.center = new Vector3(aabb.center());
98  ice.extents = new Vector3(aabb.extents());
99  return ice;
100  }
101 
102  void objpose::fromIce(const Box& box, simox::OrientedBoxf& oobb)
103  {
104  try
105  {
106  Eigen::Vector3f pos = armarx::fromIce(box.position);
107  Eigen::Matrix3f ori = armarx::fromIce(box.orientation).toRotationMatrix();
108  Eigen::Vector3f extents = armarx::fromIce(box.extents);
109  Eigen::Vector3f corner = pos - ori * extents / 2;
110 
111  oobb = simox::OrientedBox<float> (corner,
112  ori.col(0) * extents(0),
113  ori.col(1) * extents(1),
114  ori.col(2) * extents(2));
115  }
116  catch (const armarx::LocalException&)
117  {
118  // No OOBB information.
119  oobb = {};
120  }
121  }
122  void objpose::fromIce(const BoxPtr& box, std::optional<simox::OrientedBox<float>>& oobb)
123  {
124  if (box)
125  {
126  oobb = fromIce(*box);
127  }
128  else
129  {
130  oobb = std::nullopt;
131  }
132  }
133 
134  simox::OrientedBoxf objpose::fromIce(const Box& box)
135  {
136  simox::OrientedBoxf oobb;
137  fromIce(box, oobb);
138  return oobb;
139  }
140 
141  void objpose::toIce(Box& box, const simox::OrientedBoxf& oobb)
142  {
143  box.position = new Vector3(oobb.center());
144  box.orientation = new Quaternion(oobb.rotation().eval());
145  box.extents = new Vector3(oobb.dimensions());
146  }
147 
148  void objpose::toIce(BoxPtr& box, const std::optional<simox::OrientedBox<float>>& oobb)
149  {
150  if (oobb)
151  {
152  box = new Box();
153  toIce(*box, *oobb);
154  }
155  }
156 
157  objpose::Box objpose::toIce(const simox::OrientedBoxf& oobb)
158  {
159  objpose::Box box;
160  toIce(box, oobb);
161  return box;
162  }
163 
164 
165  void objpose::fromIce(const data::PoseManifoldGaussian& ice, PoseManifoldGaussian& cov)
166  {
167  // Only construct error message if necessary.
168  if (static_cast<Eigen::Index>(ice.covariance6x6.size()) != cov.covariance.size())
169  {
170  ARMARX_CHECK_EQUAL(static_cast<Eigen::Index>(ice.covariance6x6.size()), cov.covariance.size())
171  << "Float sequence representing 6x6 covariance matrix must have " << cov.covariance.size()
172  << " values, but has " << ice.covariance6x6.size() << ": \n"
173  << "[" << simox::alg::join(simox::alg::multi_to_string(ice.covariance6x6), ", ") << "]"
174  ;
175  }
176 
177  armarx::fromIce(ice.mean, cov.mean);
178  cov.covariance = Eigen::MatrixXf::Map(ice.covariance6x6.data(),
179  cov.covariance.rows(),
180  cov.covariance.cols());
181  }
182 
183  void objpose::fromIce(const data::PoseManifoldGaussianPtr& ice, std::optional<PoseManifoldGaussian>& cov)
184  {
185  if (ice)
186  {
187  cov = PoseManifoldGaussian();
188  fromIce(*ice, cov.value());
189  }
190  else
191  {
192  cov = std::nullopt;
193  }
194  }
195 
196  std::optional<objpose::PoseManifoldGaussian> objpose::fromIce(const data::PoseManifoldGaussianPtr& ice)
197  {
198  std::optional<objpose::PoseManifoldGaussian> cov;
199  fromIce(ice, cov);
200  return cov;
201  }
202 
203 
204  void objpose::toIce(data::PoseManifoldGaussian& ice, const PoseManifoldGaussian& cov)
205  {
206  armarx::toIce(ice.mean, cov.mean);
207 
208  ice.covariance6x6.resize(cov.covariance.size());
209  Eigen::MatrixXf::Map(ice.covariance6x6.data(),
210  cov.covariance.rows(),
211  cov.covariance.cols()) = cov.covariance;
212  }
213 
214  void objpose::toIce(data::PoseManifoldGaussianPtr& ice, const std::optional<PoseManifoldGaussian>& cov)
215  {
216  if (cov.has_value())
217  {
218  ice = new data::PoseManifoldGaussian;
219  toIce(*ice, cov.value());
220  }
221  else
222  {
223  ice = nullptr;
224  }
225  }
226 
227  objpose::data::PoseManifoldGaussianPtr objpose::toIce(const std::optional<PoseManifoldGaussian>& cov)
228  {
229  data::PoseManifoldGaussianPtr ice;
230  toIce(ice, cov);
231  return ice;
232  }
233 
234 }
armarx::SpawnerType::Box
@ Box
ice_conversions.h
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:11
armarx::objpose::PoseManifoldGaussian::mean
Eigen::Matrix4f mean
The mean (i.e. a pose).
Definition: PoseManifoldGaussian.h:30
armarx::armem::attachment::ObjectID
armem::MemoryID ObjectID
Definition: types.h:79
Pose.h
armarx::VariantType::Map
const VariantContainerType Map
Definition: StringValueMap.h:247
armarx::objpose::fromIce
void fromIce(const Box &box, simox::OrientedBox< float > &oobb)
armarx::objpose::PoseManifoldGaussian
A "gaussian" distribution in pose space (i.e.
Definition: PoseManifoldGaussian.h:25
armarx::objpose::PoseManifoldGaussian::covariance
Eigen::Matrix< float, 6, 6 > covariance
The covariance matrix.
Definition: PoseManifoldGaussian.h:32
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
armarx::aron::simox::arondto::AxisAlignedBoundingBox
::simox::arondto::AxisAlignedBoundingBox AxisAlignedBoundingBox
Definition: simox.h:14
visionx::armem::camera::fromIce
void fromIce(visionx::arondto::StereoCameraCalibration &aron, const visionx::StereoCalibration &ice)
Definition: ice_conversions.cpp:79
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
FramedPose.h
armarx::data::operator<<
std::ostream & operator<<(std::ostream &os, const ObjectID &id)
Definition: ice_conversions.cpp:21
PoseManifoldGaussian.h
armarx::objpose::ObjectTypeNames
const simox::meta::EnumNames< objpose::ObjectType > ObjectTypeNames
Definition: ice_conversions.cpp:87
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:26
visionx::armem::camera::toIce
void toIce(const visionx::arondto::StereoCameraCalibration &aron, visionx::StereoCalibration &ice)
Definition: ice_conversions.cpp:90
ExpressionException.h
armarx::objpose::toIce
objpose::AABB toIce(const simox::AxisAlignedBoundingBox &aabb)
Definition: ice_conversions.cpp:94
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
simox::OrientedBox
Definition: ice_conversions.h:18
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28