Point Cloud Library (PCL)  1.7.1
sparse_quantized_multi_mod_template.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_SPARSE_QUANTIZED_MULTI_MOD_TEMPLATE
39 #define PCL_FEATURES_SPARSE_QUANTIZED_MULTI_MOD_TEMPLATE
40 
41 #include <vector>
42 
43 #include <pcl/recognition/region_xy.h>
44 
45 namespace pcl
46 {
47 
48  /** \brief Feature that defines a position and quantized value in a specific modality.
49  * \author Stefan Holzer
50  */
52  {
53  /** \brief Constructor. */
55 
56  /** \brief x-position. */
57  int x;
58  /** \brief y-position. */
59  int y;
60  /** \brief the index of the corresponding modality. */
62  /** \brief the quantized value attached to the feature. */
63  unsigned char quantized_value;
64 
65  /** \brief Compares whether two features are the same.
66  * \param[in] base the feature to compare to.
67  */
68  bool
70  {
71  if (base.x != x)
72  return false;
73  if (base.y != y)
74  return false;
75  if (base.modality_index != modality_index)
76  return false;
77  if (base.quantized_value != quantized_value)
78  return false;
79 
80  return true;
81  }
82 
83  /** \brief Serializes the object to the specified stream.
84  * \param[out] stream the stream the object will be serialized to. */
85  void
86  serialize (std::ostream & stream) const
87  {
88  write (stream, x);
89  write (stream, y);
90  write (stream, modality_index);
91  write (stream, quantized_value);
92  }
93 
94  /** \brief Deserializes the object from the specified stream.
95  * \param[in] stream the stream the object will be deserialized from. */
96  void
97  deserialize (std::istream & stream)
98  {
99  read (stream, x);
100  read (stream, y);
101  read (stream, modality_index);
102  read (stream, quantized_value);
103  }
104  };
105 
106  /** \brief A multi-modality template constructed from a set of quantized multi-modality features.
107  * \author Stefan Holzer
108  */
110  {
111  /** \brief Constructor. */
113 
114  /** \brief The storage for the multi-modality features. */
115  std::vector<QuantizedMultiModFeature> features;
116 
117  /** \brief The region assigned to the template. */
119 
120  /** \brief Serializes the object to the specified stream.
121  * \param[out] stream the stream the object will be serialized to. */
122  void
123  serialize (std::ostream & stream) const
124  {
125  const int num_of_features = static_cast<int> (features.size ());
126  write (stream, num_of_features);
127  for (int feature_index = 0; feature_index < num_of_features; ++feature_index)
128  {
129  features[feature_index].serialize (stream);
130  }
131 
132  region.serialize (stream);
133  }
134 
135  /** \brief Deserializes the object from the specified stream.
136  * \param[in] stream the stream the object will be deserialized from. */
137  void
138  deserialize (std::istream & stream)
139  {
140  features.clear ();
141 
142  int num_of_features;
143  read (stream, num_of_features);
144  features.resize (num_of_features);
145  for (int feature_index = 0; feature_index < num_of_features; ++feature_index)
146  {
147  features[feature_index].deserialize (stream);
148  }
149 
150  region.deserialize (stream);
151  }
152  };
153 
154 }
155 
156 #endif