MergedLabeledPointCloud.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 MA_RainerKartmann::ArmarXObjects::PointCloudMerger
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <map>
26 #include <set>
27 
28 #include <pcl/point_cloud.h>
29 #include <pcl/point_types.h>
30 
31 #include <VisionX/interface/core/DataTypes.h>
32 
33 
34 namespace visionx
35 {
36 
37  /**
38  * @brief Merges several labeled or unlabeled point clouds into one
39  * labeled point cloud.
40  *
41  *
42  */
44  {
45  public:
46 
47  using PointT = pcl::PointXYZRGBA;
48  using PointL = pcl::PointXYZRGBL;
49  using Label = uint32_t;
50 
51 
52  public:
53 
54  /// Constructor.
56 
57 
58  // Input.
59 
60  /**
61  * @brief Set a (new) labeled or unlabeled input point cloud.
62  *
63  * Stores the given point cloud as latest point cloud with the given
64  * name, which will be used when getting the result point cloud.
65  * If `isLabeled` is passed as false, the point cloud will receive a
66  * (new) constant label.
67  *
68  * @param name The point cloud's name.
69  * @param inputCloud The input point cloud.
70  * @param isLabeld Whether the point cloud has valid labels.
71  */
72  void setInputPointCloud(const std::string& name, pcl::PointCloud<PointL>::ConstPtr inputCloud,
73  bool isLabeled = true);
74  /**
75  * @brief Set a (new) input point cloud.
76  * @param name The point cloud's name
77  * @param inputCloud The input point cloud.
78  * @param originalType The providers point type (used to check whether the
79  * cloud is labeled or not).
80  */
81  void setInputPointCloud(const std::string& name, pcl::PointCloud<PointL>::ConstPtr inputCloud,
82  visionx::PointContentType originalType);
83  /**
84  * @brief Set a (new) unlabeled input point cloud.
85  * The point cloud will receive a (new) constant label.
86  *
87  * @param name The point cloud name.
88  * @param inputCloud The input point cloud.
89  */
90  void setInputPointCloud(const std::string& name, pcl::PointCloud<PointT>::ConstPtr inputCloud);
91 
92 
93  // Result.
94 
95  /**
96  * @brief Get the result point cloud.
97  * It is rebuild if necessary.
98  *
99  * @return The result point cloud.
100  */
101  pcl::PointCloud<PointL>::Ptr getResultPointCloud();
102 
103 
104  private:
105 
106  /// Get the labels present in `inputLabeledClouds`.
107  std::set<Label> getUsedLabels() const;
108  /// Label unlabeled clouds and move them to `inputLabeledClouds`.
109  void labelUnlabeledClouds(const std::set<Label>& usedLabels);
110 
111  /// Rebuild `resultCloud`. Clears it and appends stored point clouds from all providers.
112  void mergeLabeledClouds();
113 
114 
115  private:
116 
117  /// Latest received unlabeled clouds.
118  std::map<std::string, pcl::PointCloud<PointT>::ConstPtr> inputUnlabeledClouds;
119  /// Latest received labeled clouds + unlabeled clouds with new labels.
120  std::map<std::string, pcl::PointCloud<PointL>::ConstPtr> inputLabeledClouds;
121 
122  /// Whether input has changed and resultCloud must be rebuilt.
123  bool changed = false;
124  /// Result point cloud. Cached while no new input clouds arrive.
125  pcl::PointCloud<PointL>::Ptr resultCloud { new pcl::PointCloud<PointL>() };
126 
127  };
128 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::tools::isLabeled
bool isLabeled(PointContentType type)
Definition: PointCloudConversions.cpp:108
visionx::MergedLabeledPointCloud::Label
uint32_t Label
Definition: MergedLabeledPointCloud.h:49
visionx::MergedLabeledPointCloud::MergedLabeledPointCloud
MergedLabeledPointCloud()
Constructor.
visionx::MergedLabeledPointCloud::setInputPointCloud
void setInputPointCloud(const std::string &name, pcl::PointCloud< PointL >::ConstPtr inputCloud, bool isLabeled=true)
Set a (new) labeled or unlabeled input point cloud.
Definition: MergedLabeledPointCloud.cpp:40
visionx::MergedLabeledPointCloud::PointL
pcl::PointXYZRGBL PointL
Definition: MergedLabeledPointCloud.h:48
visionx::MergedLabeledPointCloud::PointT
pcl::PointXYZRGBA PointT
Definition: MergedLabeledPointCloud.h:47
visionx::MergedLabeledPointCloud
Merges several labeled or unlabeled point clouds into one labeled point cloud.
Definition: MergedLabeledPointCloud.h:43
visionx::MergedLabeledPointCloud::getResultPointCloud
pcl::PointCloud< PointL >::Ptr getResultPointCloud()
Get the result point cloud.
Definition: MergedLabeledPointCloud.cpp:82