27#include <pcl/common/transforms.h>
28#include <pcl/filters/approximate_voxel_grid.h>
34#include <VisionX/interface/components/Calibration.h>
35#include <VisionX/interface/core/PointCloudProcessorInterface.h>
37#define call_template_function(F) \
38 switch (_pointCloudProviderInfo.pointCloudFormat->type) \
40 case visionx::PointContentType::ePoints: \
43 case visionx::PointContentType::eColoredPoints: \
44 F<pcl::PointXYZRGBA>(); \
46 case visionx::PointContentType::eColoredOrientedPoints: \
47 F<pcl::PointXYZRGBNormal>(); \
49 case visionx::PointContentType::eLabeledPoints: \
50 F<pcl::PointXYZL>(); \
52 case visionx::PointContentType::eColoredLabeledPoints: \
53 F<pcl::PointXYZRGBL>(); \
55 case visionx::PointContentType::eIntensity: \
56 F<pcl::PointXYZI>(); \
58 case visionx::PointContentType::eOrientedPoints: \
59 ARMARX_ERROR << "eOrientedPoints NOT HANDLED IN VISIONX"; \
62 ARMARX_ERROR << "Could not call " #F ", because format '" \
63 << _pointCloudProviderInfo.pointCloudFormat->type << "' is unknown"; \
75 return "MultiViewPointCloudProcessor";
89 prop->defineOptionalProperty<std::string>(
90 "ProviderReferenceFrame",
92 "Name of the point cloud refence frame (empty = autodetect)");
93 std::lock_guard guard{_cfgBufWriteMutex};
94 prop->optional(_cfgBuf.getWriteBuffer(),
"",
"");
107 std::lock_guard guard{_cfgBufWriteMutex};
121 std::lock_guard guard{_cfgBufWriteMutex};
123 prx.
getValue(_cfgBuf.getWriteBuffer(),
"cfg");
137 _cfgBuf.commitWrite();
157 _pointCloudProvider = _pointCloudProviderInfo.proxy;
159 if (_pointCloudProviderRefFrame.empty())
161 _pointCloudProviderRefFrame =
"root";
163 visionx::ReferenceFrameInterfacePrx::checkedCast(_pointCloudProvider);
166 _pointCloudProviderRefFrame = frameprov->getReferenceFrame();
171 if (!_providerThread.joinable())
180 _robot =
addRobot(
"_robot", VirtualRobot::RobotIO::eStructure);
190 _stopProviding =
true;
191 _providerThread.join();
220 std::lock_guard guard{_cfgBufWriteMutex};
221 _cfgBuf.getWriteBuffer().maxNumberOfFramesPerViewPoint = n;
222 _cfgBuf.commitWrite();
228 std::lock_guard guard{_cfgBufWriteMutex};
229 _cfgBuf.getWriteBuffer().gridSize = s;
230 _cfgBuf.commitWrite();
236 std::lock_guard guard{_cfgBufWriteMutex};
237 _cfgBuf.getWriteBuffer().frameRate = r;
238 _cfgBuf.commitWrite();
251 template <
class Po
intType>
259 const auto doRecord = _doRecord.load();
262 std::lock_guard guard{_viewPointsMutex};
264 _currentViewpoint = doRecord ? 0 : -1;
271 const auto currentViewpoint = _currentViewpoint.load();
273 using cloud_t = pcl::PointCloud<PointType>;
274 using cloud_ptr_t =
typename cloud_t::Ptr;
276 std::unique_lock lock{_cfgBufReadMutex};
277 const auto buf = _cfgBuf.getUpToDateReadBuffer();
284 cloud_ptr_t transformedCloud;
289 <<
"Timeout or error while waiting for point cloud data of provider "
290 << _pointCloudProviderName;
293 cloud_ptr_t inputCloud(
new cloud_t);
297 const Eigen::Matrix4f providerInRootFrame = [&]() -> Eigen::Matrix4f
300 Eigen::Matrix4f::Identity(), _pointCloudProviderRefFrame, _robot->getName()};
305 transformedCloud = cloud_ptr_t(
new cloud_t);
306 pcl::transformPointCloud(*inputCloud, *transformedCloud, providerInRootFrame);
309 std::lock_guard guard{_viewPointsMutex};
310 const auto p =
static_cast<std::size_t
>(currentViewpoint);
311 if (p + 1 > _viewPoints.size())
313 _viewPoints.resize(p + 1);
315 _viewPoints.at(p).clouds.emplace_back(transformedCloud);
316 if (buf.maxNumberOfFramesPerViewPoint > 0)
318 while (_viewPoints.at(p).clouds.size() >
319 static_cast<std::size_t
>(buf.maxNumberOfFramesPerViewPoint))
321 _viewPoints.at(p).clouds.pop_front();
327 template <
class Po
intType>
331 using cloud_t = pcl::PointCloud<PointType>;
332 using cloud_ptr_t =
typename cloud_t::Ptr;
333 std::deque<std::uint64_t> idxVec;
334 while (!_stopProviding)
336 const auto timeBeg = std::chrono::high_resolution_clock::now();
338 std::unique_lock lock{_cfgBufReadMutex};
339 const auto buf = _cfgBuf.getUpToDateReadBuffer();
342 cloud_ptr_t cloud(
new cloud_t);
344 std::lock_guard guard{_viewPointsMutex};
345 if (idxVec.size() < _viewPoints.size())
347 idxVec.resize(_viewPoints.size());
349 for (std::size_t i = 0; i < idxVec.size(); ++i)
351 const auto& inVec = _viewPoints.at(i).clouds;
352 const auto idx = (idxVec.at(i)++) % inVec.size();
353 const auto& in = *std::any_cast<cloud_ptr_t>(inVec.at(idx));
354 auto& out = cloud->points;
355 out.insert(out.end(), in.begin(), in.end());
359 if (buf.gridSize > 0)
361 pcl::ApproximateVoxelGrid<PointType> grid;
362 grid.setLeafSize(Eigen::Vector3f::Constant(buf.gridSize));
363 grid.setInputCloud(cloud);
364 cloud_ptr_t tempCloud(
new cloud_t);
365 grid.filter(*tempCloud);
366 tempCloud.swap(cloud);
375 std::this_thread::sleep_until(timeBeg + std::chrono::milliseconds{dtms});
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void setDebugObserverDatafield(Ts &&... ts) const
void sendDebugObserverBatch()
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
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.
Brief description of class MultiViewPointCloudProcessor.
void stopRecordingViewPoint(const Ice::Current &=Ice::emptyCurrent) override
RemoteGui::WidgetPtr buildGui()
void clearViewPoints(const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
void startRecordingNextViewPoint(const Ice::Current &=Ice::emptyCurrent) override
void onConnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
static std::string GetDefaultName()
void setFrameRate(Ice::Float r, const Ice::Current &=Ice::emptyCurrent) override
void setDownsamplingGridSize(Ice::Float s, const Ice::Current &=Ice::emptyCurrent) override
void processGui(RemoteGui::TabProxy &prx)
void onInitPointCloudProcessor() override
Setup the vision component.
void setMaxNumberOfFramesPerViewPoint(Ice::Int n, const Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
void createOrUpdateRemoteGuiTab(Ts &&... ts)
bool getButtonClicked(std::string const &name)
ValueProxy< T > getValue(std::string const &name)
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
Properties of PointCloudProcessor.
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
void usingPointCloudProvider(std::string providerName)
Registers a delayed topic subscription and a delayed provider proxy retrieval which will be available...
PointCloudProviderInfo getPointCloudProvider(std::string name, bool waitForProxy=false)
Select an PointCloudProvider.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ON_SCOPE_EXIT
Executes given code when the enclosing scope is left.
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
detail::ButtonBuilder makeButton(std::string const &name)
RemoteGui::WidgetPtr MakeGuiConfig(const std::string &name, const T &val)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Derived & addChild(WidgetPtr const &child)