VoxelGridMappingProvider.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotComponents::ArmarXObjects::VoxelGridMappingProvider
17  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
27 #include <VisionX/interface/components/VoxelGridProviderInterface.h>
29 #include <RobotAPI/interface/core/RobotState.h>
32 
33 #include <VirtualRobot/VirtualRobot.h>
34 #include <VirtualRobot/Visualization/VisualizationFactory.h>
35 
36 #include <pcl/octree/octree.h>
37 
38 #include <mutex>
39 
40 namespace armarx
41 {
42  class IceReportSkipper;
43 }
44 
45 namespace visionx
46 {
47  /**
48  * @class VoxelGridMappingProviderPropertyDefinitions
49  * @brief
50  */
53  {
54  public:
57  {
58  defineOptionalProperty<std::string>("PointCloudLoadFilepath", "", "If set, the accumulated point cloud is loaded from the file");
59  defineOptionalProperty<std::string>("PointCloudStoreFilepath", "", "If set, the accumulated point cloud is stored to this file periodically");
60  defineOptionalProperty<float>("PointCloudStorageFrequency", 0.1f, "Frequency at which the collected point cloud is stored.");
61  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
62  defineOptionalProperty<std::string>("providerName", "OpenNIPointCloudProvider", "name of the point cloud provider");
63  defineOptionalProperty<std::string>("sourceFrameName", "", "The source frame name. If unspecified the value will be retrieved from the provider.");
64  defineOptionalProperty<std::string>("BoundingBox", "0,6000;0,6000;100,2500", "Point cloud points outside of this bouning box will be cropped", armarx::PropertyDefinitionBase::eModifiable);
65  defineOptionalProperty<float>("GridSize", 50, "Size in x,y,z dimension of each entry of the voxel grid", armarx::PropertyDefinitionBase::eModifiable);
66  defineOptionalProperty<int>("MinimumPointNumberPerVoxel", 10, "Minimum number of points in a voxel of the grid to be considered a filled voxel.", armarx::PropertyDefinitionBase::eModifiable);
67  defineOptionalProperty<float>("UpdateRate", 2.0f, "Frequency how often the voxel grid is updated");
68  defineOptionalProperty<bool>("ActivateOnStartUp", true, "If true, the component will start collection point cloud directly after start up. Otherwise use interface functions.");
69 
70  //defineRequiredProperty<std::string>("PropertyName", "Description");
71  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
72  }
73  };
74 
75  /**
76  * @defgroup Component-VoxelGridMappingProvider VoxelGridMappingProvider
77  * @ingroup RobotComponents-Components
78  * A description of the component VoxelGridMappingProvider.
79  *
80  * @class VoxelGridMappingProvider
81  * @ingroup Component-VoxelGridMappingProvider
82  * @brief Brief description of class VoxelGridMappingProvider.
83  *
84  * Detailed description of class VoxelGridMappingProvider.
85  */
87  virtual public visionx::PointCloudProcessor,
88  virtual public VoxelGridProviderInterface
89  {
90  public:
91  using PointType = pcl::PointXYZRGBA;
92  using Cloud = pcl::PointCloud<PointType>;
93  using CloudPtr = Cloud::Ptr;
94 
96 
97 
98 
99  /**
100  * @see armarx::ManagedIceObject::getDefaultName()
101  */
102  std::string getDefaultName() const override;
103 
104  protected:
105  /**
106  * @see PropertyUser::createPropertyDefinitions()
107  */
109 
110 
111  // PointCloudProcessor interface
112  protected:
113  void onInitPointCloudProcessor() override;
114  void onConnectPointCloudProcessor() override;
115  void onExitPointCloudProcessor() override;
116  void process() override;
117 
118 
119  std::pair<armarx::Vector3fSeq, std::vector<VirtualRobot::VisualizationFactory::Color>> removeRobotVoxels(const armarx::Vector3fSeq& gridPoints, std::vector<VirtualRobot::VisualizationFactory::Color>const& gridColors, const VirtualRobot::RobotPtr& robot, float distanceThreshold);
120  CloudPtr removeRobotVoxels(const CloudPtr& cloud, const VirtualRobot::RobotPtr& robot, float distanceThreshold);
121 
122  std::string providerName;
123 
124  std::string pointCloudFormat;
125 
127 
129 
130  std::string sourceFrameName;
131 
133 
135  pcl::octree::OctreePointCloud<PointType>::Ptr octtree;
136  float gridLeafSize = 0.0f;
137  VirtualRobot::TriMeshModelPtr gridMesh;
138  armarx::Vector3fSeq gridPositions;
139  mutable std::mutex dataMutex;
140  bool collectingPointClouds = false;
141 
142  Eigen::Vector3f croppingMin, croppingMax;
143  std::unique_ptr<armarx::IceReportSkipper> skipper;
144  std::unique_ptr<armarx::CycleUtil> cycleKeeper;
145 
146 
147 
148  // VoxelGridMappingProviderInterface interface
149  void updateBoundaries();
150 
151  public:
152  armarx::Vector3fSeq getFilledGridPositions(const Ice::Current&) const override;
153  ::Ice::Float getGridSize(const ::Ice::Current& = Ice::emptyCurrent) const override;
154  void startCollectingPointClouds(const Ice::Current&) override;
155  void stopCollectingPointClouds(const Ice::Current&) override;
156  void reset(const Ice::Current&) override;
157 
158  // Component interface
159  public:
160  void componentPropertiesUpdated(const std::set<std::string>& changedProperties) override;
161  };
162 }
visionx::VoxelGridMappingProvider::getDefaultName
std::string getDefaultName() const override
Definition: VoxelGridMappingProvider.cpp:61
visionx::VoxelGridMappingProviderPropertyDefinitions
Definition: VoxelGridMappingProvider.h:51
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
visionx::VoxelGridMappingProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: VoxelGridMappingProvider.cpp:66
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::VoxelGridMappingProvider::skipper
std::unique_ptr< armarx::IceReportSkipper > skipper
Definition: VoxelGridMappingProvider.h:143
visionx::VoxelGridMappingProvider::VoxelGridMappingProvider
VoxelGridMappingProvider()
Definition: VoxelGridMappingProvider.cpp:56
visionx::VoxelGridMappingProvider::startCollectingPointClouds
void startCollectingPointClouds(const Ice::Current &) override
Definition: VoxelGridMappingProvider.cpp:498
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::VoxelGridMappingProvider::removeRobotVoxels
std::pair< armarx::Vector3fSeq, std::vector< VirtualRobot::VisualizationFactory::Color > > removeRobotVoxels(const armarx::Vector3fSeq &gridPoints, std::vector< VirtualRobot::VisualizationFactory::Color >const &gridColors, const VirtualRobot::RobotPtr &robot, float distanceThreshold)
visionx::VoxelGridMappingProvider::collectingPointClouds
bool collectingPointClouds
Definition: VoxelGridMappingProvider.h:140
visionx::VoxelGridMappingProvider::croppingMax
Eigen::Vector3f croppingMax
Definition: VoxelGridMappingProvider.h:142
visionx::VoxelGridMappingProvider::dd
armarx::DebugDrawerInterfacePrx dd
Definition: VoxelGridMappingProvider.h:132
armarx::RobotPoolPtr
std::shared_ptr< class RobotPool > RobotPoolPtr
Definition: RobotUnitModuleRobotData.h:35
visionx::VoxelGridMappingProvider::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Setup the vision component.
Definition: VoxelGridMappingProvider.cpp:76
visionx::VoxelGridMappingProvider::Cloud
pcl::PointCloud< PointType > Cloud
Definition: VoxelGridMappingProvider.h:92
visionx::VoxelGridMappingProviderPropertyDefinitions::VoxelGridMappingProviderPropertyDefinitions
VoxelGridMappingProviderPropertyDefinitions(std::string prefix)
Definition: VoxelGridMappingProvider.h:55
visionx::VoxelGridMappingProvider::robotStateComponent
armarx::RobotStateComponentInterfacePrx robotStateComponent
Definition: VoxelGridMappingProvider.h:128
visionx::VoxelGridMappingProvider::lastPointCloud
CloudPtr lastPointCloud
Definition: VoxelGridMappingProvider.h:134
visionx::VoxelGridMappingProvider::gridPositions
armarx::Vector3fSeq gridPositions
Definition: VoxelGridMappingProvider.h:138
visionx::VoxelGridMappingProvider::sourceFrameName
std::string sourceFrameName
Definition: VoxelGridMappingProvider.h:130
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:186
visionx::VoxelGridMappingProvider::providerName
std::string providerName
Definition: VoxelGridMappingProvider.h:122
visionx::VoxelGridMappingProvider::gridLeafSize
float gridLeafSize
Definition: VoxelGridMappingProvider.h:136
visionx::VoxelGridMappingProvider::stopCollectingPointClouds
void stopCollectingPointClouds(const Ice::Current &) override
Definition: VoxelGridMappingProvider.cpp:503
visionx::VoxelGridMappingProvider::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
Definition: VoxelGridMappingProvider.cpp:94
visionx::VoxelGridMappingProvider::updateBoundaries
void updateBoundaries()
Definition: VoxelGridMappingProvider.cpp:127
PointCloudProcessor.h
visionx::VoxelGridMappingProvider::getGridSize
::Ice::Float getGridSize(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: VoxelGridMappingProvider.cpp:492
visionx::VoxelGridMappingProvider::gridMesh
VirtualRobot::TriMeshModelPtr gridMesh
Definition: VoxelGridMappingProvider.h:137
Component.h
CycleUtil.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
visionx::VoxelGridMappingProvider::PointType
pcl::PointXYZRGBA PointType
Definition: VoxelGridMappingProvider.h:91
visionx::VoxelGridMappingProvider::robotPool
armarx::RobotPoolPtr robotPool
Definition: VoxelGridMappingProvider.h:126
visionx::VoxelGridMappingProvider::process
void process() override
Process the vision component.
Definition: VoxelGridMappingProvider.cpp:142
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::VoxelGridMappingProvider::accumulatedPointCloud
CloudPtr accumulatedPointCloud
Definition: VoxelGridMappingProvider.h:134
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
visionx::VoxelGridMappingProvider::cycleKeeper
std::unique_ptr< armarx::CycleUtil > cycleKeeper
Definition: VoxelGridMappingProvider.h:144
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
visionx::VoxelGridMappingProvider
Brief description of class VoxelGridMappingProvider.
Definition: VoxelGridMappingProvider.h:86
visionx::VoxelGridMappingProvider::reset
void reset(const Ice::Current &) override
Definition: VoxelGridMappingProvider.cpp:508
visionx::VoxelGridMappingProvider::CloudPtr
Cloud::Ptr CloudPtr
Definition: VoxelGridMappingProvider.h:93
visionx::VoxelGridMappingProvider::dataMutex
std::mutex dataMutex
Definition: VoxelGridMappingProvider.h:139
visionx::VoxelGridMappingProvider::componentPropertiesUpdated
void componentPropertiesUpdated(const std::set< std::string > &changedProperties) override
Implement this function if you would like to react to changes in the properties.
Definition: VoxelGridMappingProvider.cpp:517
visionx::VoxelGridMappingProvider::octtree
pcl::octree::OctreePointCloud< PointType >::Ptr octtree
Definition: VoxelGridMappingProvider.h:135
armarx::PropertyDefinitionBase::eModifiable
@ eModifiable
Definition: PropertyDefinitionInterface.h:57
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
visionx::VoxelGridMappingProvider::pointCloudFormat
std::string pointCloudFormat
Definition: VoxelGridMappingProvider.h:124
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
visionx::VoxelGridMappingProvider::croppingMin
Eigen::Vector3f croppingMin
Definition: VoxelGridMappingProvider.h:142
visionx::VoxelGridMappingProvider::getFilledGridPositions
armarx::Vector3fSeq getFilledGridPositions(const Ice::Current &) const override
Definition: VoxelGridMappingProvider.cpp:486
RobotPool.h
visionx::VoxelGridMappingProvider::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
Definition: VoxelGridMappingProvider.cpp:120