Fawkes API  Fawkes Development Version
storage_adapter.h
1 
2 /***************************************************************************
3  * storage_adapter.h - Utility to store differently typed point clouds in
4  * common container.
5  *
6  * Created: Fri Nov 30 16:40:51 2012
7  * Copyright 2011-2012 Tim Niemueller [www.niemueller.de]
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.
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 file in the doc directory.
21  */
22 
23 #ifndef __LIBS_PCL_UTILS_STORAGE_ADAPTER_H_
24 #define __LIBS_PCL_UTILS_STORAGE_ADAPTER_H_
25 
26 #include <pcl_utils/utils.h>
27 #include <pcl_utils/transforms.h>
28 #include <pcl/point_cloud.h>
29 
30 namespace fawkes {
31  namespace pcl_utils {
32 #if 0 /* just to make Emacs auto-indent happy */
33  }
34 }
35 #endif
36 
37 template <typename PointT>
39 
41  public:
42  /** Virtual empty destructor. */
43  virtual ~StorageAdapter() {};
44 
45  template <typename PointT>
46  bool is_pointtype() const;
47 
48  template <typename PointT>
50 
51  virtual void transform(const std::string &target_frame,
52  const tf::Transformer &transformer) = 0;
53 
54  virtual void transform(const std::string &target_frame,
55  const Time &target_time,
56  const std::string &fixed_frame,
57  const tf::Transformer &transformer) = 0;
58 
59  virtual const char * get_typename() = 0;
60  virtual StorageAdapter * clone() const = 0;
61  virtual size_t point_size() const = 0;
62  virtual unsigned int width() const = 0;
63  virtual unsigned int height() const = 0;
64  virtual size_t num_points() const = 0;
65  virtual void * data_ptr() const = 0;
66  virtual std::string frame_id() const = 0;
67  virtual void get_time(fawkes::Time &time) const = 0;
68 };
69 
70 template <typename PointT>
72 {
73  public:
74  /** Constructor.
75  * @param cloud cloud to encapsulate.
76  */
78  : cloud(cloud) {}
79 
80  /** Copy constructor.
81  * @param p storage adapter to copy
82  */
84  : cloud(p->cloud) {}
85 
86  /** The point cloud. */
88 
89  /** Get PCL shared pointer to cloud.
90  * @return PCL shared pointer to cloud
91  */
93  { return pcl_utils::cloudptr_from_refptr(cloud); }
94 
95  /** Get PCL const shared pointer to cloud.
96  * @return PCL const shared pointer to cloud
97  */
99  { return pcl_utils::cloudptr_from_refptr(cloud); }
100 
101  virtual StorageAdapter * clone() const;
102 
103  virtual void transform(const std::string &target_frame,
104  const tf::Transformer &transformer);
105 
106  virtual void transform(const std::string &target_frame,
107  const Time &target_time,
108  const std::string &fixed_frame,
109  const tf::Transformer &transformer);
110 
111  virtual const char * get_typename() { return typeid(this).name(); }
112  virtual size_t point_size() const { return sizeof(PointT); }
113  virtual unsigned int width() const { return cloud->width; }
114  virtual unsigned int height() const { return cloud->height; }
115  virtual size_t num_points() const { return cloud->points.size(); }
116  virtual void * data_ptr() const { return &cloud->points[0]; }
117  virtual std::string frame_id() const { return cloud->header.frame_id; }
118  virtual void get_time(fawkes::Time &time) const;
119 };
120 
121 template <typename PointT>
122 bool
124 {
126  dynamic_cast<const PointCloudStorageAdapter<PointT> *>(this);
127  return (!!pa);
128 }
129 
130 
131 template <typename PointT>
134 {
136  dynamic_cast<PointCloudStorageAdapter<PointT> *>(this);
137  if (!pa) {
138  throw Exception("PointCloud storage adapter is not of anticipated type");
139  }
140  return pa;
141 }
142 
143 
144 template <typename PointT>
147 {
148  return new PointCloudStorageAdapter<PointT>(this);
149 }
150 
151 
152 template <typename PointT>
153 void
155 {
156  pcl_utils::get_time(cloud, time);
157 }
158 
159 
160 template <typename PointT>
161 void
162 PointCloudStorageAdapter<PointT>::transform(const std::string &target_frame,
163  const tf::Transformer &transformer)
164 {
166  pcl_utils::transform_pointcloud(target_frame, **cloud, tmp, transformer);
167  **cloud = tmp;
168 }
169 
170 template <typename PointT>
171 void
172 PointCloudStorageAdapter<PointT>::transform(const std::string &target_frame,
173  const Time &target_time,
174  const std::string &fixed_frame,
175  const tf::Transformer &transformer)
176 {
178  pcl_utils::transform_pointcloud(target_frame, target_time, fixed_frame,
179  **cloud, tmp, transformer);
180  **cloud = tmp;
181 }
182 
183 
184 
185 } // end namespace pcl_utils
186 } // end namespace fawkes
187 
188 #endif
const RefPtr< pcl::PointCloud< PointT > > cloud
The point cloud.
virtual void get_time(fawkes::Time &time) const
Get last capture time.
Fawkes library namespace.
virtual unsigned int width() const =0
Get width of point cloud.
virtual unsigned int height() const
Get height of point cloud.
virtual StorageAdapter * clone() const =0
Clone this storage adapter.
A class for handling time.
Definition: time.h:91
virtual size_t num_points() const
Get numer of points in point cloud.
virtual size_t point_size() const =0
Get size of a point.
virtual unsigned int height() const =0
Get height of point cloud.
Adapter class for PCL point types.
virtual size_t point_size() const
Get size of a point.
bool is_pointtype() const
Check if storage adapter is for specified point type.
virtual std::string frame_id() const =0
Get frame ID of point cloud.
virtual std::string frame_id() const
Get frame ID of point cloud.
PointCloudStorageAdapter< PointT > * as_pointtype()
Transform to specific PointCloudStorageAdapter.
virtual unsigned int width() const
Get width of point cloud.
virtual void * data_ptr() const =0
Get pointer on data.
virtual void transform(const std::string &target_frame, const tf::Transformer &transformer)
Transform point cloud.
PointCloudStorageAdapter(RefPtr< pcl::PointCloud< PointT > > cloud)
Constructor.
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual StorageAdapter * clone() const
Clone this storage adapter.
PointCloudStorageAdapter(const PointCloudStorageAdapter< PointT > *p)
Copy constructor.
pcl::PointCloud< PointT >::Ptr cloud_ptr()
Get PCL shared pointer to cloud.
virtual void get_time(fawkes::Time &time) const =0
Get last capture time.
virtual const char * get_typename()
Get typename of storage adapter.
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:49
virtual const char * get_typename()=0
Get typename of storage adapter.
virtual ~StorageAdapter()
Virtual empty destructor.
virtual void * data_ptr() const
Get pointer on data.
pcl::PointCloud< PointT >::ConstPtr cloud_const_ptr()
Get PCL const shared pointer to cloud.
virtual size_t num_points() const =0
Get numer of points in point cloud.
Coordinate transforms between any two frames in a system.
Definition: transformer.h:68
virtual void transform(const std::string &target_frame, const tf::Transformer &transformer)=0
Transform point cloud.