Point Cloud Library (PCL)  1.14.1-dev
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 
81  static MaskMap
82  getDifferenceMask(const MaskMap& mask0, const MaskMap& mask1);
83 
84  inline void
85  set(const std::size_t x, const std::size_t y)
86  {
87  data_[y * width_ + x] = 255;
88  }
89 
90  inline void
91  unset(const std::size_t x, const std::size_t y)
92  {
93  data_[y * width_ + x] = 0;
94  }
95 
96  inline bool
97  isSet(const std::size_t x, const std::size_t y) const
98  {
99  return (data_[y * width_ + x] != 0);
100  }
101 
102  inline void
104  {
105  data_.assign(data_.size(), 0);
106  }
107 
108  inline unsigned char&
109  operator()(const std::size_t x, const std::size_t y)
110  {
111  return (data_[y * width_ + x]);
112  }
113 
114  inline const unsigned char&
115  operator()(const std::size_t x, const std::size_t y) const
116  {
117  return (data_[y * width_ + x]);
118  }
119 
120  void
121  erode(MaskMap& eroded_mask) const;
122 
123 private:
124  std::vector<unsigned char> data_;
125  std::size_t width_ = 0;
126  std::size_t height_ = 0;
127 };
128 
129 } // namespace pcl
std::size_t getWidth() const
Definition: mask_map.h:57
void set(const std::size_t x, const std::size_t y)
Definition: mask_map.h:85
void reset()
Definition: mask_map.h:103
virtual ~MaskMap()=default
bool isSet(const std::size_t x, const std::size_t y) const
Definition: mask_map.h:97
unsigned char * getData()
Definition: mask_map.h:69
void resize(std::size_t width, std::size_t height)
std::size_t getHeight() const
Definition: mask_map.h:63
MaskMap()=default
MaskMap(std::size_t width, std::size_t height)
void erode(MaskMap &eroded_mask) const
const unsigned char * getData() const
Definition: mask_map.h:75
static PCL_NODISCARD MaskMap getDifferenceMask(const MaskMap &mask0, const MaskMap &mask1)
unsigned char & operator()(const std::size_t x, const std::size_t y)
Definition: mask_map.h:109
void unset(const std::size_t x, const std::size_t y)
Definition: mask_map.h:91
const unsigned char & operator()(const std::size_t x, const std::size_t y) const
Definition: mask_map.h:115
Defines all the PCL and non-PCL macros used.
#define PCL_NODISCARD
Definition: pcl_macros.h:449
#define PCL_EXPORTS
Definition: pcl_macros.h:325