Fawkes API  Fawkes Development Version
pcl.cpp
1 
2 /***************************************************************************
3  * pcl.cpp - Convert PCL buffer to PointCloud structure
4  *
5  * Created: Wed Nov 02 21:17:35 2011
6  * Copyright 2011 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 <fvutils/adapters/pcl.h>
24 #include <fvutils/ipc/shm_image.h>
25 #include <fvutils/color/colorspaces.h>
26 #include <fvutils/base/types.h>
27 #include <core/exception.h>
28 
29 using namespace fawkes;
30 
31 namespace firevision {
32 #if 0 /* just to make Emacs auto-indent happy */
33 }
34 #endif
35 
36 void
37 convert_buffer_to_pcl(const SharedMemoryImageBuffer *buffer,
39 {
40  if (buffer->colorspace() != CARTESIAN_3D_FLOAT) {
41  throw Exception("Invalid colorspace, expected CARTESIAN_3D_FLOAT");
42  }
43 
44  const pcl_point_t *pclbuf = (const pcl_point_t*)buffer->buffer();
45 
46  const unsigned int width = buffer->width();
47  const unsigned int height = buffer->height();
48 
49  pcl.height = height;
50  pcl.width = width;
51  pcl.is_dense = false;
52  pcl.points.resize(width * height);
53 
54  for (unsigned int i = 0; i < width * height; ++i) {
55  pcl::PointXYZ &p = pcl.points[i];
56  const pcl_point_t &pt = pclbuf[i];
57  p.x = pt.x;
58  p.y = pt.y;
59  p.z = pt.z;
60  }
61 
62 }
63 
64 
65 void
66 convert_buffer_to_pcl(const SharedMemoryImageBuffer *buffer,
68 {
69  if (buffer->colorspace() != CARTESIAN_3D_FLOAT) {
70  throw Exception("Invalid colorspace, expected CARTESIAN_3D_FLOAT");
71  }
72 
73  const pcl_point_t *pclbuf = (const pcl_point_t*)buffer->buffer();
74 
75  const unsigned int width = buffer->width();
76  const unsigned int height = buffer->height();
77 
78  pcl.height = height;
79  pcl.width = width;
80  pcl.is_dense = false;
81  pcl.points.resize(width * height);
82 
83  for (unsigned int i = 0; i < width * height; ++i) {
84  pcl::PointXYZRGB &p = pcl.points[i];
85  const pcl_point_t &pt = pclbuf[i];
86  p.x = pt.x;
87  p.y = pt.y;
88  p.z = pt.z;
89  p.r = p.g = p.b = 255;
90  }
91 }
92 
93 
94 } // end namespace firevision
Definition: pointcloud.h:30
Fawkes library namespace.
Base class for exceptions in Fawkes.
Definition: exception.h:36