Point Cloud Library (PCL)  1.14.1-dev
quantized_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 <vector>
41 #include <pcl/pcl_macros.h>
42 
43 namespace pcl
44 {
46  {
47  public:
48 
50  QuantizedMap (std::size_t width, std::size_t height);
51  QuantizedMap (const QuantizedMap & copy_me);
52 
53  virtual ~QuantizedMap ();
54 
55  inline std::size_t
56  getWidth () const { return (width_); }
57 
58  inline std::size_t
59  getHeight () const { return (height_); }
60 
61  inline unsigned char*
62  getData () { return (data_.data()); }
63 
64  inline const unsigned char*
65  getData () const { return (data_.data()); }
66 
67  inline QuantizedMap
68  getSubMap (std::size_t x,
69  std::size_t y,
70  std::size_t width,
71  std::size_t height)
72  {
73  QuantizedMap subMap(width, height);
74 
75  for (std::size_t row_index = 0; row_index < height; ++row_index)
76  {
77  for (std::size_t col_index = 0; col_index < width; ++col_index)
78  {
79  //const std::size_t index = (row_index+y)*width_ + (col_index+x);
80  //const unsigned char value = data_[index];
81  //subMap.data_[row_index*width + col_index] = value;//data_[(row_index+y)*width_ + (col_index+x)];
82  subMap (col_index, row_index) = (*this) (col_index + x, row_index + y);
83  }
84  }
85 
86  return subMap;
87  }
88 
89  void
90  resize (std::size_t width, std::size_t height);
91 
92  inline unsigned char &
93  operator() (const std::size_t x, const std::size_t y)
94  {
95  return (data_[y*width_+x]);
96  }
97 
98  inline const unsigned char &
99  operator() (const std::size_t x, const std::size_t y) const
100  {
101  return (data_[y*width_+x]);
102  }
103 
104  static void
105  spreadQuantizedMap (const QuantizedMap & input_map, QuantizedMap & output_map, std::size_t spreading_size);
106 
107  void
108  serialize (std::ostream & stream) const
109  {
110  const int width = static_cast<int> (width_);
111  const int height = static_cast<int> (height_);
112 
113  stream.write (reinterpret_cast<const char*> (&width), sizeof (width));
114  stream.write (reinterpret_cast<const char*> (&height), sizeof (height));
115 
116  const int num_of_elements = static_cast<int> (data_.size ());
117  stream.write (reinterpret_cast<const char*> (&num_of_elements), sizeof (num_of_elements));
118  for (int element_index = 0; element_index < num_of_elements; ++element_index)
119  {
120  stream.write (reinterpret_cast<const char*> (&(data_[element_index])), sizeof (data_[element_index]));
121  }
122  }
123 
124  void
125  deserialize (std::istream & stream)
126  {
127  int width;
128  int height;
129 
130  stream.read (reinterpret_cast<char*> (&width), sizeof (width));
131  stream.read (reinterpret_cast<char*> (&height), sizeof (height));
132 
133  width_ = static_cast<std::size_t> (width);
134  height_ = static_cast<std::size_t> (height);
135 
136  int num_of_elements;
137  stream.read (reinterpret_cast<char*> (&num_of_elements), sizeof (num_of_elements));
138  data_.resize (num_of_elements);
139  for (int element_index = 0; element_index < num_of_elements; ++element_index)
140  {
141  stream.read (reinterpret_cast<char*> (&(data_[element_index])), sizeof (data_[element_index]));
142  }
143  }
144 
145 
146  //private:
147  std::vector<unsigned char> data_;
148  std::size_t width_;
149  std::size_t height_;
150 
151  };
152 }
virtual ~QuantizedMap()
unsigned char * getData()
Definition: quantized_map.h:62
void resize(std::size_t width, std::size_t height)
std::size_t getHeight() const
Definition: quantized_map.h:59
void deserialize(std::istream &stream)
void serialize(std::ostream &stream) const
QuantizedMap(std::size_t width, std::size_t height)
QuantizedMap(const QuantizedMap &copy_me)
std::size_t getWidth() const
Definition: quantized_map.h:56
QuantizedMap getSubMap(std::size_t x, std::size_t y, std::size_t width, std::size_t height)
Definition: quantized_map.h:68
std::size_t width_
std::size_t height_
std::vector< unsigned char > data_
const unsigned char * getData() const
Definition: quantized_map.h:65
static void spreadQuantizedMap(const QuantizedMap &input_map, QuantizedMap &output_map, std::size_t spreading_size)
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:323