camerainfolist.cc
Go to the documentation of this file.
1 /*
2  * This file is part of the rc_genicam_camera package.
3  *
4  * Copyright (c) 2019 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Heiko Hirschmueller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "camerainfolist.h"
37 
38 #include <algorithm>
39 
40 namespace rcgccam
41 {
43 {
44  maxsize_ = 25;
45 }
46 
47 void CameraInfoList::setSize(size_t maxsize)
48 {
49  maxsize_ = std::max(static_cast<size_t>(1), maxsize);
50 }
51 
52 void CameraInfoList::setTolerance(uint64_t tolerance)
53 {
54  tolerance_ = tolerance;
55 }
56 
57 sensor_msgs::CameraInfoPtr CameraInfoList::add(const sensor_msgs::CameraInfoPtr& image)
58 {
59  list_.push_back(image);
60 
61  sensor_msgs::CameraInfoPtr ret;
62 
63  if (list_.size() > maxsize_)
64  {
65  ret = list_[0];
66  list_.erase(list_.begin());
67  }
68 
69  return ret;
70 }
71 
72 int CameraInfoList::removeOld(const ros::Time& timestamp)
73 {
74  size_t i = 0;
75  int n = 0;
76 
77  while (i < list_.size())
78  {
79  if (list_[i]->header.stamp <= timestamp)
80  {
81  list_.erase(list_.begin() + static_cast<int>(i));
82  n++;
83  }
84  else
85  {
86  i++;
87  }
88  }
89 
90  return n;
91 }
92 
93 sensor_msgs::CameraInfoPtr CameraInfoList::find(const ros::Time& timestamp) const
94 {
95  for (size_t i = 0; i < list_.size(); i++)
96  {
97  uint64_t ts = timestamp.toNSec();
98  uint64_t info_ts = list_[i]->header.stamp.toNSec();
99 
100  if (info_ts >= ts - tolerance_ && info_ts <= ts + tolerance_)
101  {
102  return list_[i];
103  }
104  }
105 
106  return sensor_msgs::CameraInfoPtr();
107 }
108 
109 } // namespace rcgccam
rcgccam::CameraInfoList::setSize
void setSize(size_t maxsize)
Set maximum size of the list.
Definition: camerainfolist.cc:47
rcgccam::CameraInfoList::list_
std::vector< sensor_msgs::CameraInfoPtr > list_
Definition: camerainfolist.h:100
rcgccam::CameraInfoList::removeOld
int removeOld(const ros::Time &timestamp)
Remove all camera infos that have a timestamp that is older or equal than the given timestamp.
Definition: camerainfolist.cc:72
rcgccam
Definition: camerainfolist.cc:40
rcgccam::CameraInfoList::setTolerance
void setTolerance(uint64_t tolerance)
Set tolerance for finding corresponding timestamps.
Definition: camerainfolist.cc:52
rcgccam::CameraInfoList::find
sensor_msgs::CameraInfoPtr find(const ros::Time &timestamp) const
Returns the oldest camera info that has a timestamp within the tolerance of the given timestamp.
Definition: camerainfolist.cc:93
rcgccam::CameraInfoList::tolerance_
uint64_t tolerance_
Definition: camerainfolist.h:99
ros::Time
rcgccam::CameraInfoList::add
sensor_msgs::CameraInfoPtr add(const sensor_msgs::CameraInfoPtr &info)
Adds the given camera info to the internal list.
Definition: camerainfolist.cc:57
TimeBase< Time, Duration >::toNSec
uint64_t toNSec() const
header
const std::string header
rcgccam::CameraInfoList::maxsize_
size_t maxsize_
Definition: camerainfolist.h:98
camerainfolist.h
rcgccam::CameraInfoList::CameraInfoList
CameraInfoList()
Create a camera info list.
Definition: camerainfolist.cc:42


rc_genicam_camera
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 2 2022 00:49:18