Point Cloud Library (PCL)  1.14.1-dev
repacks.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
35  */
36 
37 #ifndef __PCL_GPU_UTILS_REPACKS_HPP__
38 #define __PCL_GPU_UTILS_REPACKS_HPP__
39 
40 #include <pcl/pcl_macros.h>
41 #include <pcl/point_types.h>
42 
43 #include <pcl/gpu/containers/device_array.h>
44 
45 namespace pcl
46 {
47  namespace gpu
48  {
49  ///////////////////////////////////////
50  /// This is an experimental code ///
51  ///////////////////////////////////////
52 
53  const int NoCP = 0xFFFFFFFF;
54 
55  /** \brief Returns field copy operation code. */
56  inline int cp(int from, int to)
57  {
58  return ((to & 0xF) << 4) + (from & 0xF);
59  }
60 
61  /* Combines several field copy operations to one int (called rule) */
62  inline int rule(int cp1, int cp2 = NoCP, int cp3 = NoCP, int cp4 = NoCP)
63  {
64  return (cp1 & 0xFF) + ((cp2 & 0xFF) << 8) + ((cp3 & 0xFF) << 16) + ((cp4 & 0xFF) << 24);
65  }
66 
67  /* Combines performs all field copy operations in given rule array (can be 0, 1, or 16 copies) */
68  void copyFieldsImpl(int in_size, int out_size, int rules[4], int size, const void* input, void* output);
69 
70  template<typename PointIn, typename PointOut>
71  void copyFieldsEx(const DeviceArray<PointIn>& src, DeviceArray<PointOut>& dst, int rule1, int rule2 = NoCP, int rule3 = NoCP, int rule4 = NoCP)
72  {
73  int rules[4] = { rule1, rule2, rule3, rule4 };
74  dst.create(src.size());
75  copyFieldsImpl(sizeof(PointIn)/sizeof(int), sizeof(PointOut)/sizeof(int), rules, (int)src.size(), src.ptr(), dst.ptr());
76  }
77 
79  {
80  //PointXYZ.x (0) -> PointNormal.x (0)
81  //PointXYZ.y (1) -> PointNormal.y (1)
82  //PointXYZ.z (2) -> PointNormal.z (2)
83  copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
84  };
85 
87  {
88  //PointXYZ.normal_x (0) -> PointNormal.normal_x (4)
89  //PointXYZ.normal_y (1) -> PointNormal.normal_y (5)
90  //PointXYZ.normal_z (2) -> PointNormal.normal_z (6)
91  //PointXYZ.curvature (4) -> PointNormal.curvature (8)
92  copyFieldsEx(src, dst, rule(cp(0, 4), cp(1, 5), cp(2, 6), cp(4,8)));
93  };
94 
96  {
97  //PointXYZRGBL.x (0) -> PointXYZ.x (0)
98  //PointXYZRGBL.y (1) -> PointXYZ.y (1)
99  //PointXYZRGBL.z (2) -> PointXYZ.z (2)
100  copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
101  };
102 
104  {
105  //PointXYZRGB.x (0) -> PointXYZ.x (0)
106  //PointXYZRGB.y (1) -> PointXYZ.y (1)
107  //PointXYZRGB.z (2) -> PointXYZ.z (2)
108  copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
109  };
110 
112  {
113  //PointXYZRGBA.x (0) -> PointXYZ.x (0)
114  //PointXYZRGBA.y (1) -> PointXYZ.y (1)
115  //PointXYZRGBA.z (2) -> PointXYZ.z (2)
116  copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
117  };
118 
120  {
121  //PointXYZRGBL.z (2) -> float (1)
122  copyFieldsEx(src, dst, rule(cp(2, 0)));
123  };
124 
126  {
127  //PointXYZRGBL.z (2) -> float (1)
128  copyFieldsEx(src, dst, rule(cp(2, 0)));
129  };
130  }
131 }
132 
133 #endif /* __PCL_GPU_UTILS_REPACKS_HPP__ */
DeviceArray class
Definition: device_array.h:54
std::size_t size() const
Returns size in elements.
void create(std::size_t size)
Allocates internal buffer in GPU memory.
T * ptr()
Returns pointer for internal buffer in GPU memory.
Defines all the PCL implemented PointT point type structures.
void copyFieldsEx(const DeviceArray< PointIn > &src, DeviceArray< PointOut > &dst, int rule1, int rule2=NoCP, int rule3=NoCP, int rule4=NoCP)
Definition: repacks.hpp:71
int cp(int from, int to)
Returns field copy operation code.
Definition: repacks.hpp:56
int rule(int cp1, int cp2=NoCP, int cp3=NoCP, int cp4=NoCP)
Definition: repacks.hpp:62
void copyFieldsZ(const DeviceArray< PointXYZ > &src, DeviceArray< float > &dst)
Definition: repacks.hpp:119
const int NoCP
This is an experimental code ///.
Definition: repacks.hpp:53
void copyFields(const DeviceArray< PointXYZ > &src, DeviceArray< PointNormal > &dst)
Definition: repacks.hpp:78
void copyFieldsImpl(int in_size, int out_size, int rules[4], int size, const void *input, void *output)
Defines all the PCL and non-PCL macros used.