Fawkes API  Fawkes Development Version
pointcloud_manager.h
1 
2 /***************************************************************************
3  * pointcloud_manager.h - PointCloud manager for aspect
4  *
5  * Created: Sun Nov 06 23:29: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 #ifndef __LIBS_PCL_UTILS_POINTCLOUD_MANAGER_H_
24 #define __LIBS_PCL_UTILS_POINTCLOUD_MANAGER_H_
25 
26 #include <core/exception.h>
27 #include <core/utils/refptr.h>
28 #include <core/utils/lock_map.h>
29 #include <core/threading/mutex_locker.h>
30 #include <utils/time/time.h>
31 
32 #include <pcl_utils/storage_adapter.h>
33 
34 #include <vector>
35 #include <string>
36 #include <stdint.h>
37 #include <typeinfo>
38 #include <cstring>
39 
40 namespace pcl {
41  template <typename PointT>
42  class PointCloud;
43 }
44 
45 namespace fawkes {
46 #if 0 /* just to make Emacs auto-indent happy */
47 }
48 #endif
49 
51 {
52  public:
54  virtual ~PointCloudManager();
55 
56  template <typename PointT>
57  void add_pointcloud(const char *id, RefPtr<pcl::PointCloud<PointT> > cloud);
58 
59  void remove_pointcloud(const char *id);
60 
61  template <typename PointT>
62  const RefPtr<const pcl::PointCloud<PointT> > get_pointcloud(const char *id);
63  bool exists_pointcloud(const char *id);
64 
65  /** Check if point cloud of specified type exists.
66  * @param id ID of point cloud to check
67  * @return true if the point cloud exists, false otherwise
68  */
69  template <typename PointT>
70  bool exists_pointcloud(const char *id);
71 
72 
73  std::vector<std::string> get_pointcloud_list() const;
74  const fawkes::LockMap<std::string, pcl_utils::StorageAdapter *> & get_pointclouds() const;
75  const pcl_utils::StorageAdapter * get_storage_adapter(const char *id);
76 
77  private:
79 };
80 
81 
82 template <typename PointT>
83 void
84 PointCloudManager::add_pointcloud(const char *id,
86 {
87  fawkes::MutexLocker lock(__clouds.mutex());
88 
89  if (__clouds.find(id) == __clouds.end()) {
90  __clouds[id] = new pcl_utils::PointCloudStorageAdapter<PointT>(cloud);
91  } else {
92  throw Exception("Cloud %s already registered");
93  }
94 }
95 
96 template <typename PointT>
98 PointCloudManager::get_pointcloud(const char *id)
99 {
100  fawkes::MutexLocker lock(__clouds.mutex());
101 
102  if (__clouds.find(id) != __clouds.end()) {
104  dynamic_cast<pcl_utils::PointCloudStorageAdapter<PointT> *>(__clouds[id]);
105 
106  if (!pa) {
107  // workaround for older compilers
108  if (strcmp(__clouds[id]->get_typename(),
109  typeid(pcl_utils::PointCloudStorageAdapter<PointT> *).name()) == 0)
110  {
111  return static_cast<pcl_utils::PointCloudStorageAdapter<PointT> *>(__clouds[id])->cloud;
112  }
113 
114  throw Exception("The desired point cloud is of a different type");
115  }
116  return pa->cloud;
117  } else {
118  throw Exception("No point cloud with ID '%s' registered", id);
119  }
120 }
121 
122 template <typename PointT>
123 bool
124 PointCloudManager::exists_pointcloud(const char *id)
125 {
126  try {
127  const RefPtr<const pcl::PointCloud<PointT> > p = get_pointcloud<PointT>(id);
128  return true;
129  } catch (Exception &e) {
130  return false;
131  }
132 
133 }
134 
135 } // end namespace fawkes
136 
137 #endif
const RefPtr< pcl::PointCloud< PointT > > cloud
The point cloud.
Definition: pointcloud.h:30
Fawkes library namespace.
Mutex locking helper.
Definition: mutex_locker.h:33
Adapter class for PCL point types.
Map with a lock.
Definition: lock_map.h:37
Point Cloud manager.
Base class for exceptions in Fawkes.
Definition: exception.h:36
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:49