Fawkes API  Fawkes Development Version
pointcloud_manager.cpp
1 
2 /***************************************************************************
3  * pointcloud_manager.cpp - PointCloud manager for aspect
4  *
5  * Created: Sun Nov 06 23:49:36 2011
6  * Copyright 2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <aspect/pointcloud/pointcloud_manager.h>
25 
26 namespace fawkes {
27 #if 0 /* just to make Emacs auto-indent happy */
28 }
29 #endif
30 
31 
32 /** @class PointCloudManager <aspect/pointcloud/pointcloud_manager.h>
33  * Point Cloud manager.
34  * This class manages a number of points clouds and acts as a hub to
35  * distribute them.
36  * @author Tim Niemueller
37  *
38  * @fn void PointCloudManager::add_pointcloud(const char *id, RefPtr<pcl::PointCloud<PointT> > cloud)
39  * Add point cloud.
40  * @param id ID of point cloud to add, must be unique
41  * @param cloud refptr to point cloud
42  *
43  * @fn const RefPtr<const pcl::PointCloud<PointT> > PointCloudManager::get_pointcloud(const char *id)
44  * Get point cloud.
45  * @param id ID of point cloud to retrieve
46  * @return point cloud
47  * @exception Exception thrown if point cloud for given ID does not exist
48  *
49  */
50 
51 /** @class PointCloudManager::StorageAdapter <aspect/pointcloud/pointcloud_manager.h>
52  * Adapter base class.
53  * The adapter base class is required to store point clouds of
54  * arbitrary point types.
55  * @author Tim Niemueller
56  *
57  * @fn bool PointCloudManager::StorageAdapter::is_pointtype() const
58  * Check if storage adapter is for specified point type.
59  * @return true if storage adapter is for specified point type, false otherwise
60  *
61  * @fn template <PointT> PointCloudManager::PointCloudStorageAdapter<PointT> * PointCloudManager::StorageAdapter::as_pointtype() const
62  * Transform to specific PointCloudStorageAdapter.
63  * @return transformed PointCloudStorageAdapter
64  * @exception Exception thrown if storage adapter is not of requested point type or does not exist
65  *
66  * @fn PointCloudManager::StorageAdapter * PointCloudManager::StorageAdapter::clone() const
67  * Clone this storage adapter.
68  * @return cloned copy
69  *
70  * @fn const char * PointCloudManager::StorageAdapter::get_typename()
71  * Get typename of storage adapter.
72  * @return type name
73  *
74  * @fn size_t PointCloudManager::StorageAdapter::point_size() const
75  * Get size of a point.
76  * @return size in bytes of a single point
77  *
78  * @fn unsigned int PointCloudManager::StorageAdapter::width() const
79  * Get width of point cloud.
80  * @return width of point cloud
81  *
82  * @fn unsigned int PointCloudManager::StorageAdapter::height() const
83  * Get height of point cloud.
84  * @return height of point cloud
85  *
86  * @fn size_t PointCloudManager::StorageAdapter::num_points() const
87  * Get numer of points in point cloud.
88  * @return number of points
89  *
90  * @fn void * PointCloudManager::StorageAdapter::data_ptr() const
91  * Get pointer on data.
92  * @return pointer on data
93  *
94  * @fn void PointCloudManager::StorageAdapter::get_time(fawkes::Time &time) const
95  * Get last capture time.
96  * @param time upon return contains last capture time
97  */
98 
99 
100 /** Virtual empty destructor. */
102 {
103 }
104 
105 
106 /** @class PointCloudManager::PointCloudStorageAdapter <aspect/pointcloud/pointcloud_manager.h>
107  * Adapter class for PCL point types.
108  * The adapter class is required to store point clouds of arbitrary point types.
109  * @author Tim Niemueller
110  */
111 
112 /** Constructor. */
114 {
115 }
116 
117 /** Destructor. */
119 {
121  for (c = __clouds.begin(); c != __clouds.end(); ++c) {
122  delete c->second;
123  }
124 
125  __clouds.clear();
126 }
127 
128 
129 /** Remove the point cloud.
130  * @param id ID of point cloud to remove
131  */
132 void
134 {
135  MutexLocker lock(__clouds.mutex());
136 
137  if (__clouds.find(id) != __clouds.end()) {
138  delete __clouds[id];
139  __clouds.erase(id);
140  }
141 }
142 
143 /** Check if point cloud exists
144  * @param id ID of point cloud to check
145  * @return true if the point cloud exists, false otherwise
146  */
147 bool
149 {
150  MutexLocker lock(__clouds.mutex());
151 
152  return (__clouds.find(id) != __clouds.end());
153 }
154 
155 
156 /** Get list of point cloud IDs.
157  * @return list of point cloud IDs
158  */
159 std::vector<std::string>
161 {
162  MutexLocker lock(__clouds.mutex());
163 
164  std::vector<std::string> rv;
165  rv.clear();
167  for (c = __clouds.begin(); c != __clouds.end(); ++c) {
168  rv.push_back(c->first);
169  }
170  return rv;
171 }
172 
173 
174 /** Get map of point clouds.
175  * Use with care. Do not use in ROS-enabled plugins unless you are aware
176  * of sensor_msgs and std_msgs incompatibilities between standalone PCL
177  * and ROS!
178  * @return map from ID to storage adapter
179  */
182 {
183  return __clouds;
184 }
185 
186 
187 /** Get a storage adapter.
188  * Use with care. Do not use in ROS-enabled plugins unless you are aware
189  * of sensor_msgs and std_msgs incompatibilities between standalone PCL
190  * and ROS!
191  * @param id ID of point clouds whose storage adapter to retrieve
192  * @return storage adapter for given ID
193  * @exception Exception thrown if ID is unknown
194  */
197 {
198  MutexLocker lock(__clouds.mutex());
199 
200  if (__clouds.find(id) == __clouds.end()) {
201  throw Exception("PointCloud '%s' unknown", id);
202  }
203  return __clouds[id];
204 }
205 
206 
207 
208 } // 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.
const StorageAdapter * get_storage_adapter(const char *id)
Get a storage adapter.
Fawkes library namespace.
Mutex locking helper.
Definition: mutex_locker.h:33
const fawkes::LockMap< std::string, StorageAdapter * > & get_pointclouds() const
Get map of point clouds.
virtual ~StorageAdapter()
Virtual empty destructor.
virtual ~PointCloudManager()
Destructor.
Map with a lock.
Definition: lock_map.h:37
Base class for exceptions in Fawkes.
Definition: exception.h:36
bool exists_pointcloud(const char *id)
Check if point cloud exists.