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