Fawkes API  Fawkes Development Version
pointcloud_manager.cpp
1 
2 /***************************************************************************
3  * pointcloud_manager.cpp - PointCloud manager
4  *
5  * Created: Sun Nov 06 23:49:36 2011
6  * Copyright 2011-2014 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21  */
22 
23 #include <pcl_utils/pointcloud_manager.h>
24 
25 namespace fawkes {
26 
27 /** @class PointCloudManager <pcl_utils/pointcloud_manager.h>
28  * Point Cloud manager.
29  * This class manages a number of points clouds and acts as a hub to
30  * distribute them.
31  * @author Tim Niemueller
32  *
33  * @fn void PointCloudManager::add_pointcloud(const char *id, RefPtr<pcl::PointCloud<PointT> > cloud)
34  * Add point cloud.
35  * @param id ID of point cloud to add, must be unique
36  * @param cloud refptr to point cloud
37  *
38  * @fn const RefPtr<const pcl::PointCloud<PointT> > PointCloudManager::get_pointcloud(const char *id)
39  * Get point cloud.
40  * @param id ID of point cloud to retrieve
41  * @return point cloud
42  * @exception Exception thrown if point cloud for given ID does not exist
43  *
44  */
45 
46 /** Constructor. */
48 {
49 }
50 
51 /** Destructor. */
53 {
55  for (c = clouds_.begin(); c != clouds_.end(); ++c) {
56  delete c->second;
57  }
58 
59  clouds_.clear();
60 }
61 
62 /** Remove the point cloud.
63  * @param id ID of point cloud to remove
64  */
65 void
67 {
68  MutexLocker lock(clouds_.mutex());
69 
70  if (clouds_.find(id) != clouds_.end()) {
71  delete clouds_[id];
72  clouds_.erase(id);
73  }
74 }
75 
76 /** Check if point cloud exists
77  * @param id ID of point cloud to check
78  * @return true if the point cloud exists, false otherwise
79  */
80 bool
82 {
83  MutexLocker lock(clouds_.mutex());
84 
85  return (clouds_.find(id) != clouds_.end());
86 }
87 
88 /** Get list of point cloud IDs.
89  * @return list of point cloud IDs
90  */
91 std::vector<std::string>
93 {
94  MutexLocker lock(clouds_.mutex());
95 
96  std::vector<std::string> rv;
97  rv.clear();
99  for (c = clouds_.begin(); c != clouds_.end(); ++c) {
100  rv.push_back(c->first);
101  }
102  return rv;
103 }
104 
105 /** Get map of point clouds.
106  * Use with care. Do not use in ROS-enabled plugins unless you are aware
107  * of sensor_msgs and std_msgs incompatibilities between standalone PCL
108  * and ROS!
109  * @return map from ID to storage adapter
110  */
113 {
114  return clouds_;
115 }
116 
117 /** Get a storage adapter.
118  * Use with care. Do not use in ROS-enabled plugins unless you are aware
119  * of sensor_msgs and std_msgs incompatibilities between standalone PCL
120  * and ROS!
121  * @param id ID of point clouds whose storage adapter to retrieve
122  * @return storage adapter for given ID
123  * @exception Exception thrown if ID is unknown
124  */
127 {
128  MutexLocker lock(clouds_.mutex());
129 
130  if (clouds_.find(id) == clouds_.end()) {
131  throw Exception("PointCloud '%s' unknown", id);
132  }
133  return clouds_[id];
134 }
135 
136 } // end namespace fawkes
fawkes::LockMap
Definition: lock_map.h:39
fawkes::PointCloudManager::exists_pointcloud
bool exists_pointcloud(const char *id)
Check if point cloud exists.
Definition: pointcloud_manager.cpp:84
fawkes::PointCloudManager::remove_pointcloud
void remove_pointcloud(const char *id)
Remove the point cloud.
Definition: pointcloud_manager.cpp:69
fawkes::MutexLocker
Definition: mutex_locker.h:37
fawkes::PointCloudManager::PointCloudManager
PointCloudManager()
Constructor.
Definition: pointcloud_manager.cpp:50
fawkes
fawkes::pcl_utils::StorageAdapter
Definition: storage_adapter.h:45
fawkes::PointCloudManager::get_pointclouds
const fawkes::LockMap< std::string, pcl_utils::StorageAdapter * > & get_pointclouds() const
Get map of point clouds.
Definition: pointcloud_manager.cpp:115
fawkes::PointCloudManager::get_storage_adapter
const pcl_utils::StorageAdapter * get_storage_adapter(const char *id)
Get a storage adapter.
Definition: pointcloud_manager.cpp:129
fawkes::PointCloudManager::get_pointcloud_list
std::vector< std::string > get_pointcloud_list() const
Get list of point cloud IDs.
Definition: pointcloud_manager.cpp:95
fawkes::PointCloudManager::~PointCloudManager
virtual ~PointCloudManager()
Destructor.
Definition: pointcloud_manager.cpp:55
fawkes::Exception
Definition: exception.h:39