27#include <pcl/common/colors.h>
28#include <pcl/point_types.h>
30#include <VirtualRobot/MathTools.h>
46 primitiveColorFrame = viz::Color::blue(150, 200);
70 std::unique_lock<std::mutex> lock(mutex, std::try_to_lock);
72 if (!lock.owns_lock())
75 <<
"unable to process new geometric primitives. already processing previous "
84 std::vector<memoryx::EnvironmentalPrimitiveBasePtr> primitives =
86 for (memoryx::EnvironmentalPrimitiveBasePtr& primitive : primitives)
88 viz::Color color = getPrimitiveColor(primitive);
89 visualizePrimitive(primitive, color);
92 arviz.commit({layer});
96PrimitiveVisualization::getPrimitiveColor(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive)
98 if (primitive->getLabel())
101 pcl::RGB
c = pcl::GlasbeyLUT::at(primitive->getLabel() % pcl::GlasbeyLUT::size());
110 return viz::Color::blue(128, 128);
115PrimitiveVisualization::visualizePrimitive(
const memoryx::EnvironmentalPrimitiveBasePtr& primitive,
118 if (primitive->ice_isA(memoryx::PlanePrimitiveBase::ice_staticId()))
120 visualizePlane(memoryx::PlanePrimitiveBasePtr::dynamicCast(primitive), color);
122 else if (primitive->ice_isA(memoryx::SpherePrimitiveBase::ice_staticId()))
124 visualizeSphere(memoryx::SpherePrimitiveBasePtr::dynamicCast(primitive), color);
126 else if (primitive->ice_isA(memoryx::CylinderPrimitiveBase::ice_staticId()))
128 visualizeCylinder(memoryx::CylinderPrimitiveBasePtr::dynamicCast(primitive), color);
132 ARMARX_WARNING <<
"Cannot visualize unknown primitive type: " << primitive->getName();
138PrimitiveVisualization::visualizePlane(
const memoryx::PlanePrimitiveBasePtr& plane,
144 Eigen::Matrix4f pose = FramedPosePtr::dynamicCast(p->getPose())->toEigen();
145 Eigen::Vector3f dimensions = Vector3Ptr::dynamicCast(p->getOBBDimensions())->toEigen();
153 viz::Box box(p->getId());
154 box.size(dimensions);
163 viz::Polygon rectangle(p->getId());
165 rectangle.color(color);
166 rectangle.lineColor(primitiveColorFrame);
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)));
175 rectangle.addPoint(Eigen::Vector3f(
176 (pose * Eigen::Vector4f(-dimensions.x() / 2, dimensions.y() / 2, 0, 1)).head(3)));
179 layer.add(rectangle);
184 viz::Polygon polygon(p->getId());
185 polygon.color(color);
186 polygon.lineColor(primitiveColorFrame);
188 for (
const Vector3BasePtr& v : p->getGraspPoints())
190 polygon.addPoint(Vector3Ptr::dynamicCast(v)->
toEigen());
198 viz::PointCloud cloud(p->getId());
200 for (
const armarx::Vector3BasePtr& v : p->getInliers())
203 cloud.addPoint(
v->x,
v->y,
v->z);
211PrimitiveVisualization::visualizeSphere(
const memoryx::SpherePrimitiveBasePtr& sphere,
216 Eigen::Vector3f
center = Vector3Ptr::dynamicCast(p->getSphereCenter())->toEigen();
217 float radius = p->getSphereRadius();
219 viz::Sphere
s(p->getId());
228PrimitiveVisualization::visualizeCylinder(
const memoryx::CylinderPrimitiveBasePtr& cylinder,
232 Eigen::Vector3f
center = Vector3Ptr::dynamicCast(p->getCylinderPoint())->toEigen();
233 Eigen::Vector3f direction = Vector3Ptr::dynamicCast(p->getCylinderAxisDirection())->toEigen();
235 float radius = p->getCylinderRadius();
236 float length = p->getLength();
238 viz::Cylinder
c(p->getId());
241 c.direction(direction);
256 return "PrimitiveVisualization";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
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)
Brief description of class PrimitiveVisualization.
void onInitComponent() override
void onDisconnectComponent() override
void reportNewPointCloudSegmentation(const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
static std::string GetDefaultName()
memoryx::WorkingMemoryInterfacePrx workingMemory
void onExitComponent() override
memoryx::EnvironmentalPrimitiveSegmentBasePrx environmentalPrimitiveSegment
std::string getDefaultName() const override
Retrieve default name of component.
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