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