25 #include <pcl/common/colors.h>
26 #include <pcl/point_types.h>
28 #include <VirtualRobot/MathTools.h>
42 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
51 getProperty<std::string>(
"WorkingMemoryName").getValue());
68 std::unique_lock<std::mutex> lock(mutex, std::try_to_lock);
70 if (!lock.owns_lock())
73 <<
"unable to process new geometric primitives. already processing previous "
82 std::vector<memoryx::EnvironmentalPrimitiveBasePtr> primitives =
84 for (memoryx::EnvironmentalPrimitiveBasePtr& primitive : primitives)
86 viz::Color color = getPrimitiveColor(primitive);
87 visualizePrimitive(primitive, color);
94 PrimitiveVisualization::getPrimitiveColor(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive)
96 if (primitive->getLabel())
99 pcl::RGB
c = pcl::GlasbeyLUT::at(primitive->getLabel() % pcl::GlasbeyLUT::size());
113 PrimitiveVisualization::visualizePrimitive(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive,
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();
136 PrimitiveVisualization::visualizePlane(
const memoryx::PlanePrimitiveBasePtr& plane,
142 Eigen::Matrix4f pose = FramedPosePtr::dynamicCast(p->getPose())->toEigen();
143 Eigen::Vector3f dimensions = Vector3Ptr::dynamicCast(p->getOBBDimensions())->toEigen();
146 if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
Obb)
152 box.size(dimensions);
158 else if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
163 rectangle.color(color);
164 rectangle.lineColor(primitiveColorFrame);
167 rectangle.addPoint(Eigen::Vector3f(
168 (pose * Eigen::Vector4f(dimensions.x() / 2, dimensions.y() / 2, 0, 1)).head(3)));
169 rectangle.addPoint(Eigen::Vector3f(
170 (pose * Eigen::Vector4f(dimensions.x() / 2, -dimensions.y() / 2, 0, 1)).head(3)));
171 rectangle.addPoint(Eigen::Vector3f(
172 (pose * Eigen::Vector4f(-dimensions.x() / 2, -dimensions.y() / 2, 0, 1)).head(3)));
173 rectangle.addPoint(Eigen::Vector3f(
174 (pose * Eigen::Vector4f(-dimensions.x() / 2, dimensions.y() / 2, 0, 1)).head(3)));
177 layer.
add(rectangle);
179 else if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
Hull)
183 polygon.color(color);
184 polygon.lineColor(primitiveColorFrame);
186 for (
const Vector3BasePtr&
v : p->getGraspPoints())
188 polygon.addPoint(Vector3Ptr::dynamicCast(
v)->
toEigen());
193 else if (getProperty<PLANE_VISUALIZATION_METHOD>(
"PlaneVisualizationMethod").
getValue() ==
198 for (
const armarx::Vector3BasePtr&
v : p->getInliers())
201 cloud.addPoint(
v->x,
v->y,
v->z);
209 PrimitiveVisualization::visualizeSphere(
const memoryx::SpherePrimitiveBasePtr& sphere,
214 Eigen::Vector3f
center = Vector3Ptr::dynamicCast(p->getSphereCenter())->toEigen();
215 float radius = p->getSphereRadius();
226 PrimitiveVisualization::visualizeCylinder(
const memoryx::CylinderPrimitiveBasePtr& cylinder,
230 Eigen::Vector3f
center = Vector3Ptr::dynamicCast(p->getCylinderPoint())->toEigen();
231 Eigen::Vector3f direction = Vector3Ptr::dynamicCast(p->getCylinderAxisDirection())->toEigen();
233 float radius = p->getCylinderRadius();
234 float length = p->getLength();
239 c.direction(direction);