Point Cloud Library (PCL)  1.8.0
orr_octree_zprojection.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 /*
40  * orr_octree_zprojection.h
41  *
42  * Created on: Nov 17, 2012
43  * Author: papazov
44  */
45 
46 #ifndef ORR_OCTREE_ZPROJECTION_H_
47 #define ORR_OCTREE_ZPROJECTION_H_
48 
49 #include "orr_octree.h"
50 #include <pcl/pcl_exports.h>
51 #include <set>
52 
53 
54 namespace pcl
55 {
56  namespace recognition
57  {
58  class ORROctree;
59 
60  class PCL_EXPORTS ORROctreeZProjection
61  {
62  public:
63  class Pixel
64  {
65  public:
66  Pixel (int id): id_ (id) {}
67 
68  inline void
69  set_z1 (float z1) { z1_ = z1;}
70 
71  inline void
72  set_z2 (float z2) { z2_ = z2;}
73 
74  float
75  z1 () const { return z1_;}
76 
77  float
78  z2 () const { return z2_;}
79 
80  int
81  getId () const { return id_;}
82 
83  protected:
84  float z1_, z2_;
85  int id_;
86  };
87 
88  public:
89  class Set
90  {
91  public:
92  Set (int x, int y)
93  : nodes_ (compare_nodes_z), x_ (x), y_ (y)
94  {}
95 
96  static inline bool
98  {
99  return static_cast<bool> (node1->getData ()->get3dIdZ () < node2->getData ()->get3dIdZ ());
100  }
101 
102  inline void
103  insert (ORROctree::Node* leaf) { nodes_.insert(leaf);}
104 
105  inline std::set<ORROctree::Node*, bool(*)(ORROctree::Node*,ORROctree::Node*)>&
106  get_nodes (){ return nodes_;}
107 
108  inline int
109  get_x () const { return x_;}
110 
111  inline int
112  get_y () const { return y_;}
113 
114  protected:
115  std::set<ORROctree::Node*, bool(*)(ORROctree::Node*,ORROctree::Node*)> nodes_;
116  int x_, y_;
117  };
118 
119  public:
121  : pixels_(NULL),
122  sets_(NULL)
123  {}
124  virtual ~ORROctreeZProjection (){ this->clear();}
125 
126  void
127  build (const ORROctree& input, float eps_front, float eps_back);
128 
129  void
130  clear ();
131 
132  inline void
133  getPixelCoordinates (const float* p, int& x, int& y) const
134  {
135  x = static_cast<int> ((p[0] - bounds_[0])*inv_pixel_size_);
136  y = static_cast<int> ((p[1] - bounds_[2])*inv_pixel_size_);
137  }
138 
139  inline const Pixel*
140  getPixel (const float* p) const
141  {
142  int x, y; this->getPixelCoordinates (p, x, y);
143 
144  if ( x < 0 || x >= num_pixels_x_ ) return (NULL);
145  if ( y < 0 || y >= num_pixels_y_ ) return (NULL);
146 
147  return (pixels_[x][y]);
148  }
149 
150  inline Pixel*
151  getPixel (const float* p)
152  {
153  int x, y; this->getPixelCoordinates (p, x, y);
154 
155  if ( x < 0 || x >= num_pixels_x_ ) return (NULL);
156  if ( y < 0 || y >= num_pixels_y_ ) return (NULL);
157 
158  return (pixels_[x][y]);
159  }
160 
161  inline const std::set<ORROctree::Node*, bool(*)(ORROctree::Node*,ORROctree::Node*)>*
162  getOctreeNodes (const float* p) const
163  {
164  int x, y; this->getPixelCoordinates (p, x, y);
165 
166  if ( x < 0 || x >= num_pixels_x_ ) return (NULL);
167  if ( y < 0 || y >= num_pixels_y_ ) return (NULL);
168 
169  if ( !sets_[x][y] )
170  return NULL;
171 
172  return (&sets_[x][y]->get_nodes ());
173  }
174 
175  inline std::list<Pixel*>&
176  getFullPixels (){ return full_pixels_;}
177 
178  inline const Pixel*
179  getPixel (int i, int j) const
180  {
181  return pixels_[i][j];
182  }
183 
184  inline float
185  getPixelSize () const
186  {
187  return pixel_size_;
188  }
189 
190  inline const float*
191  getBounds () const
192  {
193  return bounds_;
194  }
195 
196  /** \brief Get the width ('num_x') and height ('num_y') of the image. */
197  inline void
198  getNumberOfPixels (int& num_x, int& num_y) const
199  {
200  num_x = num_pixels_x_;
201  num_y = num_pixels_y_;
202  }
203 
204  protected:
205  float pixel_size_, inv_pixel_size_, bounds_[4], extent_x_, extent_y_;
206  int num_pixels_x_, num_pixels_y_, num_pixels_;
208  Set ***sets_;
209  std::list<Set*> full_sets_;
210  std::list<Pixel*> full_pixels_;
211  };
212  } // namespace recognition
213 } // namespace pcl
214 
215 
216 #endif /* ORR_OCTREE_ZPROJECTION_H_ */
std::set< ORROctree::Node *, bool(*)(ORROctree::Node *, ORROctree::Node *)> nodes_
const Pixel * getPixel(const float *p) const
void getPixelCoordinates(const float *p, int &x, int &y) const
const std::set< ORROctree::Node *, bool(*)(ORROctree::Node *, ORROctree::Node *)> * getOctreeNodes(const float *p) const
std::set< ORROctree::Node *, bool(*)(ORROctree::Node *, ORROctree::Node *)> & get_nodes()
static bool compare_nodes_z(ORROctree::Node *node1, ORROctree::Node *node2)
const Pixel * getPixel(int i, int j) const
void getNumberOfPixels(int &num_x, int &num_y) const
Get the width (&#39;num_x&#39;) and height (&#39;num_y&#39;) of the image.
That&#39;s a very specialized and simple octree class.
Definition: orr_octree.h:71