1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/************************************************************************
*
* Copyright (C) 2009-2024 IRCAD France
* Copyright (C) 2012-2020 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#pragma once
#include <sight/data/config.hpp>
#include "data/timeline/base.hpp"
#include "data/timeline/buffer.hpp"
#include <boost/array.hpp>
#include <boost/pool/pool.hpp>
#include <boost/pool/poolfwd.hpp>
namespace sight::data
{
/**
* @brief This class defines a timeline of buffers. It implements basic features of the Timeline interface such as
* pushing or retrieving objects. Allocation must be done by inherited classes.
*/
class SIGHT_DATA_CLASS_API buffer_tl : public timeline::base
{
public:
SIGHT_DECLARE_CLASS(buffer_tl, timeline::base);
using timestamp_t = core::clock::type;
using timeline_t = std::map<timestamp_t, std::shared_ptr<timeline::buffer> >;
using buffer_pair_t = std::pair<timestamp_t, std::shared_ptr<timeline::buffer> >;
using pool_t = boost::pool<>;
SIGHT_DATA_API buffer_tl();
SIGHT_DATA_API ~buffer_tl() override;
/// Check if the type of an object is compatible with this timeline
SIGHT_DATA_API virtual bool is_object_valid(const CSPTR(timeline::object)& _obj) const = 0;
/**
* @brief Return the closest object to the given timestamp
* @param _timestamp timestamp used to find the closest object
* @param _direction direction to find the closest object (PAST, FUTURE, BOTH)
*/
SIGHT_DATA_API CSPTR(timeline::object) get_closest_object(
core::clock::type _timestamp,
timeline::direction_t _direction = timeline::both
) const override;
/// Return the object matching the specified timestamp, returns NULL if object is not found
SIGHT_DATA_API CSPTR(timeline::object) get_object(core::clock::type _timestamp)
const override;
/// Clear the timeline
SIGHT_DATA_API virtual void clear_timeline();
/// Push a buffer to the timeline
SIGHT_DATA_API void push_object(const SPTR(timeline::object)& _obj) override;
/// Remove a buffer to the timeline
SIGHT_DATA_API SPTR(timeline::object) pop_object(timestamp_t _timestamp) override;
/// Change a buffer timestamp to the timeline
SIGHT_DATA_API void modify_time(timestamp_t _timestamp, timestamp_t _new_timestamp) override;
/// Change a buffer object to the specified timestamp
SIGHT_DATA_API void set_object(timestamp_t _timestamp, const SPTR(timeline::object)& _obj) override;
/// Return the last object in the timeline
SIGHT_DATA_API CSPTR(timeline::object) get_newer_object() const;
/// Return the last timestamp in the timeline
SIGHT_DATA_API core::clock::type get_newer_timestamp() const;
/// Change the maximum size of the timeline
void set_maximum_size(std::size_t _maximum_size)
{
m_maximum_size = _maximum_size;
}
/// Default Timeline Size
SIGHT_DATA_API static const std::size_t DEFAULT_TIMELINE_MAX_SIZE;
/// Return true if the pool is allocated
bool is_allocated() const
{
return m_pool != nullptr;
}
/// Equality comparison operators
/// @{
SIGHT_DATA_API bool operator==(const buffer_tl& _other) const noexcept;
SIGHT_DATA_API bool operator!=(const buffer_tl& _other) const noexcept;
/// @}
protected:
/// Allocate the pool buffer.
SIGHT_DATA_API void alloc_pool_size(std::size_t _size);
///Timeline
timeline_t m_timeline;
/// Pool of buffer
SPTR(pool_t) m_pool;
/// maximum size
std::size_t m_maximum_size;
}; // class buffer_tl
} // namespace sight::data
|