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 
26 namespace visionx
27 {
28 
30  {
31  }
32 
34  {
35  }
36 
37  void Manager::registerPointCloud(const std::string& name)
38  {
39  std::unique_lock lock(mutex);
40  if (clouds.find(name) == clouds.end())
41  {
42  clouds.emplace(name, nullptr);
43  }
44  }
45 
46  void Manager::unregisterPointCloud(const std::string& name)
47  {
48  std::unique_lock lock(mutex);
49  auto find = clouds.find(name);
50  if (find != clouds.end())
51  {
52  if (find->second != nullptr)
53  {
54  int position = this->findChild(find->second);
55  if (position != -1)
56  {
57  this->removeChild(position);
58  }
59  }
60  clouds.erase(find);
61  }
62  }
63 
64  std::vector<std::string> Manager::getRegisteredPointClouds()
65  {
66  std::unique_lock lock(mutex);
67 
68  std::vector<std::string> cloud_list;
69  for (const auto& [name, _] : clouds)
70  {
71  cloud_list.push_back(name);
72  }
73  return cloud_list;
74  }
75 
76  CoinPointCloud* Manager::getCloudByName(const std::string& name)
77  {
78  std::unique_lock lock(mutex);
79  auto find = clouds.find(name);
80  return find != clouds.end() ? find->second : nullptr;
81  }
82 
83  void Manager::updatePointCloud(const std::string& name, CoinPointCloud& cloud)
84  {
85  std::unique_lock lock(mutex);
86 
87  auto item = clouds.find(name);
88  if (item != clouds.end())
89  {
90  if (item->second != nullptr)
91  {
92  // This will also bring ref counter of cloud to zero and free memory.
93  int position = this->findChild(item->second);
94  if (position != -1)
95  {
96  this->removeChild(position);
97  }
98  }
99  item->second = &cloud;
100  this->addChild(&cloud);
101  }
102  }
103 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::Manager::unregisterPointCloud
void unregisterPointCloud(const std::string &name)
Definition: Manager.cpp:46
Manager.h
visionx::Manager::Manager
Manager()
Definition: Manager.cpp:29
visionx::Manager::getRegisteredPointClouds
std::vector< std::string > getRegisteredPointClouds()
Definition: Manager.cpp:64
visionx::CoinPointCloud
Definition: CoinPointCloud.h:39
visionx::Manager::updatePointCloud
void updatePointCloud(const std::string &name, CoinPointCloud &cloud)
Definition: Manager.cpp:83
visionx::Manager::registerPointCloud
void registerPointCloud(const std::string &name)
Definition: Manager.cpp:37
visionx::Manager::getCloudByName
CoinPointCloud * getCloudByName(const std::string &name)
Definition: Manager.cpp:76
visionx::Manager::~Manager
~Manager() override
Definition: Manager.cpp:33