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 namespace visionx
34 {
35 
36  /**
37  * @brief Merges several labeled or unlabeled point clouds into one
38  * labeled point cloud.
39  *
40  *
41  */
43  {
44  public:
45  using PointT = pcl::PointXYZRGBA;
46  using PointL = pcl::PointXYZRGBL;
47  using Label = uint32_t;
48 
49 
50  public:
51  /// Constructor.
53 
54 
55  // Input.
56 
57  /**
58  * @brief Set a (new) labeled or unlabeled input point cloud.
59  *
60  * Stores the given point cloud as latest point cloud with the given
61  * name, which will be used when getting the result point cloud.
62  * If `isLabeled` is passed as false, the point cloud will receive a
63  * (new) constant label.
64  *
65  * @param name The point cloud's name.
66  * @param inputCloud The input point cloud.
67  * @param isLabeld Whether the point cloud has valid labels.
68  */
69  void setInputPointCloud(const std::string& name,
70  pcl::PointCloud<PointL>::ConstPtr inputCloud,
71  bool isLabeled = true);
72  /**
73  * @brief Set a (new) input point cloud.
74  * @param name The point cloud's name
75  * @param inputCloud The input point cloud.
76  * @param originalType The providers point type (used to check whether the
77  * cloud is labeled or not).
78  */
79  void setInputPointCloud(const std::string& name,
80  pcl::PointCloud<PointL>::ConstPtr inputCloud,
81  visionx::PointContentType originalType);
82  /**
83  * @brief Set a (new) unlabeled input point cloud.
84  * The point cloud will receive a (new) constant label.
85  *
86  * @param name The point cloud name.
87  * @param inputCloud The input point cloud.
88  */
89  void setInputPointCloud(const std::string& name,
90  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  /// Get the labels present in `inputLabeledClouds`.
106  std::set<Label> getUsedLabels() const;
107  /// Label unlabeled clouds and move them to `inputLabeledClouds`.
108  void labelUnlabeledClouds(const std::set<Label>& usedLabels);
109 
110  /// Rebuild `resultCloud`. Clears it and appends stored point clouds from all providers.
111  void mergeLabeledClouds();
112 
113 
114  private:
115  /// Latest received unlabeled clouds.
116  std::map<std::string, pcl::PointCloud<PointT>::ConstPtr> inputUnlabeledClouds;
117  /// Latest received labeled clouds + unlabeled clouds with new labels.
118  std::map<std::string, pcl::PointCloud<PointL>::ConstPtr> inputLabeledClouds;
119 
120  /// Whether input has changed and resultCloud must be rebuilt.
121  bool changed = false;
122  /// Result point cloud. Cached while no new input clouds arrive.
123  pcl::PointCloud<PointL>::Ptr resultCloud{new pcl::PointCloud<PointL>()};
124  };
125 } // namespace visionx
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::tools::isLabeled
bool isLabeled(PointContentType type)
Definition: PointCloudConversions.cpp:131
visionx::MergedLabeledPointCloud::Label
uint32_t Label
Definition: MergedLabeledPointCloud.h:47
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:39
visionx::MergedLabeledPointCloud::PointL
pcl::PointXYZRGBL PointL
Definition: MergedLabeledPointCloud.h:46
visionx::MergedLabeledPointCloud::PointT
pcl::PointXYZRGBA PointT
Definition: MergedLabeledPointCloud.h:45
visionx::MergedLabeledPointCloud
Merges several labeled or unlabeled point clouds into one labeled point cloud.
Definition: MergedLabeledPointCloud.h:42
visionx::MergedLabeledPointCloud::getResultPointCloud
pcl::PointCloud< PointL >::Ptr getResultPointCloud()
Get the result point cloud.
Definition: MergedLabeledPointCloud.cpp:81