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