25 #include <AffordanceKit/primitives/Plane.h>
26 #include <AffordanceKit/primitives/Cylinder.h>
27 #include <AffordanceKit/primitives/Sphere.h>
28 #include <AffordanceKit/primitives/Box.h>
48 for (
auto& primitive : *primitiveSet)
56 memoryx::PlanePrimitiveBaseList planes;
57 memoryx::CylinderPrimitiveBaseList cylinders;
58 memoryx::SpherePrimitiveBaseList spheres;
59 memoryx::BoxPrimitiveBaseList boxes;
64 planes = segment->getMostRecentPlanes();
65 cylinders = segment->getMostRecentCylinders();
66 spheres = segment->getMostRecentSpheres();
67 boxes = segment->getMostRecentBoxes();
78 for (
auto& primitive : planes)
80 memoryx::PointList originalPoints = primitive->getGraspPoints();
82 std::vector<Eigen::Vector3f>
convexHull(originalPoints.size());
83 for (
unsigned int i = 0; i < originalPoints.size(); i++)
85 convexHull[i] = armarx::Vector3Ptr::dynamicCast(originalPoints[i])->toEigen();
88 AffordanceKit::PrimitivePtr plane(
new AffordanceKit::Plane(
convexHull));
89 plane->setId(primitive->getId());
90 plane->setSampling(armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
91 plane->setTimestamp(primitive->getTime()->timestamp);
92 plane->setLabel(primitive->getLabel());
97 for (
auto& primitive : cylinders)
99 Eigen::Vector3f basePoint = armarx::Vector3Ptr::dynamicCast(primitive->getCylinderPoint())->toEigen();
100 Eigen::Vector3f direction = armarx::Vector3Ptr::dynamicCast(primitive->getCylinderAxisDirection())->toEigen();
102 AffordanceKit::PrimitivePtr cylinder(
new AffordanceKit::Cylinder(basePoint, direction, primitive->getLength(), primitive->getCylinderRadius()));
103 cylinder->setId(primitive->getId());
104 cylinder->setSampling(armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
105 cylinder->setTimestamp(primitive->getTime()->timestamp);
106 cylinder->setLabel(primitive->getLabel());
111 for (
auto& primitive : spheres)
113 Eigen::Vector3f center = armarx::Vector3Ptr::dynamicCast(primitive->getSphereCenter())->toEigen();
115 AffordanceKit::PrimitivePtr sphere(
new AffordanceKit::Sphere(center, primitive->getSphereRadius()));
116 sphere->setId(primitive->getId());
117 sphere->setTimestamp(primitive->getTime()->timestamp);
118 sphere->setSampling(armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
123 for (
auto& primitive : boxes)
125 Eigen::Matrix4f pose = armarx::PosePtr::dynamicCast(primitive->getPose())->toEigen();
126 Eigen::Vector3f dimensions = armarx::Vector3Ptr::dynamicCast(primitive->getOBBDimensions())->toEigen();
128 AffordanceKit::PrimitivePtr box(
new AffordanceKit::Box(pose, dimensions));
129 box->setId(primitive->getId());
130 box->setTimestamp(primitive->getTime()->timestamp);
131 box->setSampling(armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
144 std::vector<memoryx::EntityBasePtr> newPrimitives;
145 for (
auto& primitive : *
this)
147 memoryx::EnvironmentalPrimitiveBasePtr p;
149 if (AffordanceKit::Plane* pl =
dynamic_cast<AffordanceKit::Plane*
>(primitive.get()))
151 const std::vector<Eigen::Vector3f>& ch = pl->getConvexHull();
163 else if (AffordanceKit::Cylinder*
c =
dynamic_cast<AffordanceKit::Cylinder*
>(primitive.get()))
166 p2->setCylinderRadius(
c->getRadius());
169 p2->setLength(
c->getLength());
173 else if (AffordanceKit::Sphere*
s =
dynamic_cast<AffordanceKit::Sphere*
>(primitive.get()))
177 p2->setSphereRadius(
s->getRadius());
181 else if (AffordanceKit::Box* b =
dynamic_cast<AffordanceKit::Box*
>(primitive.get()))
190 p->setName(
"environmentalPrimitive_" + primitive->getId());
191 p->setId(primitive->getId());
193 ARMARX_INFO <<
"Writing primitive to memory: ID=" << p->getId() <<
", name=" << p->getName();
194 p->setCircularityProbability(primitive->isCircular());
196 p->setLabel(primitive->getLabel());
202 newPrimitives.push_back(p);
205 segment->upsertEntityList(newPrimitives);