Point Cloud Library (PCL)  1.7.0
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 #ifndef PCL_FEATURES_MASK_MAP
39 #define PCL_FEATURES_MASK_MAP
40 
41 #include <vector>
42 #include <pcl/pcl_macros.h>
43 #include <cstring>
44 
45 namespace pcl
46 {
47  class PCL_EXPORTS MaskMap
48  {
49  public:
50  MaskMap ();
51  MaskMap (size_t width, size_t height);
52  virtual ~MaskMap ();
53 
54  void
55  resize (size_t width, size_t height);
56 
57  inline size_t
58  getWidth () const { return (width_); }
59 
60  inline size_t
61  getHeight () const { return (height_); }
62 
63  inline unsigned char*
64  getData () { return (&data_[0]); }
65 
66  inline const unsigned char*
67  getData () const { return (&data_[0]); }
68 
69  static void
70  getDifferenceMask (const MaskMap & mask0,
71  const MaskMap & mask1,
72  MaskMap & diff_mask);
73 
74  inline void
75  set (const size_t x, const size_t y)
76  {
77  data_[y*width_+x] = 255;
78  }
79 
80  inline void
81  unset (const size_t x, const size_t y)
82  {
83  data_[y*width_+x] = 0;
84  }
85 
86  inline bool
87  isSet (const size_t x, const size_t y) const
88  {
89  return (data_[y*width_+x] != 0);
90  }
91 
92  inline void
93  reset ()
94  {
95  memset (&data_[0], 0, width_*height_);
96  }
97 
98  inline unsigned char &
99  operator() (const size_t x, const size_t y)
100  {
101  return (data_[y*width_+x]);
102  }
103 
104  inline const unsigned char &
105  operator() (const size_t x, const size_t y) const
106  {
107  return (data_[y*width_+x]);
108  }
109 
110  void
111  erode (MaskMap & eroded_mask) const;
112 
113  private:
114  //unsigned char * data_;
115  std::vector<unsigned char> data_;
116  size_t width_;
117  size_t height_;
118  };
119 
120 }
121 
122 #endif