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