|
Point Cloud Library (PCL)
1.5.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: point_operators.h 3657 2011-12-26 23:11:38Z nizar $ 00037 * 00038 */ 00039 00040 #ifndef PCL_COMMON_POINT_OPERATORS_H 00041 #define PCL_COMMON_POINT_OPERATORS_H 00042 00043 #include <pcl/point_types.h> 00044 00045 namespace pcl 00046 { 00047 namespace common 00048 { 00049 00059 template <typename PointIN, typename PointOUT> 00060 struct PointOperators 00061 { 00062 typedef PointIN PointIn; 00063 typedef PointOUT PointOut; 00064 }; 00065 00066 struct PointXYZItoIntensity : PointOperators <pcl::PointXYZI, float> 00067 { 00068 float 00069 operator () () 00070 { 00071 return 0; 00072 } 00073 00074 float 00075 operator () (pcl::PointXYZI& p) 00076 { 00077 return (p.intensity); 00078 } 00079 00080 float 00081 add (const pcl::PointXYZI& lhs, const pcl::PointXYZI& rhs) 00082 { 00083 return (lhs.intensity + rhs.intensity); 00084 } 00085 00086 float 00087 dot (const float& scalar, const pcl::PointXYZI& p) 00088 { 00089 return (scalar * p.intensity); 00090 } 00091 00092 float 00093 dot (const pcl::PointXYZI& p, const float& scalar) 00094 { 00095 return dot (scalar, p); 00096 } 00097 }; 00098 00099 struct PointXYZRGBtoIntensity : PointOperators <pcl::PointXYZRGB, float> 00100 { 00101 float 00102 operator () () 00103 { 00104 return 0; 00105 } 00106 00107 float 00108 operator () (pcl::PointXYZRGB& p) 00109 { 00110 return ((299*p.r + 587*p.g + 114*p.b)/1000.0f); 00111 } 00112 00113 float 00114 add (const pcl::PointXYZRGB& lhs, const pcl::PointXYZRGB& rhs) 00115 { 00116 return ((299*(lhs.r + rhs.r) + 587*(lhs.g + rhs.g) + 114*(lhs.b + rhs.b))/1000.0); 00117 } 00118 00119 float 00120 dot (const float& scalar, const pcl::PointXYZRGB& p) 00121 { 00122 return (scalar * (299*p.r + 587*p.g + 114*p.b)/1000.0); 00123 } 00124 00125 float 00126 dot (const pcl::PointXYZRGB& p, const float& scalar) 00127 { 00128 return (dot (p, scalar)); 00129 } 00130 }; 00131 00132 struct PointXYZItoPointXYZI : PointOperators <pcl::PointXYZI, pcl::PointXYZI> 00133 { 00134 pcl::PointXYZI 00135 operator () () 00136 { 00137 pcl::PointXYZI zero; 00138 zero.x = 0; zero.y = 0; zero.z = 0; zero.intensity = 0; 00139 return zero; 00140 } 00141 00142 const pcl::PointXYZI& 00143 operator () (const pcl::PointXYZI& p) 00144 { 00145 return (p); 00146 } 00147 00148 pcl::PointXYZI& 00149 operator () (pcl::PointXYZI& p) 00150 { 00151 return (p); 00152 } 00153 00154 // pcl::PointXYZI& 00155 // operator= (pcl::PointXYZI& p, int 0) 00156 // { 00157 // p.x = p.y = p.z = p.intensity = 0; 00158 // return (p); 00159 // } 00160 00161 pcl::PointXYZI 00162 add (const pcl::PointXYZI& lhs, const pcl::PointXYZI& rhs) 00163 { 00164 pcl::PointXYZI result; 00165 result.x = lhs.x + rhs.x; 00166 result.y = lhs.y + rhs.y; 00167 result.z = lhs.z + rhs.z; 00168 result.intensity = lhs.intensity + rhs.intensity; 00169 return (result); 00170 } 00171 00172 00173 pcl::PointXYZI 00174 minus (const pcl::PointXYZI& lhs, const pcl::PointXYZI& rhs) 00175 { 00176 pcl::PointXYZI result; 00177 result.x = lhs.x - rhs.x; 00178 result.y = lhs.y - rhs.y; 00179 result.z = lhs.z - rhs.z; 00180 result.intensity = lhs.intensity - rhs.intensity; 00181 return (result); 00182 } 00183 00184 pcl::PointXYZI 00185 dot (const float& scalar, const pcl::PointXYZI& p) 00186 { 00187 pcl::PointXYZI result; 00188 result.x = scalar * p.x; 00189 result.y = scalar * p.y; 00190 result.z = scalar * p.z; 00191 result.intensity = scalar * p.intensity; 00192 return (result); 00193 } 00194 00195 pcl::PointXYZI 00196 dot (const pcl::PointXYZI& p, const float& scalar) 00197 { 00198 return (dot (scalar, p)); 00199 } 00200 00201 pcl::PointXYZI& 00202 plus_assign (pcl::PointXYZI& lhs, const pcl::PointXYZI& rhs) 00203 { 00204 lhs.x+= rhs.x; lhs.y+= rhs.y; lhs.z+= rhs.z; lhs.intensity+= rhs.intensity; 00205 return (lhs); 00206 } 00207 }; 00208 00209 struct PointXYZRGBtoPointXYZRGB : PointOperators <pcl::PointXYZRGB, pcl::PointXYZRGB> 00210 { 00211 pcl::PointXYZRGB 00212 operator () () 00213 { 00214 pcl::PointXYZRGB zero; 00215 zero.x = 0; zero.y = 0; zero.z = 0; zero.r = 0; zero.g = 0; zero.b = 0; 00216 return zero; 00217 } 00218 00219 pcl::PointXYZRGB 00220 operator () (pcl::PointXYZRGB& p) 00221 { 00222 return (p); 00223 } 00224 00225 pcl::PointXYZRGB 00226 add (const pcl::PointXYZRGB& lhs, const pcl::PointXYZRGB& rhs) 00227 { 00228 pcl::PointXYZRGB result; 00229 result.x = lhs.x + rhs.x; result.y = lhs.y + rhs.y; result.z = lhs.z + rhs.z; 00230 result.r = lhs.r + rhs.r; result.g = lhs.g + rhs.g; result.b = lhs.b + rhs.b; 00231 return (result); 00232 } 00233 00234 pcl::PointXYZRGB 00235 dot (const float& scalar, const pcl::PointXYZRGB& p) 00236 { 00237 pcl::PointXYZRGB result; 00238 result.x = scalar * p.x; result.y = scalar * p.y; result.z = scalar * p.z; 00239 result.r = scalar * p.r; result.g = scalar * p.g; result.b = scalar * p.b; 00240 return (result); 00241 } 00242 00243 pcl::PointXYZRGB& 00244 plus_assign (pcl::PointXYZRGB& lhs, const pcl::PointXYZRGB& rhs) 00245 { 00246 lhs.x+= rhs.x; lhs.y+= rhs.y; lhs.z+= rhs.z; 00247 lhs.r+= rhs.r; lhs.g+= rhs.g; lhs.b+= rhs.b; 00248 return (lhs); 00249 } 00250 }; 00251 00252 struct PointXYZRGBtoPointXYZI : PointOperators <pcl::PointXYZRGB, pcl::PointXYZI> 00253 { 00254 PointXYZI 00255 operator () (pcl::PointXYZRGB& p) 00256 { 00257 pcl::PointXYZI result; 00258 result.x = p.x; result.y = p.y; result.z = p.z; 00259 result.intensity = (299*p.r + 587*p.g + 114*p.b)/1000.0f; 00260 return (result); 00261 } 00262 00263 pcl::PointXYZI 00264 add (const pcl::PointXYZRGB& lhs, const pcl::PointXYZRGB& rhs) 00265 { 00266 pcl::PointXYZI result; 00267 result.x = lhs.x + rhs.x; result.y = lhs.y + rhs.y; result.z = lhs.z + rhs.z; 00268 result.intensity = (299*(lhs.r + rhs.r) + 587*(lhs.g + rhs.g) + 114*(lhs.b + rhs.b))/1000.0; 00269 return (result); 00270 } 00271 00272 pcl::PointXYZI 00273 dot (const float& scalar, const pcl::PointXYZRGB& p) 00274 { 00275 pcl::PointXYZI result; 00276 result.x = scalar * p.x; result.y = scalar * p.y; result.z = scalar * p.z; 00277 result.intensity = scalar * (299*p.r + 587*p.g + 114*p.b)/1000.0; 00278 return (result); 00279 } 00280 00281 pcl::PointXYZI& 00282 plus_assign (pcl::PointXYZI& lhs, const pcl::PointXYZI& rhs) 00283 { 00284 lhs.x+= rhs.x; lhs.y+= rhs.y; lhs.z+= rhs.z; lhs.intensity+= rhs.intensity; 00285 return (lhs); 00286 } 00287 }; 00288 } 00289 } 00290 00291 #endif
1.8.0