37 #include <gtest/gtest.h>
39 #include <geometric_shapes/shapes.h>
49 shapes::ShapePtr ball = std::make_shared<shapes::Sphere>(1.0);
50 shapes::ShapePtr box = std::make_shared<shapes::Box>(1, 2, 3);
51 shapes::ShapePtr cyl = std::make_shared<shapes::Cylinder>(4, 5);
53 EXPECT_EQ(1, ball.use_count());
58 world.
addToObject(
"ball", ball, Eigen::Isometry3d::Identity());
60 EXPECT_EQ(2, ball.use_count());
63 bool move_ok = world.
moveShapeInObject(
"ball", ball, Eigen::Isometry3d(Eigen::Translation3d(0, 0, 9)));
66 EXPECT_EQ(2, ball.use_count());
70 EXPECT_FALSE(rm_nonexistant);
73 EXPECT_FALSE(rm_wrong_shape);
75 EXPECT_EQ(2, ball.use_count());
76 EXPECT_EQ(1, box.use_count());
82 EXPECT_EQ(1, ball.use_count());
86 world.
addToObject(
"ball", ball, Eigen::Isometry3d::Identity());
88 EXPECT_EQ(2, ball.use_count());
94 std::vector<shapes::ShapeConstPtr>
shapes;
95 EigenSTL::vector_Isometry3d poses;
101 poses.push_back(Eigen::Isometry3d(Eigen::Translation3d(0, 0, 1)));
102 poses.push_back(Eigen::Isometry3d(Eigen::Translation3d(0, 0, 2)));
103 poses.push_back(Eigen::Isometry3d(Eigen::Translation3d(0, 0, 3)));
113 EXPECT_EQ(2, box.use_count());
114 EXPECT_EQ(2, cyl.use_count());
115 EXPECT_EQ(3, ball.use_count());
118 world.
addToObject(
"ball2", ball, Eigen::Isometry3d(Eigen::Translation3d(0, 0, 4)));
120 EXPECT_EQ(2, box.use_count());
121 EXPECT_EQ(2, cyl.use_count());
122 EXPECT_EQ(4, ball.use_count());
127 EXPECT_EQ(2, box.use_count());
128 EXPECT_EQ(1, cyl.use_count());
129 EXPECT_EQ(4, ball.use_count());
132 EXPECT_FALSE(rm_cyl);
134 EXPECT_EQ(2, box.use_count());
135 EXPECT_EQ(1, cyl.use_count());
136 EXPECT_EQ(4, ball.use_count());
140 EXPECT_EQ(3u, world.
size());
143 World::ObjectConstPtr obj = world.
getObject(
"mix1");
144 EXPECT_EQ(2, obj.use_count());
146 ASSERT_EQ(2u, obj->shapes_.size());
147 ASSERT_EQ(2u, obj->shape_poses_.size());
150 EXPECT_EQ(1.0, obj->shape_poses_[0](2, 3));
151 EXPECT_EQ(3.0, obj->shape_poses_[1](2, 3));
153 move_ok = world.
moveShapeInObject(
"mix1", ball, Eigen::Isometry3d(Eigen::Translation3d(0, 0, 5)));
154 EXPECT_TRUE(move_ok);
156 World::ObjectConstPtr obj2 = world.
getObject(
"mix1");
157 EXPECT_EQ(2, obj2.use_count());
158 EXPECT_EQ(1, obj.use_count());
160 EXPECT_EQ(1.0, obj2->shape_poses_[0](2, 3));
161 EXPECT_EQ(5.0, obj2->shape_poses_[1](2, 3));
163 EXPECT_EQ(1.0, obj->shape_poses_[0](2, 3));
164 EXPECT_EQ(3.0, obj->shape_poses_[1](2, 3));
167 EXPECT_EQ(3, box.use_count());
168 EXPECT_EQ(1, cyl.use_count());
169 EXPECT_EQ(5, ball.use_count());
173 EXPECT_EQ(2u, world.
size());
176 EXPECT_EQ(3, box.use_count());
177 EXPECT_EQ(1, cyl.use_count());
178 EXPECT_EQ(5, ball.use_count());
184 World::ObjectConstPtr obj3 = world.
getObject(
"abc");
188 EXPECT_EQ(1, box.use_count());
189 EXPECT_EQ(1, cyl.use_count());
190 EXPECT_EQ(3, ball.use_count());
192 EXPECT_EQ(2u, world.
size());
196 EXPECT_EQ(1, box.use_count());
197 EXPECT_EQ(1, cyl.use_count());
198 EXPECT_EQ(1, ball.use_count());
204 EXPECT_EQ(0u, world.
size());
220 obj_.shapes_.clear();
221 obj_.shape_poses_.clear();
241 return trackChangesNotify(ta,
object,
action);
245 shapes::ShapePtr ball = std::make_shared<shapes::Sphere>(1.0);
246 shapes::ShapePtr box = std::make_shared<shapes::Box>(1, 2, 3);
247 shapes::ShapePtr cyl = std::make_shared<shapes::Cylinder>(4, 5);
249 world.
addToObject(
"obj1", ball, Eigen::Isometry3d::Identity());
251 EXPECT_EQ(1, ta.
cnt_);
252 EXPECT_EQ(
"obj1", ta.
obj_.
id_);
256 bool move_ok = world.
moveShapeInObject(
"obj1", ball, Eigen::Isometry3d(Eigen::Translation3d(0, 0, 1)));
257 EXPECT_TRUE(move_ok);
259 EXPECT_EQ(2, ta.
cnt_);
260 EXPECT_EQ(
"obj1", ta.
obj_.
id_);
264 world.
addToObject(
"obj1", box, Eigen::Isometry3d::Identity());
266 EXPECT_EQ(3, ta.
cnt_);
267 EXPECT_EQ(
"obj1", ta.
obj_.
id_);
274 return trackChangesNotify(ta2,
object,
action);
277 world.
addToObject(
"obj2", cyl, Eigen::Isometry3d::Identity());
279 EXPECT_EQ(4, ta.
cnt_);
280 EXPECT_EQ(
"obj2", ta.
obj_.
id_);
283 EXPECT_EQ(1, ta2.
cnt_);
284 EXPECT_EQ(
"obj2", ta2.
obj_.
id_);
288 world.
addToObject(
"obj3", box, Eigen::Isometry3d::Identity());
290 EXPECT_EQ(5, ta.
cnt_);
291 EXPECT_EQ(
"obj3", ta.
obj_.
id_);
294 EXPECT_EQ(2, ta2.
cnt_);
295 EXPECT_EQ(
"obj3", ta2.
obj_.
id_);
301 EXPECT_FALSE(rm_bad);
302 EXPECT_EQ(5, ta.
cnt_);
303 EXPECT_EQ(2, ta2.
cnt_);
307 EXPECT_FALSE(rm_bad);
308 EXPECT_EQ(5, ta.
cnt_);
309 EXPECT_EQ(2, ta2.
cnt_);
314 return trackChangesNotify(ta3,
object,
action);
318 EXPECT_TRUE(rm_good);
320 EXPECT_EQ(6, ta.
cnt_);
321 EXPECT_EQ(
"obj2", ta.
obj_.
id_);
324 EXPECT_EQ(3, ta2.
cnt_);
325 EXPECT_EQ(
"obj2", ta2.
obj_.
id_);
328 EXPECT_EQ(1, ta3.
cnt_);
329 EXPECT_EQ(
"obj2", ta3.
obj_.
id_);
336 EXPECT_TRUE(rm_good);
338 EXPECT_EQ(7, ta.
cnt_);
339 EXPECT_EQ(
"obj1", ta.
obj_.
id_);
342 EXPECT_EQ(3, ta2.
cnt_);
344 EXPECT_EQ(2, ta3.
cnt_);
345 EXPECT_EQ(
"obj1", ta3.
obj_.
id_);
352 EXPECT_EQ(9, ta.
cnt_);
355 EXPECT_EQ(3, ta2.
cnt_);
357 EXPECT_EQ(4, ta3.
cnt_);
364 EXPECT_EQ(9, ta.
cnt_);
365 EXPECT_EQ(3, ta2.
cnt_);
366 EXPECT_EQ(4, ta3.
cnt_);
368 world.
addToObject(
"obj4", box, Eigen::Isometry3d::Identity());
370 EXPECT_EQ(9, ta.
cnt_);
371 EXPECT_EQ(3, ta2.
cnt_);
372 EXPECT_EQ(4, ta3.
cnt_);
382 return trackChangesNotify(ta,
object,
action);
386 shapes::ShapePtr ball = std::make_shared<shapes::Sphere>(1.0);
387 shapes::ShapePtr box = std::make_shared<shapes::Box>(1, 1, 1);
388 shapes::ShapePtr cyl = std::make_shared<shapes::Cylinder>(0.5, 3);
393 EXPECT_EQ(1, ta.
cnt_);
394 EXPECT_EQ(
"mix1", ta.
obj_.
id_);
398 world.
addToObject(
"mix1", box, Eigen::Isometry3d::Identity());
399 world.
addToObject(
"mix1", cyl, Eigen::Isometry3d(Eigen::Translation3d(0, 0, 2)));
402 subframes[
"frame1"] = Eigen::Isometry3d(Eigen::Translation3d(0, 0, 2));
403 subframes[
"frame2"] = Eigen::Isometry3d(Eigen::Translation3d(0, 1, 0));
407 bool found_ok, found_bad;
408 Eigen::Isometry3d pose = world.
getTransform(
"mix1/frame1", found_ok);
409 EXPECT_TRUE(found_ok);
410 EXPECT_EQ(2.0, pose(2, 3));
413 EXPECT_TRUE(found_ok);
414 EXPECT_EQ(1.0, pose(1, 3));
415 EXPECT_EQ(0.0, pose(2, 3));
418 EXPECT_FALSE(found_bad);
421 world.
setObjectPose(
"mix1", Eigen::Isometry3d(Eigen::Translation3d(0, 0, 1)));
424 EXPECT_TRUE(found_ok);
425 EXPECT_EQ(3.0, pose(2, 3));
428 EXPECT_TRUE(found_ok);
429 EXPECT_EQ(1.0, pose(1, 3));
430 EXPECT_EQ(1.0, pose(2, 3));
433 EXPECT_TRUE(found_ok);
434 EXPECT_EQ(1.0, pose(2, 3));
436 World::ObjectConstPtr obj = world.
getObject(
"mix1");
437 EXPECT_EQ(0.0, obj->shape_poses_[0](2, 3));
438 EXPECT_EQ(2.0, obj->shape_poses_[1](2, 3));
441 world.
moveObject(
"mix1", Eigen::Isometry3d(Eigen::Translation3d(0, 0, 1)));
444 EXPECT_TRUE(found_ok);
445 EXPECT_EQ(2.0, pose(2, 3));
448 EXPECT_TRUE(found_ok);
449 EXPECT_EQ(4.0, pose(2, 3));
451 EXPECT_EQ(0.0, obj->shape_poses_[0](2, 3));
452 EXPECT_EQ(2.0, obj->shape_poses_[1](2, 3));
455 world.
setObjectPose(
"mix1", Eigen::Isometry3d(Eigen::Translation3d(0, 0, 1)));
457 EXPECT_TRUE(found_ok);
458 EXPECT_EQ(1.0, pose(2, 3));
461 int main(
int argc,
char** argv)
463 testing::InitGoogleTest(&argc, argv);
464 return RUN_ALL_TESTS();
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
Maintain a representation of the environment.
const Eigen::Isometry3d & getTransform(const std::string &name) const
Get the transform to an object or subframe with given name. If name does not exist,...
void removeObserver(const ObserverHandle observer_handle)
remove a notifier callback
bool hasObject(const std::string &object_id) const
Check if a particular object exists in the collision world.
bool removeObject(const std::string &object_id)
Remove a particular object. If there are no external pointers to the corresponding instance of Object...
bool moveShapeInObject(const std::string &object_id, const shapes::ShapeConstPtr &shape, const Eigen::Isometry3d &shape_pose)
Update the pose of a shape in an object. Shape equality is verified by comparing pointers....
bool removeShapeFromObject(const std::string &object_id, const shapes::ShapeConstPtr &shape)
Remove shape from object. Shape equality is verified by comparing pointers. Ownership of the object i...
const Eigen::Isometry3d & getGlobalShapeTransform(const std::string &object_id, int shape_index) const
Get the global transform to a shape of an object with multiple shapes. shape_index is the index of th...
void addToObject(const std::string &object_id, const Eigen::Isometry3d &pose, const std::vector< shapes::ShapeConstPtr > &shapes, const EigenSTL::vector_Isometry3d &shape_poses)
Add a pose and shapes to an object in the map. This function makes repeated calls to addToObjectInter...
bool moveObject(const std::string &object_id, const Eigen::Isometry3d &transform)
Move the object pose (thus moving all shapes and subframes in the object) according to the given tran...
ObserverHandle addObserver(const ObserverCallbackFn &callback)
register a callback function for notification of changes. callback will be called right after any cha...
bool setObjectPose(const std::string &object_id, const Eigen::Isometry3d &pose)
Set the pose of an object. The pose is specified in the world frame.
bool setSubframesOfObject(const std::string &object_id, const moveit::core::FixedTransformsMap &subframe_poses)
Set subframes on an object. The frames are relative to the object pose.
void clearObjects()
Clear all objects. If there are no other pointers to corresponding instances of Objects,...
ObjectConstPtr getObject(const std::string &object_id) const
Get a particular object.
std::map< std::string, Eigen::Isometry3d, std::less< std::string >, Eigen::aligned_allocator< std::pair< const std::string, Eigen::Isometry3d > > > FixedTransformsMap
Map frame names to the transformation matrix that can transform objects from the frame name to the pl...
A representation of an object.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::string id_
The id for this object.
TEST(World, AddRemoveShape)
int main(int argc, char **argv)