00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, 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 * 00037 */ 00038 00039 #ifndef PCL_RECOGNITION_VOXEL_STRUCTURE_H_ 00040 #define PCL_RECOGNITION_VOXEL_STRUCTURE_H_ 00041 00042 #include <cstdlib> 00043 00044 namespace pcl 00045 { 00046 namespace recognition 00047 { 00049 template<class T, typename REAL = float> 00050 class VoxelStructure 00051 { 00052 public: 00053 inline VoxelStructure (): voxels_(NULL){} 00054 inline virtual ~VoxelStructure (){ this->clear();} 00055 00057 inline void 00058 build (const REAL bounds[6], int num_of_voxels[3]); 00059 00061 inline void 00062 clear (){ if ( voxels_ ){ delete[] voxels_; voxels_ = NULL;}} 00063 00065 inline T* 00066 getVoxel (const REAL p[3]); 00067 00069 inline T* 00070 getVoxel (int x, int y, int z) const; 00071 00073 const inline T* 00074 getVoxels () const 00075 { 00076 return voxels_; 00077 } 00078 00080 inline T* 00081 getVoxels () 00082 { 00083 return voxels_; 00084 } 00085 00090 inline void 00091 compute3dId (int linear_id, int id3d[3]) const 00092 { 00093 // Compute the z axis id 00094 id3d[2] = linear_id / num_of_voxels_xy_plane_; 00095 int proj_xy = linear_id % num_of_voxels_xy_plane_; 00096 // Compute the y axis id 00097 id3d[1] = proj_xy / num_of_voxels_[0]; 00098 // Compute the x axis id 00099 id3d[0] = proj_xy % num_of_voxels_[0]; 00100 } 00101 00103 inline const int* 00104 getNumberOfVoxelsXYZ() const 00105 { 00106 return (num_of_voxels_); 00107 } 00108 00113 inline void 00114 computeVoxelCenter (const int id3[3], REAL center[3]) const 00115 { 00116 center[0] = min_center_[0] + static_cast<float> (id3[0])*spacing_[0]; 00117 center[1] = min_center_[1] + static_cast<float> (id3[1])*spacing_[1]; 00118 center[2] = min_center_[2] + static_cast<float> (id3[2])*spacing_[2]; 00119 } 00120 00122 inline int 00123 getNumberOfVoxels() const 00124 { 00125 return (total_num_of_voxels_); 00126 } 00127 00129 inline const float* 00130 getBounds() const 00131 { 00132 return (bounds_); 00133 } 00134 00136 inline void 00137 getBounds(REAL b[6]) const 00138 { 00139 b[0] = bounds_[0]; 00140 b[1] = bounds_[1]; 00141 b[2] = bounds_[2]; 00142 b[3] = bounds_[3]; 00143 b[4] = bounds_[4]; 00144 b[5] = bounds_[5]; 00145 } 00146 00148 const REAL* 00149 getVoxelSpacing() const 00150 { 00151 return (spacing_); 00152 } 00153 00156 inline int 00157 getNeighbors (const REAL* p, T **neighs) const; 00158 00159 protected: 00160 T *voxels_; 00161 int num_of_voxels_[3], num_of_voxels_xy_plane_, total_num_of_voxels_; 00162 REAL bounds_[6]; 00163 REAL spacing_[3]; // spacing betwen the voxel in x, y and z direction = voxel size in x, y and z direction 00164 REAL min_center_[3]; // the center of the voxel with integer coordinates (0, 0, 0) 00165 }; 00166 } // namespace recognition 00167 } // namespace pcl 00168 00169 #include <pcl/recognition/impl/ransac_based/voxel_structure.hpp> 00170 00171 #endif // PCL_RECOGNITION_VOXEL_STRUCTURE_H_