Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
voxel_structure.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2010-2012, Willow Garage, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of Willow Garage, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 *
37 */
38
39#pragma once
40
41namespace pcl
42{
43 namespace recognition
44 {
45 /** \brief This class is a box in R3 built of voxels ordered in a regular rectangular grid. Each voxel is of type T. */
46 template<class T, typename REAL = float>
48 {
49 public:
51 inline virtual ~VoxelStructure (){ this->clear();}
52
53 /** \brief Call this method before using an instance of this class. Parameter meaning is obvious. */
54 inline void
55 build (const REAL bounds[6], int num_of_voxels[3]);
56
57 /** \brief Release the memory allocated for the voxels. */
58 inline void
59 clear (){ delete[] voxels_; voxels_ = nullptr;}
60
61 /** \brief Returns a pointer to the voxel which contains p or NULL if p is not inside the structure. */
62 inline T*
63 getVoxel (const REAL p[3]);
64
65 /** \brief Returns a pointer to the voxel with integer id (x,y,z) or NULL if (x,y,z) is out of bounds. */
66 inline T*
67 getVoxel (int x, int y, int z) const;
68
69 /** \brief Returns the linear voxel array. */
70 const inline T*
71 getVoxels () const
72 {
73 return voxels_;
74 }
75
76 /** \brief Returns the linear voxel array. */
77 inline T*
79 {
80 return voxels_;
81 }
82
83 /** \brief Converts a linear id to a 3D id, i.e., computes the integer 3D coordinates of a voxel from its position in the voxel array.
84 *
85 * \param[in] linear_id the position of the voxel in the internal voxel array.
86 * \param[out] id3d an array of 3 integers for the integer coordinates of the voxel. */
87 inline void
88 compute3dId (int linear_id, int id3d[3]) const
89 {
90 // Compute the z axis id
93 // Compute the y axis id
94 id3d[1] = proj_xy / num_of_voxels_[0];
95 // Compute the x axis id
96 id3d[0] = proj_xy % num_of_voxels_[0];
97 }
98
99 /** \brief Returns the number of voxels in x, y and z direction. */
100 inline const int*
102 {
103 return (num_of_voxels_);
104 }
105
106 /** \brief Computes the center of the voxel with given integer coordinates.
107 *
108 * \param[in] id3 the integer coordinates along the x, y and z axis.
109 * \param[out] center */
110 inline void
111 computeVoxelCenter (const int id3[3], REAL center[3]) const
112 {
113 center[0] = min_center_[0] + static_cast<float> (id3[0])*spacing_[0];
114 center[1] = min_center_[1] + static_cast<float> (id3[1])*spacing_[1];
115 center[2] = min_center_[2] + static_cast<float> (id3[2])*spacing_[2];
116 }
117
118 /** \brief Returns the total number of voxels. */
119 inline int
121 {
122 return (total_num_of_voxels_);
123 }
124
125 /** \brief Returns the bounds of the voxel structure, which is pointer to the internal array of 6 doubles: (min_x, max_x, min_y, max_y, min_z, max_z). */
126 inline const float*
127 getBounds() const
128 {
129 return (bounds_);
130 }
131
132 /** \brief Copies the bounds of the voxel structure to 'b'. */
133 inline void
134 getBounds(REAL b[6]) const
135 {
136 b[0] = bounds_[0];
137 b[1] = bounds_[1];
138 b[2] = bounds_[2];
139 b[3] = bounds_[3];
140 b[4] = bounds_[4];
141 b[5] = bounds_[5];
142 }
143
144 /** \brief Returns the voxel spacing in x, y and z direction. That's the same as the voxel size along each axis. */
145 const REAL*
147 {
148 return (spacing_);
149 }
150
151 /** \brief Saves pointers to the voxels which are neighbors of the voxels which contains 'p'. The containing voxel is returned too.
152 * 'neighs' has to be an array of pointers with space for at least 27 pointers (27 = 3^3 which is the max number of neighbors). The */
153 inline int
154 getNeighbors (const REAL* p, T **neighs) const;
155
156 protected:
160 REAL spacing_[3]; // spacing between the voxel in x, y and z direction = voxel size in x, y and z direction
161 REAL min_center_[3]; // the center of the voxel with integer coordinates (0, 0, 0)
162 };
163 } // namespace recognition
164} // namespace pcl
165
166#include <pcl/recognition/impl/ransac_based/voxel_structure.hpp>
Iterator class for point clouds with or without given indices.
This class is a box in R3 built of voxels ordered in a regular rectangular grid.
void build(const REAL bounds[6], int num_of_voxels[3])
Call this method before using an instance of this class.
T * getVoxel(const REAL p[3])
Returns a pointer to the voxel which contains p or NULL if p is not inside the structure.
T * getVoxels()
Returns the linear voxel array.
const REAL * getVoxelSpacing() const
Returns the voxel spacing in x, y and z direction.
const T * getVoxels() const
Returns the linear voxel array.
int getNumberOfVoxels() const
Returns the total number of voxels.
const int * getNumberOfVoxelsXYZ() const
Returns the number of voxels in x, y and z direction.
void compute3dId(int linear_id, int id3d[3]) const
Converts a linear id to a 3D id, i.e., computes the integer 3D coordinates of a voxel from its positi...
void clear()
Release the memory allocated for the voxels.
int getNeighbors(const REAL *p, T **neighs) const
Saves pointers to the voxels which are neighbors of the voxels which contains 'p'.
const float * getBounds() const
Returns the bounds of the voxel structure, which is pointer to the internal array of 6 doubles: (min_...
void computeVoxelCenter(const int id3[3], REAL center[3]) const
Computes the center of the voxel with given integer coordinates.
void getBounds(REAL b[6]) const
Copies the bounds of the voxel structure to 'b'.