Manager.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "Manager.h"
25
26namespace visionx
27{
28
30 {
31 }
32
34 {
35 }
36
37 void
38 Manager::registerPointCloud(const std::string& name)
39 {
40 std::unique_lock lock(mutex);
41 if (clouds.find(name) == clouds.end())
42 {
43 clouds.emplace(name, nullptr);
44 }
45 }
46
47 void
48 Manager::unregisterPointCloud(const std::string& name)
49 {
50 std::unique_lock lock(mutex);
51 auto find = clouds.find(name);
52 if (find != clouds.end())
53 {
54 if (find->second != nullptr)
55 {
56 int position = this->findChild(find->second);
57 if (position != -1)
58 {
59 this->removeChild(position);
60 }
61 }
62 clouds.erase(find);
63 }
64 }
65
66 std::vector<std::string>
68 {
69 std::unique_lock lock(mutex);
70
71 std::vector<std::string> cloud_list;
72 for (const auto& [name, _] : clouds)
73 {
74 cloud_list.push_back(name);
75 }
76 return cloud_list;
77 }
78
80 Manager::getCloudByName(const std::string& name)
81 {
82 std::unique_lock lock(mutex);
83 auto find = clouds.find(name);
84 return find != clouds.end() ? find->second : nullptr;
85 }
86
87 void
88 Manager::updatePointCloud(const std::string& name, CoinPointCloud& cloud)
89 {
90 std::unique_lock lock(mutex);
91
92 auto item = clouds.find(name);
93 if (item != clouds.end())
94 {
95 if (item->second != nullptr)
96 {
97 // This will also bring ref counter of cloud to zero and free memory.
98 int position = this->findChild(item->second);
99 if (position != -1)
100 {
101 this->removeChild(position);
102 }
103 }
104 item->second = &cloud;
105 this->addChild(&cloud);
106 }
107 }
108} // namespace visionx
CoinPointCloud * getCloudByName(const std::string &name)
Definition Manager.cpp:80
~Manager() override
Definition Manager.cpp:33
void registerPointCloud(const std::string &name)
Definition Manager.cpp:38
void unregisterPointCloud(const std::string &name)
Definition Manager.cpp:48
std::vector< std::string > getRegisteredPointClouds()
Definition Manager.cpp:67
void updatePointCloud(const std::string &name, CoinPointCloud &cloud)
Definition Manager.cpp:88
ArmarX headers.