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