Point Cloud Library (PCL)  1.11.1
mask_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 #include <pcl/pcl_macros.h>
41 
42 #include <vector>
43 
44 namespace pcl {
46 public:
47  MaskMap() = default;
48 
49  MaskMap(std::size_t width, std::size_t height);
50 
51  virtual ~MaskMap() = default;
52 
53  void
54  resize(std::size_t width, std::size_t height);
55 
56  inline std::size_t
57  getWidth() const
58  {
59  return (width_);
60  }
61 
62  inline std::size_t
63  getHeight() const
64  {
65  return (height_);
66  }
67 
68  inline unsigned char*
70  {
71  return (data_.data());
72  }
73 
74  inline const unsigned char*
75  getData() const
76  {
77  return (data_.data());
78  }
79 
80  PCL_DEPRECATED(1, 12, "Use new version diff getDifferenceMask(mask0, mask1)")
81  static void
82  getDifferenceMask(const MaskMap& mask0, const MaskMap& mask1, MaskMap& diff_mask);
83 
85  static MaskMap
86  getDifferenceMask(const MaskMap& mask0, const MaskMap& mask1);
87 
88  inline void
89  set(const std::size_t x, const std::size_t y)
90  {
91  data_[y * width_ + x] = 255;
92  }
93 
94  inline void
95  unset(const std::size_t x, const std::size_t y)
96  {
97  data_[y * width_ + x] = 0;
98  }
99 
100  inline bool
101  isSet(const std::size_t x, const std::size_t y) const
102  {
103  return (data_[y * width_ + x] != 0);
104  }
105 
106  inline void
108  {
109  data_.assign(data_.size(), 0);
110  }
111 
112  inline unsigned char&
113  operator()(const std::size_t x, const std::size_t y)
114  {
115  return (data_[y * width_ + x]);
116  }
117 
118  inline const unsigned char&
119  operator()(const std::size_t x, const std::size_t y) const
120  {
121  return (data_[y * width_ + x]);
122  }
123 
124  void
125  erode(MaskMap& eroded_mask) const;
126 
127 private:
128  std::vector<unsigned char> data_;
129  std::size_t width_ = 0;
130  std::size_t height_ = 0;
131 };
132 
133 } // namespace pcl
#define PCL_NODISCARD
Definition: pcl_macros.h:444
std::size_t getHeight() const
Definition: mask_map.h:63
void reset()
Definition: mask_map.h:107
const unsigned char * getData() const
Definition: mask_map.h:75
unsigned char * getData()
Definition: mask_map.h:69
unsigned char & operator()(const std::size_t x, const std::size_t y)
Definition: mask_map.h:113
std::size_t getWidth() const
Definition: mask_map.h:57
const unsigned char & operator()(const std::size_t x, const std::size_t y) const
Definition: mask_map.h:119
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major...
Definition: pcl_macros.h:147
bool isSet(const std::size_t x, const std::size_t y) const
Definition: mask_map.h:101
#define PCL_EXPORTS
Definition: pcl_macros.h:328
Defines all the PCL and non-PCL macros used.
void unset(const std::size_t x, const std::size_t y)
Definition: mask_map.h:95