Point Cloud Library (PCL)  1.14.1-dev
distance_map.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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 #pragma once
39 
40 namespace pcl
41 {
42 
43  /** \brief Represents a distance map obtained from a distance transformation.
44  * \author Stefan Holzer
45  */
47  {
48  public:
49  /** \brief Constructor. */
50  DistanceMap () : data_ (0) {}
51  /** \brief Destructor. */
52  virtual ~DistanceMap () = default;
53 
54  /** \brief Returns the width of the map. */
55  inline std::size_t
56  getWidth () const
57  {
58  return (width_);
59  }
60 
61  /** \brief Returns the height of the map. */
62  inline std::size_t
63  getHeight () const
64  {
65  return (height_);
66  }
67 
68  /** \brief Returns a pointer to the beginning of map. */
69  inline float *
71  {
72  return (data_.data());
73  }
74 
75  /** \brief Resizes the map to the specified size.
76  * \param[in] width the new width of the map.
77  * \param[in] height the new height of the map.
78  */
79  void
80  resize (const std::size_t width, const std::size_t height)
81  {
82  data_.resize (width*height);
83  width_ = width;
84  height_ = height;
85  }
86 
87  /** \brief Operator to access an element of the map.
88  * \param[in] col_index the column index of the element to access.
89  * \param[in] row_index the row index of the element to access.
90  */
91  inline float &
92  operator() (const std::size_t col_index, const std::size_t row_index)
93  {
94  return (data_[row_index*width_ + col_index]);
95  }
96 
97  /** \brief Operator to access an element of the map.
98  * \param[in] col_index the column index of the element to access.
99  * \param[in] row_index the row index of the element to access.
100  */
101  inline const float &
102  operator() (const std::size_t col_index, const std::size_t row_index) const
103  {
104  return (data_[row_index*width_ + col_index]);
105  }
106 
107  protected:
108  /** \brief The storage for the distance map data. */
109  std::vector<float> data_;
110  /** \brief The width of the map. */
111  std::size_t width_{0};
112  /** \brief The height of the map. */
113  std::size_t height_{0};
114  };
115 
116 }
Represents a distance map obtained from a distance transformation.
Definition: distance_map.h:47
std::size_t getWidth() const
Returns the width of the map.
Definition: distance_map.h:56
DistanceMap()
Constructor.
Definition: distance_map.h:50
std::size_t getHeight() const
Returns the height of the map.
Definition: distance_map.h:63
float * getData()
Returns a pointer to the beginning of map.
Definition: distance_map.h:70
std::size_t height_
The height of the map.
Definition: distance_map.h:113
virtual ~DistanceMap()=default
Destructor.
float & operator()(const std::size_t col_index, const std::size_t row_index)
Operator to access an element of the map.
Definition: distance_map.h:92
void resize(const std::size_t width, const std::size_t height)
Resizes the map to the specified size.
Definition: distance_map.h:80
std::size_t width_
The width of the map.
Definition: distance_map.h:111
std::vector< float > data_
The storage for the distance map data.
Definition: distance_map.h:109