Point Cloud Library (PCL)  1.14.0-dev
multi_channel_2d_data_set.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/common/common.h>
41 
42 #include <istream>
43 #include <ostream>
44 
45 namespace pcl {
46 
47 /** Holds two-dimensional multi-channel data. */
48 template <class DATA_TYPE, std::size_t NUM_OF_CHANNELS>
50 public:
51  /** Constructor. */
52  inline MultiChannel2DData() : data_(NULL), width_(0), height_(0) {}
53 
54  /** Resizes the internal data storage.
55  *
56  * \param[in] width the width of the resized 2D data array
57  * \param[in] height the height of the resized 2D data array
58  */
59  inline void
60  resize(std::size_t width, std::size_t height)
61  {
62  data_.resize(NUM_OF_CHANNELS * width * height);
63  width_ = width;
64  height_ = height;
65  }
66 
67  /** Clears the internal data storage and sets width and height to 0. */
68  void
70  {
71  width_ = 0;
72  height_ = 0;
73  data_.clear();
74  }
75 
76  /** Returns a pointer to the internal data at the specified location.
77  *
78  * \param[in] col_index the column index
79  * \param[in] row_index the row index
80  */
81  inline DATA_TYPE*
82  operator()(const std::size_t col_index, const std::size_t row_index)
83  {
84  return &(data_[NUM_OF_CHANNELS * (row_index * width_ + col_index)]);
85  };
86 
87  /** Returns a pointer to the internal data at the specified location.
88  *
89  * \param[in] col_index the column index
90  * \param[in] row_index the row index
91  */
92  inline const DATA_TYPE*
93  operator()(const std::size_t col_index, const std::size_t row_index) const
94  {
95  return &(data_[NUM_OF_CHANNELS * (row_index * width_ + col_index)]);
96  };
97 
98  /** Returns a reference to the internal data at the specified location.
99  *
100  * \param[in] col_index the column index
101  * \param[in] row_index the row index
102  * \param[in] channel the channel index
103  */
104  inline DATA_TYPE&
105  operator()(const std::size_t col_index,
106  const std::size_t row_index,
107  const std::size_t channel)
108  {
109  return data_[NUM_OF_CHANNELS * (row_index * width_ + col_index) + channel];
110  };
111 
112  /** Returns a reference to the internal data at the specified location.
113  *
114  * \param[in] col_index the column index
115  * \param[in] row_index the row index
116  * \param[in] channel the channel index
117  */
118  inline const DATA_TYPE&
119  operator()(const std::size_t col_index,
120  const std::size_t row_index,
121  const std::size_t channel) const
122  {
123  return data_[NUM_OF_CHANNELS * (row_index * width_ + col_index) + channel];
124  };
125 
126 private:
127  /** The internal data storage. */
128  std::vector<DATA_TYPE> data_;
129  /** The width of the data storage. */
130  std::size_t width_;
131  /** The height of the data storage. */
132  std::size_t height_;
133 };
134 
135 /** Holds a set of two-dimensional multi-channel data. */
136 template <class DATA_TYPE, std::size_t NUM_OF_CHANNELS>
138 public:
139  /** Constructor. */
140  inline MultiChannel2DDataSet() : data_set_() {}
141 
142  /** Adds a new two-dimensional data block to the data set.
143  *
144  * \param[in] width the width of the new data block
145  * \param[in] height the height of the new data block
146  */
147  void
148  addData(const std::size_t width, const std::size_t height)
149  {
152  data->resize(width, height);
153 
154  data_set_.push_back(data);
155  };
156 
157  /** Releases the data stored in the data set. */
158  void
160  {
161  for (std::size_t data_set_index = 0; data_set_index < data_set_.size();
162  ++data_set_index) {
163  delete data_set_[data_set_index];
164  }
165  }
166 
167  /** Releases the data stored in the data set. */
168  void
170  {
171  releaseDataSet();
172  }
173 
174  /** Returns a pointer to the specified data block at the specified location.
175  *
176  * \param[in] data_set_id the index of the data block
177  * \param[in] col the column of the desired location
178  * \param[in] row the row of the desired location
179  */
180  inline DATA_TYPE*
181  operator()(const std::size_t data_set_id,
182  const std::size_t col,
183  const std::size_t row)
184  {
185  return (*data_set_[data_set_id])(col, row);
186  };
187 
188  /** Returns a pointer to the specified data block at the specified location.
189  *
190  * \param[in] data_set_id the index of the data block
191  * \param[in] col the column of the desired location
192  * \param[in] row the row of the desired location
193  */
194  inline const DATA_TYPE*
195  operator()(const std::size_t data_set_id,
196  const std::size_t col,
197  const std::size_t row) const
198  {
199  return (*data_set_[data_set_id])(col, row);
200  };
201 
202  /** Returns a reference to the specified data block at the specified location.
203  *
204  * \param[in] data_set_id the index of the data block
205  * \param[in] col the column of the desired location
206  * \param[in] row the row of the desired location
207  * \param[in] channel the channel index
208  */
209  inline DATA_TYPE&
210  operator()(const std::size_t data_set_id,
211  const std::size_t col,
212  const std::size_t row,
213  const std::size_t channel)
214  {
215  return (*data_set_[data_set_id])(col, row, channel);
216  };
217 
218  /** Returns a reference to the specified data block at the specified location.
219  *
220  * \param[in] data_set_id the index of the data block
221  * \param[in] col the column of the desired location
222  * \param[in] row the row of the desired location
223  * \param[in] channel the channel index
224  */
225  inline const DATA_TYPE&
226  operator()(const std::size_t data_set_id,
227  const std::size_t col,
228  const std::size_t row,
229  const std::size_t channel) const
230  {
231  return (*data_set_[data_set_id])(col, row, channel);
232  };
233 
234 private:
235  /** The data set. */
236  std::vector<MultiChannel2DData<DATA_TYPE, NUM_OF_CHANNELS>*> data_set_;
237 };
238 
243 
244 } // namespace pcl
Holds two-dimensional multi-channel data.
void resize(std::size_t width, std::size_t height)
Resizes the internal data storage.
void clear()
Clears the internal data storage and sets width and height to 0.
DATA_TYPE & operator()(const std::size_t col_index, const std::size_t row_index, const std::size_t channel)
Returns a reference to the internal data at the specified location.
DATA_TYPE * operator()(const std::size_t col_index, const std::size_t row_index)
Returns a pointer to the internal data at the specified location.
const DATA_TYPE * operator()(const std::size_t col_index, const std::size_t row_index) const
Returns a pointer to the internal data at the specified location.
const DATA_TYPE & operator()(const std::size_t col_index, const std::size_t row_index, const std::size_t channel) const
Returns a reference to the internal data at the specified location.
Holds a set of two-dimensional multi-channel data.
void clear()
Releases the data stored in the data set.
void releaseDataSet()
Releases the data stored in the data set.
const DATA_TYPE * operator()(const std::size_t data_set_id, const std::size_t col, const std::size_t row) const
Returns a pointer to the specified data block at the specified location.
DATA_TYPE * operator()(const std::size_t data_set_id, const std::size_t col, const std::size_t row)
Returns a pointer to the specified data block at the specified location.
void addData(const std::size_t width, const std::size_t height)
Adds a new two-dimensional data block to the data set.
const DATA_TYPE & operator()(const std::size_t data_set_id, const std::size_t col, const std::size_t row, const std::size_t channel) const
Returns a reference to the specified data block at the specified location.
DATA_TYPE & operator()(const std::size_t data_set_id, const std::size_t col, const std::size_t row, const std::size_t channel)
Returns a reference to the specified data block at the specified location.
Define standard C methods and C++ classes that are common to all methods.
#define PCL_EXPORTS
Definition: pcl_macros.h:323