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 #if 0 /* just to make Emacs auto-indent happy */
27 }
28 #endif
29 
30 
31 /** @class PointCloudManager <pcl_utils/pointcloud_manager.h>
32  * Point Cloud manager.
33  * This class manages a number of points clouds and acts as a hub to
34  * distribute them.
35  * @author Tim Niemueller
36  *
37  * @fn void PointCloudManager::add_pointcloud(const char *id, RefPtr<pcl::PointCloud<PointT> > cloud)
38  * Add point cloud.
39  * @param id ID of point cloud to add, must be unique
40  * @param cloud refptr to point cloud
41  *
42  * @fn const RefPtr<const pcl::PointCloud<PointT> > PointCloudManager::get_pointcloud(const char *id)
43  * Get point cloud.
44  * @param id ID of point cloud to retrieve
45  * @return point cloud
46  * @exception Exception thrown if point cloud for given ID does not exist
47  *
48  */
49 
50 /** Constructor. */
52 {
53 }
54 
55 /** Destructor. */
57 {
59  for (c = __clouds.begin(); c != __clouds.end(); ++c) {
60  delete c->second;
61  }
62 
63  __clouds.clear();
64 }
65 
66 
67 /** Remove the point cloud.
68  * @param id ID of point cloud to remove
69  */
70 void
72 {
73  MutexLocker lock(__clouds.mutex());
74 
75  if (__clouds.find(id) != __clouds.end()) {
76  delete __clouds[id];
77  __clouds.erase(id);
78  }
79 }
80 
81 /** Check if point cloud exists
82  * @param id ID of point cloud to check
83  * @return true if the point cloud exists, false otherwise
84  */
85 bool
87 {
88  MutexLocker lock(__clouds.mutex());
89 
90  return (__clouds.find(id) != __clouds.end());
91 }
92 
93 
94 /** Get list of point cloud IDs.
95  * @return list of point cloud IDs
96  */
97 std::vector<std::string>
99 {
100  MutexLocker lock(__clouds.mutex());
101 
102  std::vector<std::string> rv;
103  rv.clear();
105  for (c = __clouds.begin(); c != __clouds.end(); ++c) {
106  rv.push_back(c->first);
107  }
108  return rv;
109 }
110 
111 
112 /** Get map of point clouds.
113  * Use with care. Do not use in ROS-enabled plugins unless you are aware
114  * of sensor_msgs and std_msgs incompatibilities between standalone PCL
115  * and ROS!
116  * @return map from ID to storage adapter
117  */
120 {
121  return __clouds;
122 }
123 
124 
125 /** Get a storage adapter.
126  * Use with care. Do not use in ROS-enabled plugins unless you are aware
127  * of sensor_msgs and std_msgs incompatibilities between standalone PCL
128  * and ROS!
129  * @param id ID of point clouds whose storage adapter to retrieve
130  * @return storage adapter for given ID
131  * @exception Exception thrown if ID is unknown
132  */
135 {
136  MutexLocker lock(__clouds.mutex());
137 
138  if (__clouds.find(id) == __clouds.end()) {
139  throw Exception("PointCloud '%s' unknown", id);
140  }
141  return __clouds[id];
142 }
143 
144 
145 
146 } // end namespace fawkes
std::vector< std::string > get_pointcloud_list() const
Get list of point cloud IDs.
void remove_pointcloud(const char *id)
Remove the point cloud.
Fawkes library namespace.
Mutex locking helper.
Definition: mutex_locker.h:33
virtual ~PointCloudManager()
Destructor.
Map with a lock.
Definition: lock_map.h:37
const fawkes::LockMap< std::string, pcl_utils::StorageAdapter * > & get_pointclouds() const
Get map of point clouds.
Base class for exceptions in Fawkes.
Definition: exception.h:36
const pcl_utils::StorageAdapter * get_storage_adapter(const char *id)
Get a storage adapter.
bool exists_pointcloud(const char *id)
Check if point cloud exists.