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 
26 #include <mutex>
27 
28 #include <pcl/octree/octree.h>
29 
30 #include <VirtualRobot/VirtualRobot.h>
31 #include <VirtualRobot/Visualization/VisualizationFactory.h>
32 
35 
36 #include <RobotAPI/interface/core/RobotState.h>
38 
40 #include <VisionX/interface/components/VoxelGridProviderInterface.h>
41 
42 namespace armarx
43 {
44  class IceReportSkipper;
45 }
46 
47 namespace visionx
48 {
49  /**
50  * @class VoxelGridMappingProviderPropertyDefinitions
51  * @brief
52  */
54  {
55  public:
58  {
59  defineOptionalProperty<std::string>(
60  "PointCloudLoadFilepath",
61  "",
62  "If set, the accumulated point cloud is loaded from the file");
63  defineOptionalProperty<std::string>(
64  "PointCloudStoreFilepath",
65  "",
66  "If set, the accumulated point cloud is stored to this file periodically");
67  defineOptionalProperty<float>(
68  "PointCloudStorageFrequency",
69  0.1f,
70  "Frequency at which the collected point cloud is stored.");
71  defineOptionalProperty<std::string>(
72  "RobotStateComponentName",
73  "RobotStateComponent",
74  "Name of the robot state component that should be used");
75  defineOptionalProperty<std::string>(
76  "providerName", "OpenNIPointCloudProvider", "name of the point cloud provider");
77  defineOptionalProperty<std::string>("sourceFrameName",
78  "",
79  "The source frame name. If unspecified the value "
80  "will be retrieved from the provider.");
81  defineOptionalProperty<std::string>(
82  "BoundingBox",
83  "0,6000;0,6000;100,2500",
84  "Point cloud points outside of this bouning box will be cropped",
86  defineOptionalProperty<float>("GridSize",
87  50,
88  "Size in x,y,z dimension of each entry of the voxel grid",
90  defineOptionalProperty<int>(
91  "MinimumPointNumberPerVoxel",
92  10,
93  "Minimum number of points in a voxel of the grid to be considered a filled voxel.",
95  defineOptionalProperty<float>(
96  "UpdateRate", 2.0f, "Frequency how often the voxel grid is updated");
97  defineOptionalProperty<bool>(
98  "ActivateOnStartUp",
99  true,
100  "If true, the component will start collection point cloud directly after start up. "
101  "Otherwise use interface functions.");
102 
103  //defineRequiredProperty<std::string>("PropertyName", "Description");
104  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
105  }
106  };
107 
108  /**
109  * @defgroup Component-VoxelGridMappingProvider VoxelGridMappingProvider
110  * @ingroup RobotComponents-Components
111  * A description of the component VoxelGridMappingProvider.
112  *
113  * @class VoxelGridMappingProvider
114  * @ingroup Component-VoxelGridMappingProvider
115  * @brief Brief description of class VoxelGridMappingProvider.
116  *
117  * Detailed description of class VoxelGridMappingProvider.
118  */
120  virtual public visionx::PointCloudProcessor,
121  virtual public VoxelGridProviderInterface
122  {
123  public:
124  using PointType = pcl::PointXYZRGBA;
125  using Cloud = pcl::PointCloud<PointType>;
126  using CloudPtr = Cloud::Ptr;
127 
129 
130 
131  /**
132  * @see armarx::ManagedIceObject::getDefaultName()
133  */
134  std::string getDefaultName() const override;
135 
136  protected:
137  /**
138  * @see PropertyUser::createPropertyDefinitions()
139  */
141 
142 
143  // PointCloudProcessor interface
144  protected:
145  void onInitPointCloudProcessor() override;
146  void onConnectPointCloudProcessor() override;
147  void onExitPointCloudProcessor() override;
148  void process() override;
149 
150 
151  std::pair<armarx::Vector3fSeq, std::vector<VirtualRobot::VisualizationFactory::Color>>
152  removeRobotVoxels(const armarx::Vector3fSeq& gridPoints,
153  std::vector<VirtualRobot::VisualizationFactory::Color> const& gridColors,
154  const VirtualRobot::RobotPtr& robot,
155  float distanceThreshold);
156  CloudPtr removeRobotVoxels(const CloudPtr& cloud,
157  const VirtualRobot::RobotPtr& robot,
158  float distanceThreshold);
159 
160  std::string providerName;
161 
162  std::string pointCloudFormat;
163 
165 
167 
168  std::string sourceFrameName;
169 
171 
173  pcl::octree::OctreePointCloud<PointType>::Ptr octtree;
174  float gridLeafSize = 0.0f;
175  VirtualRobot::TriMeshModelPtr gridMesh;
176  armarx::Vector3fSeq gridPositions;
177  mutable std::mutex dataMutex;
178  bool collectingPointClouds = false;
179 
180  Eigen::Vector3f croppingMin, croppingMax;
181  std::unique_ptr<armarx::IceReportSkipper> skipper;
182  std::unique_ptr<armarx::CycleUtil> cycleKeeper;
183 
184 
185  // VoxelGridMappingProviderInterface interface
186  void updateBoundaries();
187 
188  public:
189  armarx::Vector3fSeq getFilledGridPositions(const Ice::Current&) const override;
190  ::Ice::Float getGridSize(const ::Ice::Current& = Ice::emptyCurrent) const override;
191  void startCollectingPointClouds(const Ice::Current&) override;
192  void stopCollectingPointClouds(const Ice::Current&) override;
193  void reset(const Ice::Current&) override;
194 
195  // Component interface
196  public:
197  void componentPropertiesUpdated(const std::set<std::string>& changedProperties) override;
198  };
199 } // namespace visionx
visionx::VoxelGridMappingProvider::getDefaultName
std::string getDefaultName() const override
Definition: VoxelGridMappingProvider.cpp:64
visionx::VoxelGridMappingProviderPropertyDefinitions
Definition: VoxelGridMappingProvider.h:53
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
visionx::VoxelGridMappingProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: VoxelGridMappingProvider.cpp:70
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::VoxelGridMappingProvider::skipper
std::unique_ptr< armarx::IceReportSkipper > skipper
Definition: VoxelGridMappingProvider.h:181
visionx::VoxelGridMappingProvider::VoxelGridMappingProvider
VoxelGridMappingProvider()
Definition: VoxelGridMappingProvider.cpp:59
visionx::VoxelGridMappingProvider::startCollectingPointClouds
void startCollectingPointClouds(const Ice::Current &) override
Definition: VoxelGridMappingProvider.cpp:511
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::VoxelGridMappingProvider::collectingPointClouds
bool collectingPointClouds
Definition: VoxelGridMappingProvider.h:178
visionx::VoxelGridMappingProvider::croppingMax
Eigen::Vector3f croppingMax
Definition: VoxelGridMappingProvider.h:180
visionx::VoxelGridMappingProvider::dd
armarx::DebugDrawerInterfacePrx dd
Definition: VoxelGridMappingProvider.h:170
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:77
visionx::VoxelGridMappingProvider::Cloud
pcl::PointCloud< PointType > Cloud
Definition: VoxelGridMappingProvider.h:125
visionx::VoxelGridMappingProviderPropertyDefinitions::VoxelGridMappingProviderPropertyDefinitions
VoxelGridMappingProviderPropertyDefinitions(std::string prefix)
Definition: VoxelGridMappingProvider.h:56
visionx::VoxelGridMappingProvider::robotStateComponent
armarx::RobotStateComponentInterfacePrx robotStateComponent
Definition: VoxelGridMappingProvider.h:166
visionx::VoxelGridMappingProvider::lastPointCloud
CloudPtr lastPointCloud
Definition: VoxelGridMappingProvider.h:172
visionx::VoxelGridMappingProvider::gridPositions
armarx::Vector3fSeq gridPositions
Definition: VoxelGridMappingProvider.h:176
visionx::VoxelGridMappingProvider::sourceFrameName
std::string sourceFrameName
Definition: VoxelGridMappingProvider.h:168
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:177
visionx::VoxelGridMappingProvider::providerName
std::string providerName
Definition: VoxelGridMappingProvider.h:160
visionx::VoxelGridMappingProvider::gridLeafSize
float gridLeafSize
Definition: VoxelGridMappingProvider.h:174
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::stopCollectingPointClouds
void stopCollectingPointClouds(const Ice::Current &) override
Definition: VoxelGridMappingProvider.cpp:517
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:99
visionx::VoxelGridMappingProvider::updateBoundaries
void updateBoundaries()
Definition: VoxelGridMappingProvider.cpp:134
PointCloudProcessor.h
visionx::VoxelGridMappingProvider::getGridSize
::Ice::Float getGridSize(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: VoxelGridMappingProvider.cpp:505
visionx::VoxelGridMappingProvider::gridMesh
VirtualRobot::TriMeshModelPtr gridMesh
Definition: VoxelGridMappingProvider.h:175
Component.h
CycleUtil.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
visionx::VoxelGridMappingProvider::PointType
pcl::PointXYZRGBA PointType
Definition: VoxelGridMappingProvider.h:124
visionx::VoxelGridMappingProvider::robotPool
armarx::RobotPoolPtr robotPool
Definition: VoxelGridMappingProvider.h:164
visionx::VoxelGridMappingProvider::process
void process() override
Process the vision component.
Definition: VoxelGridMappingProvider.cpp:150
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::VoxelGridMappingProvider::accumulatedPointCloud
CloudPtr accumulatedPointCloud
Definition: VoxelGridMappingProvider.h:172
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
visionx::VoxelGridMappingProvider::cycleKeeper
std::unique_ptr< armarx::CycleUtil > cycleKeeper
Definition: VoxelGridMappingProvider.h:182
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
visionx::VoxelGridMappingProvider
Brief description of class VoxelGridMappingProvider.
Definition: VoxelGridMappingProvider.h:119
visionx::VoxelGridMappingProvider::reset
void reset(const Ice::Current &) override
Definition: VoxelGridMappingProvider.cpp:523
visionx::VoxelGridMappingProvider::CloudPtr
Cloud::Ptr CloudPtr
Definition: VoxelGridMappingProvider.h:126
visionx::VoxelGridMappingProvider::dataMutex
std::mutex dataMutex
Definition: VoxelGridMappingProvider.h:177
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:531
visionx::VoxelGridMappingProvider::octtree
pcl::octree::OctreePointCloud< PointType >::Ptr octtree
Definition: VoxelGridMappingProvider.h:173
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:27
visionx::VoxelGridMappingProvider::pointCloudFormat
std::string pointCloudFormat
Definition: VoxelGridMappingProvider.h:162
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
visionx::VoxelGridMappingProvider::croppingMin
Eigen::Vector3f croppingMin
Definition: VoxelGridMappingProvider.h:180
visionx::VoxelGridMappingProvider::getFilledGridPositions
armarx::Vector3fSeq getFilledGridPositions(const Ice::Current &) const override
Definition: VoxelGridMappingProvider.cpp:498
RobotPool.h
visionx::VoxelGridMappingProvider::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
Definition: VoxelGridMappingProvider.cpp:129