OKVIS ROS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FrameSynchronizer.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: Sep 14, 2014
30  * Author: Pascal Gohl
31  * Modified: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
32  * Modified: Andreas Forster (an.forster@gmail.com)
33  *********************************************************************************/
34 
43 #ifndef INCLUDE_OKVIS_FRAMESYNCHRONIZER_HPP_
44 #define INCLUDE_OKVIS_FRAMESYNCHRONIZER_HPP_
45 
46 #include <memory>
47 #include <okvis/Measurements.hpp>
48 #include <okvis/MultiFrame.hpp>
49 #include <okvis/VioInterface.hpp>
50 #include <okvis/Parameters.hpp>
51 #include <okvis/assert_macros.hpp>
52 
54 namespace okvis {
55 
61  public:
62  OKVIS_DEFINE_EXCEPTION(Exception, std::runtime_error)
63 
64 
69 
71  virtual ~FrameSynchronizer();
72 
77  void init(okvis::VioParameters& parameters);
78 
84  std::shared_ptr<okvis::MultiFrame> addNewFrame(
85  std::shared_ptr<okvis::CameraMeasurement> &frame);
86 
96  bool detectionEndedForMultiFrame(uint64_t multiFrameId);
97 
108  bool detectionCompletedForAllCameras(uint64_t multiFrameId);
109 
110  private:
111 
120  bool findFrameByTime(const okvis::Time& timestamp, int& position) const;
121 
123 
130  bool findFrameById(uint64_t mfId, int& position) const;
131 
135  size_t numCameras_;
137  double timeTol_;
139  std::vector<std::pair<std::shared_ptr<okvis::MultiFrame>, size_t> > frameBuffer_;
142 
147 
148 };
149 
150 } /* namespace okvis */
151 
152 #endif /* INCLUDE_OKVIS_FRAMESYNCHRONIZER_HPP_ */
bool detectionEndedForMultiFrame(uint64_t multiFrameId)
Inform the synchronizer that a frame in the multiframe has completed keypoint detection and descripti...
Definition: FrameSynchronizer.cpp:113
double timeTol_
Timestamp tolerance to classify multiple frames as being part of the same multiframe.
Definition: FrameSynchronizer.hpp:137
Header file for the MultiFrame class.
okvis::Time lastCompletedFrameTimestamp_
Timestamp of the last multiframe that returned true in detectionCompletedForAllCameras().
Definition: FrameSynchronizer.hpp:144
size_t numCameras_
Number of cameras for easy access.
Definition: FrameSynchronizer.hpp:135
This file contains the templated measurement structs, structs encapsulating Sensor data and related t...
std::shared_ptr< okvis::MultiFrame > addNewFrame(std::shared_ptr< okvis::CameraMeasurement > &frame)
Adds a new frame to the internal buffer and returns the Multiframe containing the frame...
Definition: FrameSynchronizer.cpp:81
uint64_t lastCompletedFrameId_
ID of the last multiframe that returned true in detectionCompletedForAllCameras().
Definition: FrameSynchronizer.hpp:146
bool findFrameByTime(const okvis::Time &timestamp, int &position) const
Find a multiframe in the buffer that has a timestamp within the tolerances of the given one...
Definition: FrameSynchronizer.cpp:149
virtual ~FrameSynchronizer()
Trivial destructor.
Definition: FrameSynchronizer.cpp:69
#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
Macro for defining an exception with a given parent.
Definition: assert_macros.hpp:52
This file contains some useful assert macros.
Struct to combine all parameters and settings.
Definition: Parameters.hpp:280
FrameSynchronizer(okvis::VioParameters &parameters)
Constructor. Calls init().
Definition: FrameSynchronizer.cpp:54
bool detectionCompletedForAllCameras(uint64_t multiFrameId)
This will return true if the internal counter on how many times detectionEndedForMultiFrame() has bee...
Definition: FrameSynchronizer.cpp:126
Header file for the VioInterface class.
void init(okvis::VioParameters &parameters)
Initialise the synchronizer with new parameters. Is called in the constructor.
Definition: FrameSynchronizer.cpp:73
This class combines multiple frames with the same or similar timestamp into one multiframe.
Definition: FrameSynchronizer.hpp:60
int bufferPosition_
Position of the newest multiframe in the buffer.
Definition: FrameSynchronizer.hpp:141
Time representation. May either represent wall clock time or ROS clock time.
Definition: Time.hpp:187
This file contains struct definitions that encapsulate parameters and settings.
okvis::VioParameters parameters_
Copy of the parameters and settings.
Definition: FrameSynchronizer.hpp:133
bool findFrameById(uint64_t mfId, int &position) const
returns true if a frame with multiframe id mfId is found and sets position to its frame buffer positi...
Definition: FrameSynchronizer.cpp:164
std::vector< std::pair< std::shared_ptr< okvis::MultiFrame >, size_t > > frameBuffer_
Circular buffer containing a multiframe pointer and a counter for how many times detection has comple...
Definition: FrameSynchronizer.hpp:139