30#include <pcl/console/print.h>
38#include <VisionX/interface/components/Calibration.h>
53 resultPointCloudProviderName(
"ResultPointCloudProvider"),
54 pointContentType(PointContentType::eColoredPoints)
61 resultPointCloudProviderName = name;
67 return resultPointCloudProviderName;
73 this->shmCapacity = shmCapacity;
85 pointContentType = type;
91 return pointContentType;
104 MetaPointCloudFormatPtr
107 MetaPointCloudFormatPtr info =
new MetaPointCloudFormat();
108 info->capacity =
static_cast<Ice::Int
>(shmCapacity);
109 info->size =
static_cast<Ice::Int
>(shmCapacity);
110 info->type = pointContentType;
128 "Number of frames per second. If zero then this property is ignored.");
130 "AutomaticTypeConversion",
false,
"Automatically convert different point cloud types.");
132 "ProviderName",
"",
"Name(s) of the point cloud provider(s).");
142 pcl::console::setVerbosityLevel(pcl::console::L_VERBOSE);
145 pcl::console::setVerbosityLevel(pcl::console::L_DEBUG);
149 pcl::console::setVerbosityLevel(pcl::console::L_INFO);
152 pcl::console::setVerbosityLevel(pcl::console::L_WARN);
156 pcl::console::setVerbosityLevel(pcl::console::L_ERROR);
159 pcl::console::setVerbosityLevel(pcl::console::L_ALWAYS);
185 std::vector<std::string> providerNames =
188 for (
const std::string& providerName : providerNames)
190 if (providerName.empty())
193 <<
" contains an invalid value";
204 <<
"\nnot derive from PointCloudProcessorPropertyDefinitions. Consider"
206 <<
"'s properties from this class to get"
207 <<
"\ndefault point cloud processor properties, such as 'ProviderName', and"
208 <<
"\nthe respective features.";
271 std::this_thread::sleep_for(std::chrono::milliseconds(1));
284 usingTopic(providerName +
".PointCloudListener");
289 this, providerName,
"PointCloudProvider");
320 std::string memoryName = providerName +
"Memory" +
"PointCloudProvider";
332 ARMARX_INFO <<
"Point cloud provider already started: " << providerName;
341 ARMARX_DEBUG <<
"getProxy '" << providerName <<
"'...done!";
347 size_t pointCloudBufferSize =
static_cast<size_t>(providerInfo.
pointCloudFormat->size);
348 providerInfo.
buffer.resize(pointCloudBufferSize);
359 statistics[providerName].pointCloudProviderFPS.reset();
361 if (!providerInfo.
proxy->hasSharedMemorySupport())
363 ARMARX_IMPORTANT <<
"shared memory not available for provider " << providerName;
386 std::string providerName;
393 ARMARX_ERROR <<
"Calling getPointCloudProvider without "
394 <<
"PointCloudProvider name but using multiple "
395 <<
"PointCloudProviders";
403 std::vector<std::string>
406 std::vector<std::string> names;
410 names.push_back(name);
424 PointContentType pointContentType)
426 if (resultProviderName ==
"")
428 resultProviderName =
getName() +
"Result";
435 ARMARX_WARNING <<
"result point cloud provider already exists: " << resultProviderName;
441 resultProvider->setName(resultProviderName);
442 resultProvider->setShmCapacity(shmCapacity);
443 resultProvider->setPointContentType(pointContentType);
453 resultProvider->getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted);
465 ARMARX_ERROR <<
"Calling waitForPointClouds without PointCloudProvider name but using "
466 "multiple PointCloudProviders";
488 <<
"Trying to wait for PointClouds from unknown PointCloud provider '"
489 << providerName <<
"'. Call usingPointCloudProvider before."
494 if (iter->second.pointCloudAvailable)
500 auto cond = iter->second.pointCloudAvailableEvent;
506 std::unique_lock lock2(mut);
507 auto td = std::chrono::milliseconds(milliseconds);
510 return cond->wait_for(lock2, td) != std::cv_status::timeout;
523 <<
"Asked for new point cloud data for unknown PointCloud provider '"
524 << providerName <<
"'. Call usingPointCloudProvider() beforehand."
530 return iter->second.pointCloudAvailable;
533 MetaPointCloudFormatPtr
538 MetaPointCloudFormatPtr format;
545 <<
"Trying to wait for PointClouds from unknown PointCloud provider '"
546 << providerName <<
"'. Call usingPointCloudProvider before."
551 format = iter->second.proxy->getPointCloudFormat();
565 ARMARX_ERROR <<
"Requesting statistics for unknown PointCloud provider '"
566 << providerName <<
"'"
575 iter->second.pointCloudProviderFPS.reset();
576 iter->second.pollingFPS.reset();
580 iter->second.pointCloudProviderFPS.recalculate();
581 iter->second.pollingFPS.recalculate();
589 const std::string& defaultFrame)
595 <<
"Requesting information about unknown point cloud provider ''" << providerName
600 auto frameProv = ReferenceFrameInterfacePrx::checkedCast(providerInfo.
proxy);
602 return frameProv ? frameProv->getReferenceFrame() : defaultFrame;
612 std::map<std::string, PointCloudProviderInfo>::iterator iter =
617 ARMARX_ERROR <<
"Received notification from unknown point cloud provider '"
618 << providerName <<
"'."
623 iter->second.pointCloudAvailable =
true;
624 iter->second.pointCloudAvailableEvent->notify_all();
628 statistics[providerName].pointCloudProviderFPS.update();
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
The IceSharedMemoryConsumer reads data via Ice or shared memory.
IceUtil::Handle< IceSharedMemoryConsumer< MemoryObject, MemoryObjectMetaInfo > > pointer_type
pointer type for convenience.
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 unsubscribeFromTopic(const std::string &name)
Unsubscribe from a topic.
virtual std::string getDefaultName() const =0
Retrieve default name of component.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
void waitForProxy(std::string const &name, bool addToDependencies)
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
bool removeProxyDependency(const std::string &name)
This function removes the dependency of this object on the in parameter name specified object.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
bool hasProperty(const std::string &name)
PointCloudProcessorPropertyDefinitions(std::string prefix)
virtual void onInitComponent() override
void releasePointCloudProvider(std::string providerName)
Removes topic subscription and provider proxy dependency to release a point cloud provider.
std::string getPointCloudFrame(const std::string &providerName, const std::string &defaultFrame="")
Get the reference frame of the point cloud by given provider.
virtual void process()=0
Process the vision component.
virtual void onInitPointCloudProcessor()=0
Setup the vision component.
std::map< std::string, IceInternal::Handle< ResultPointCloudProvider > > resultPointCloudProviders
std::map< std::string, PointCloudTransferStats > statistics
bool isPointCloudProviderKnown(const std::string &providerName) const
Indicate whether the given name identifies a known point cloud provider.
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
virtual void onDisconnectComponent() override
virtual void runProcessor()
virtual void onConnectPointCloudProcessor()=0
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
MetaPointCloudFormatPtr getPointCloudFormat(std::string providerName)
std::shared_mutex pointCloudProviderInfoMutex
std::shared_mutex resultProviderMutex
PointCloudProviderMap usedPointCloudProviders
void usingPointCloudProvider(std::string providerName)
Registers a delayed topic subscription and a delayed provider proxy retrieval which will be available...
virtual void onDisconnectPointCloudProcessor()
Implement this method in the PointCloudProcessor in order execute parts when the component looses net...
virtual void onConnectComponent() override
PointCloudProviderInfo getPointCloudProvider(std::string name, bool waitForProxy=false)
Select an PointCloudProvider.
bool pointCloudHasNewData(std::string providerName)
Returns current status for the given point cloud.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
armarx::RunningTask< PointCloudProcessor >::pointer_type processorTask
PointCloudTransferStats getPointCloudTransferStats(std::string providerName, bool resetStats=false)
Retrieve statistics for a connection to an PointCloudProvider.
virtual void onExitComponent() override
std::vector< std::string > getPointCloudProviderNames() const
Get the names of providers for which usingPointCloudProvider() has been called.
virtual void onExitPointCloudProcessor()=0
Exit the ImapeProcessor component.
void reportPointCloudAvailable(const std::string &providerName, const Ice::Current &c=Ice::emptyCurrent) override
Listener callback function.
std::map< std::string, PointCloudProviderInfo > pointCloudProviderInfoMap
std::mutex statisticsMutex
PointCloudProviderInterfacePrx proxy
Proxy to PointCloud provider.
MetaPointCloudFormatPtr pointCloudFormat
PointCloud format struct that contains all necessary PointCloud information.
std::vector< unsigned char > buffer
Memory block.
std::shared_ptr< std::condition_variable > pointCloudAvailableEvent
Conditional variable used internally for synchronization purposes.
bool pointCloudAvailable
Indicates whether an PointCloud is available.
PointCloudProviderPropertyDefinitions(std::string prefix)
The PointCloudTransferStats class provides information on the connection between PointCloudProvider a...
ResultPointCloudProviderPropertyDefinitions(std::string prefix)
PointContentType getPointContentType() const
void setShmCapacity(size_t shmCapacity)
void setPointContentType(PointContentType type)
virtual void onInitPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
virtual MetaPointCloudFormatPtr getDefaultPointCloudFormat() override
default point cloud format used to initialize shared memory
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
ResultPointCloudProvider()
virtual void onExitPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
virtual std::string getDefaultName() const override
Retrieve default name of component.
void setResultPointCloudProviderName(const std::string &name)
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_NOT_EQUAL(lhs, rhs)
This macro evaluates whether lhs is inequal (!=) rhs and if it turns out to be false it will throw an...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void getMapKeys(const MapType &map, OutputIteratorType it)