imagelist.cc
Go to the documentation of this file.
00001 /*
00002  * This file is part of the rc_genicam_api package.
00003  *
00004  * Copyright (c) 2017 Roboception GmbH
00005  * All rights reserved
00006  *
00007  * Author: Heiko Hirschmueller
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright notice,
00013  * this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  * this list of conditions and the following disclaimer in the documentation
00017  * and/or other materials provided with the distribution.
00018  *
00019  * 3. Neither the name of the copyright holder nor the names of its contributors
00020  * may be used to endorse or promote products derived from this software without
00021  * specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  * POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 #include "imagelist.h"
00037 
00038 #include <algorithm>
00039 
00040 namespace rcg
00041 {
00042 
00043 ImageList::ImageList(size_t _maxsize)
00044 {
00045   maxsize=std::max(static_cast<size_t>(1), _maxsize);
00046 }
00047 
00048 void ImageList::add(const std::shared_ptr<const Image> &image)
00049 {
00050   list.push_back(image);
00051 
00052   while (list.size() > maxsize)
00053   {
00054     list.erase(list.begin());
00055   }
00056 }
00057 
00058 void ImageList::add(const Buffer *buffer, uint32_t part)
00059 {
00060   list.push_back(std::shared_ptr<const Image>(new Image(buffer, part)));
00061 
00062   while (list.size() > maxsize)
00063   {
00064     list.erase(list.begin());
00065   }
00066 }
00067 
00068 void ImageList::removeOld(uint64_t timestamp)
00069 {
00070   size_t i=0;
00071 
00072   while (i < list.size())
00073   {
00074     if (list[i]->getTimestampNS() <= timestamp)
00075     {
00076       list.erase(list.begin()+static_cast<int>(i));
00077     }
00078     else
00079     {
00080       i++;
00081     }
00082   }
00083 }
00084 
00085 uint64_t ImageList::getOldestTime() const
00086 {
00087   uint64_t ret=0;
00088 
00089   if (list.size() > 0)
00090   {
00091     ret=list[0]->getTimestampNS();
00092   }
00093 
00094   return ret;
00095 }
00096 
00097 std::shared_ptr<const Image> ImageList::find(uint64_t timestamp) const
00098 {
00099   for (size_t i=0; i<list.size(); i++)
00100   {
00101     if (list[i]->getTimestampNS() == timestamp)
00102     {
00103       return list[i];
00104     }
00105   }
00106 
00107   return std::shared_ptr<const Image>();
00108 }
00109 
00110 std::shared_ptr<const Image> ImageList::find(uint64_t timestamp, uint64_t tolerance) const
00111 {
00112   if (tolerance > 0)
00113   {
00114     for (size_t i=0; i<list.size(); i++)
00115     {
00116       if (list[i]->getTimestampNS() >= timestamp-tolerance &&
00117           list[i]->getTimestampNS() <= timestamp+tolerance)
00118       {
00119         return list[i];
00120       }
00121     }
00122   }
00123   else
00124   {
00125     return find(timestamp);
00126   }
00127 
00128   return std::shared_ptr<const Image>();
00129 }
00130 
00131 }


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:47