32 #include <AffordanceKit/primitives/Box.h>
33 #include <AffordanceKit/primitives/Cylinder.h>
34 #include <AffordanceKit/primitives/Plane.h>
35 #include <AffordanceKit/primitives/Sphere.h>
47 for (
auto& primitive : *primitiveSet)
54 const memoryx::EnvironmentalPrimitiveSegmentBasePrx& segment,
57 memoryx::PlanePrimitiveBaseList planes;
58 memoryx::CylinderPrimitiveBaseList cylinders;
59 memoryx::SpherePrimitiveBaseList spheres;
60 memoryx::BoxPrimitiveBaseList boxes;
65 planes = segment->getMostRecentPlanes();
66 cylinders = segment->getMostRecentCylinders();
67 spheres = segment->getMostRecentSpheres();
68 boxes = segment->getMostRecentBoxes();
79 for (
auto& primitive : planes)
81 memoryx::PointList originalPoints = primitive->getGraspPoints();
83 std::vector<Eigen::Vector3f>
convexHull(originalPoints.size());
84 for (
unsigned int i = 0; i < originalPoints.size(); i++)
86 convexHull[i] = armarx::Vector3Ptr::dynamicCast(originalPoints[i])->toEigen();
89 AffordanceKit::PrimitivePtr plane(
new AffordanceKit::Plane(
convexHull));
90 plane->setId(primitive->getId());
92 armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
93 plane->setTimestamp(primitive->getTime()->timestamp);
94 plane->setLabel(primitive->getLabel());
99 for (
auto& primitive : cylinders)
101 Eigen::Vector3f basePoint =
102 armarx::Vector3Ptr::dynamicCast(primitive->getCylinderPoint())->toEigen();
103 Eigen::Vector3f direction =
104 armarx::Vector3Ptr::dynamicCast(primitive->getCylinderAxisDirection())->toEigen();
106 AffordanceKit::PrimitivePtr cylinder(
new AffordanceKit::Cylinder(
107 basePoint, direction, primitive->getLength(), primitive->getCylinderRadius()));
108 cylinder->setId(primitive->getId());
109 cylinder->setSampling(
110 armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
111 cylinder->setTimestamp(primitive->getTime()->timestamp);
112 cylinder->setLabel(primitive->getLabel());
117 for (
auto& primitive : spheres)
119 Eigen::Vector3f center =
120 armarx::Vector3Ptr::dynamicCast(primitive->getSphereCenter())->toEigen();
122 AffordanceKit::PrimitivePtr sphere(
123 new AffordanceKit::Sphere(center, primitive->getSphereRadius()));
124 sphere->setId(primitive->getId());
125 sphere->setTimestamp(primitive->getTime()->timestamp);
127 armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
132 for (
auto& primitive : boxes)
134 Eigen::Matrix4f pose = armarx::PosePtr::dynamicCast(primitive->getPose())->toEigen();
135 Eigen::Vector3f dimensions =
136 armarx::Vector3Ptr::dynamicCast(primitive->getOBBDimensions())->toEigen();
138 AffordanceKit::PrimitivePtr box(
new AffordanceKit::Box(pose, dimensions));
139 box->setId(primitive->getId());
140 box->setTimestamp(primitive->getTime()->timestamp);
142 armarx::MatrixFloatPtr::dynamicCast(primitive->getSampling())->toEigen());
149 const memoryx::EnvironmentalPrimitiveSegmentBasePrx& segment)
const
157 std::vector<memoryx::EntityBasePtr> newPrimitives;
158 for (
auto& primitive : *
this)
160 memoryx::EnvironmentalPrimitiveBasePtr p;
162 if (AffordanceKit::Plane* pl =
dynamic_cast<AffordanceKit::Plane*
>(primitive.get()))
164 const std::vector<Eigen::Vector3f>& ch = pl->getConvexHull();
176 else if (AffordanceKit::Cylinder*
c =
177 dynamic_cast<AffordanceKit::Cylinder*
>(primitive.get()))
180 p2->setCylinderRadius(
c->getRadius());
183 p2->setLength(
c->getLength());
187 else if (AffordanceKit::Sphere*
s =
188 dynamic_cast<AffordanceKit::Sphere*
>(primitive.get()))
192 p2->setSphereRadius(
s->getRadius());
196 else if (AffordanceKit::Box* b =
dynamic_cast<AffordanceKit::Box*
>(primitive.get()))
205 p->setName(
"environmentalPrimitive_" + primitive->getId());
206 p->setId(primitive->getId());
208 ARMARX_INFO <<
"Writing primitive to memory: ID=" << p->getId()
209 <<
", name=" << p->getName();
210 p->setCircularityProbability(primitive->isCircular());
212 p->setLabel(primitive->getLabel());
218 newPrimitives.push_back(p);
221 segment->upsertEntityList(newPrimitives);