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/threading/mutex_locker.h>
28#include <core/utils/lock_map.h>
29#include <core/utils/refptr.h>
30#include <pcl_utils/storage_adapter.h>
31#include <utils/time/time.h>
32
33#include <cstring>
34#include <stdint.h>
35#include <string>
36#include <typeinfo>
37#include <vector>
38
39namespace pcl {
40template <typename PointT>
41class PointCloud;
42}
43
44namespace fawkes {
45
47{
48public:
50 virtual ~PointCloudManager();
51
52 template <typename PointT>
53 void add_pointcloud(const char *id, RefPtr<pcl::PointCloud<PointT>> cloud);
54
55 void remove_pointcloud(const char *id);
56
57 template <typename PointT>
59 bool exists_pointcloud(const char *id);
60
61 /** Check if point cloud of specified type exists.
62 * @param id ID of point cloud to check
63 * @return true if the point cloud exists, false otherwise
64 */
65 template <typename PointT>
66 bool exists_pointcloud(const char *id);
67
68 std::vector<std::string> get_pointcloud_list() const;
71
72private:
74};
75
76template <typename PointT>
77void
79{
80 fawkes::MutexLocker lock(clouds_.mutex());
81
82 if (clouds_.find(id) == clouds_.end()) {
83 clouds_[id] = new pcl_utils::PointCloudStorageAdapter<PointT>(cloud);
84 } else {
85 throw Exception("Cloud %s already registered", id);
86 }
87}
88
89template <typename PointT>
92{
93 fawkes::MutexLocker lock(clouds_.mutex());
94
95 if (clouds_.find(id) != clouds_.end()) {
97 dynamic_cast<pcl_utils::PointCloudStorageAdapter<PointT> *>(clouds_[id]);
98
99 if (!pa) {
100 // workaround for older compilers
101 if (strcmp(clouds_[id]->get_typename(),
103 == 0) {
104 return static_cast<pcl_utils::PointCloudStorageAdapter<PointT> *>(clouds_[id])->cloud;
105 }
106
107 throw Exception("The desired point cloud is of a different type");
108 }
109 return pa->cloud;
110 } else {
111 throw Exception("No point cloud with ID '%s' registered", id);
112 }
113}
114
115template <typename PointT>
116bool
118{
119 try {
120 const RefPtr<const pcl::PointCloud<PointT>> p = get_pointcloud<PointT>(id);
121 return true;
122 } catch (Exception &e) {
123 return false;
124 }
125}
126
127} // end namespace fawkes
128
129#endif
Base class for exceptions in Fawkes.
Definition: exception.h:36
Map with a lock.
Definition: lock_map.h:36
Mutex locking helper.
Definition: mutex_locker.h:34
Point Cloud manager.
virtual ~PointCloudManager()
Destructor.
void remove_pointcloud(const char *id)
Remove the point cloud.
std::vector< std::string > get_pointcloud_list() const
Get list of point cloud IDs.
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.
const RefPtr< const pcl::PointCloud< PointT > > get_pointcloud(const char *id)
Get point cloud.
const fawkes::LockMap< std::string, pcl_utils::StorageAdapter * > & get_pointclouds() const
Get map of point clouds.
void add_pointcloud(const char *id, RefPtr< pcl::PointCloud< PointT > > cloud)
Add point cloud.
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:50
Adapter class for PCL point types.
const RefPtr< pcl::PointCloud< PointT > > cloud
The point cloud.
Fawkes library namespace.