Point Cloud Library (PCL)  1.7.1
region_xy.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_REGION_XY_
39 #define PCL_FEATURES_REGION_XY_
40 
41 #include <fstream>
42 
43 namespace pcl
44 {
45  /** \brief Function for reading data from a stream. */
46  template <class Type>
47  void read (std::istream & stream, Type & value)
48  {
49  stream.read (reinterpret_cast<char*> (&value), sizeof(value));
50  }
51 
52  /** \brief Function for reading data arrays from a stream. */
53  template <class Type>
54  void read (std::istream & stream, Type * value, int nr_values)
55  {
56  for (int value_index = 0; value_index < nr_values; ++value_index)
57  {
58  read (stream, value[value_index]);
59  }
60  }
61 
62  /** \brief Function for writing data to a stream. */
63  template <class Type>
64  void write (std::ostream & stream, Type value)
65  {
66  stream.write (reinterpret_cast<char*> (&value), sizeof (value));
67  }
68 
69  /** \brief Function for writing data arrays to a stream. */
70  template <class Type>
71  void write (std::ostream & stream, Type * value, int nr_values)
72  {
73  for (int value_index = 0; value_index < nr_values; ++value_index)
74  {
75  write (stream, value[value_index]);
76  }
77  }
78 
79  /** \brief Defines a region in XY-space.
80  * \author Stefan Holzer
81  */
82  struct PCL_EXPORTS RegionXY
83  {
84  /** \brief Constructor. */
85  RegionXY () : x (0), y (0), width (0), height (0) {}
86 
87  /** \brief x-position of the region. */
88  int x;
89  /** \brief y-position of the region. */
90  int y;
91  /** \brief width of the region. */
92  int width;
93  /** \brief height of the region. */
94  int height;
95 
96  /** \brief Serializes the object to the specified stream.
97  * \param[out] stream the stream the object will be serialized to. */
98  void
99  serialize (std::ostream & stream) const
100  {
101  write (stream, x);
102  write (stream, y);
103  write (stream, width);
104  write (stream, height);
105  }
106 
107  /** \brief Deserializes the object from the specified stream.
108  * \param[in] stream the stream the object will be deserialized from. */
109  void
110  deserialize (::std::istream & stream)
111  {
112  read (stream, x);
113  read (stream, y);
114  read (stream, width);
115  read (stream, height);
116  }
117 
118  };
119 }
120 
121 #endif // PCL_FEATURES_REGION_XY_