30 #include <VirtualRobot/MathTools.h>
32 #include <pcl/point_types.h>
33 #include <pcl/common/colors.h>
43 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
51 workingMemory = getProxy<memoryx::WorkingMemoryInterfacePrx>(getProperty<std::string>(
"WorkingMemoryName").getValue());
71 std::unique_lock<std::mutex> lock(mutex, std::try_to_lock);
73 if (!lock.owns_lock())
75 ARMARX_INFO <<
deactivateSpam(3) <<
"unable to process new geometric primitives. already processing previous primitive set.";
83 for (memoryx::EnvironmentalPrimitiveBasePtr& primitive : primitives)
85 viz::Color color = getPrimitiveColor(primitive);
86 visualizePrimitive(primitive, color);
93 viz::Color PrimitiveVisualization::getPrimitiveColor(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive)
95 if (primitive->getLabel())
98 pcl::RGB
c = pcl::GlasbeyLUT::at(primitive->getLabel() % pcl::GlasbeyLUT::size());
114 void PrimitiveVisualization::visualizePrimitive(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive,
viz::Color color)
116 if (primitive->ice_isA(memoryx::PlanePrimitiveBase::ice_staticId()))
118 visualizePlane(memoryx::PlanePrimitiveBasePtr::dynamicCast(primitive), color);
120 else if (primitive->ice_isA(memoryx::SpherePrimitiveBase::ice_staticId()))
122 visualizeSphere(memoryx::SpherePrimitiveBasePtr::dynamicCast(primitive), color);
124 else if (primitive->ice_isA(memoryx::CylinderPrimitiveBase::ice_staticId()))
126 visualizeCylinder(memoryx::CylinderPrimitiveBasePtr::dynamicCast(primitive), color);
130 ARMARX_WARNING <<
"Cannot visualize unknown primitive type: " << primitive->getName();
135 void PrimitiveVisualization::visualizePlane(
const memoryx::PlanePrimitiveBasePtr& plane,
viz::Color color)
140 Eigen::Matrix4f pose = FramedPosePtr::dynamicCast(p->getPose())->toEigen();
141 Eigen::Vector3f dimensions = Vector3Ptr::dynamicCast(p->getOBBDimensions())->toEigen();
144 if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
Obb)
150 box.size(dimensions);
157 else if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
Rectangle)
161 rectangle.color(color);
162 rectangle.lineColor(primitiveColorFrame);
165 rectangle.addPoint(Eigen::Vector3f((pose * Eigen::Vector4f(dimensions.x() / 2, dimensions.y() / 2, 0, 1)).head(3)));
166 rectangle.addPoint(Eigen::Vector3f((pose * Eigen::Vector4f(dimensions.x() / 2, -dimensions.y() / 2, 0, 1)).head(3)));
167 rectangle.addPoint(Eigen::Vector3f((pose * Eigen::Vector4f(-dimensions.x() / 2, -dimensions.y() / 2, 0, 1)).head(3)));
168 rectangle.addPoint(Eigen::Vector3f((pose * Eigen::Vector4f(-dimensions.x() / 2, dimensions.y() / 2, 0, 1)).head(3)));
171 layer.
add(rectangle);
174 else if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
Hull)
178 polygon.color(color);
179 polygon.lineColor(primitiveColorFrame);
181 for (
const Vector3BasePtr&
v : p->getGraspPoints())
183 polygon.addPoint(Vector3Ptr::dynamicCast(
v)->
toEigen());
188 else if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
Inlier)
192 for (
const armarx::Vector3BasePtr&
v : p->getInliers())
195 cloud.addPoint(
v->x,
v->y,
v->z);
203 void PrimitiveVisualization::visualizeSphere(
const memoryx::SpherePrimitiveBasePtr& sphere,
viz::Color color)
207 Eigen::Vector3f center = Vector3Ptr::dynamicCast(p->getSphereCenter())->toEigen();
208 float radius = p->getSphereRadius();
218 void PrimitiveVisualization::visualizeCylinder(
const memoryx::CylinderPrimitiveBasePtr& cylinder,
viz::Color color)
221 Eigen::Vector3f center = Vector3Ptr::dynamicCast(p->getCylinderPoint())->toEigen();
222 Eigen::Vector3f direction = Vector3Ptr::dynamicCast(p->getCylinderAxisDirection())->toEigen();
224 float radius = p->getCylinderRadius();
225 float length = p->getLength();
230 c.direction(direction);