25#include <pcl/common/colors.h>
26#include <pcl/point_types.h>
28#include <VirtualRobot/MathTools.h>
44 primitiveColorFrame = viz::Color::blue(150, 200);
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);
90 arviz.commit({layer});
94PrimitiveVisualization::getPrimitiveColor(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive)
96 if (primitive->getLabel())
99 pcl::RGB
c = pcl::GlasbeyLUT::at(primitive->getLabel() % pcl::GlasbeyLUT::size());
108 return viz::Color::blue(128, 128);
113PrimitiveVisualization::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();
136PrimitiveVisualization::visualizePlane(
const memoryx::PlanePrimitiveBasePtr& plane,
142 Eigen::Matrix4f pose = FramedPosePtr::dynamicCast(p->getPose())->toEigen();
143 Eigen::Vector3f dimensions = Vector3Ptr::dynamicCast(p->getOBBDimensions())->toEigen();
151 viz::Box box(p->getId());
152 box.size(dimensions);
161 viz::Polygon rectangle(p->getId());
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);
182 viz::Polygon polygon(p->getId());
183 polygon.color(color);
184 polygon.lineColor(primitiveColorFrame);
186 for (
const Vector3BasePtr& v : p->getGraspPoints())
188 polygon.addPoint(Vector3Ptr::dynamicCast(v)->
toEigen());
196 viz::PointCloud cloud(p->getId());
198 for (
const armarx::Vector3BasePtr& v : p->getInliers())
201 cloud.addPoint(
v->x,
v->y,
v->z);
209PrimitiveVisualization::visualizeSphere(
const memoryx::SpherePrimitiveBasePtr& sphere,
214 Eigen::Vector3f
center = Vector3Ptr::dynamicCast(p->getSphereCenter())->toEigen();
215 float radius = p->getSphereRadius();
217 viz::Sphere
s(p->getId());
226PrimitiveVisualization::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();
236 viz::Cylinder
c(p->getId());
239 c.direction(direction);
armarx::viz::Client arviz
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void onInitComponent() override
void onDisconnectComponent() override
void reportNewPointCloudSegmentation(const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
memoryx::WorkingMemoryInterfacePrx workingMemory
void onExitComponent() override
memoryx::EnvironmentalPrimitiveSegmentBasePrx environmentalPrimitiveSegment
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
double s(double t, double s0, double v0, double a0, double j)
double v(double t, double v0, double a0, double j)
state::Type center(state::Type previous)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)
IceInternal::Handle< SpherePrimitive > SpherePrimitivePtr
IceInternal::Handle< PlanePrimitive > PlanePrimitivePtr
IceInternal::Handle< CylinderPrimitive > CylinderPrimitivePtr