OKVIS ROS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterBlockSized.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 8, 2013
30  * Author: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
31  *********************************************************************************/
32 
39 #ifndef INCLUDE_OKVIS_CERES_PARAMETERBLOCKSIZED_HPP_
40 #define INCLUDE_OKVIS_CERES_PARAMETERBLOCKSIZED_HPP_
41 
42 #include <stdio.h>
43 #include <iostream>
44 #include <stdint.h>
46 #include <okvis/assert_macros.hpp>
47 #include <Eigen/Core>
48 
50 namespace okvis {
52 namespace ceres {
53 
58 template<int Dim, int MinDim, class T>
60  public:
61  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
62  OKVIS_DEFINE_EXCEPTION(Exception,std::runtime_error)
63 
64 
65  static const int Dimension = Dim;
66 
68  static const int MinimalDimension = MinDim;
69 
71  typedef T parameter_t;
72 
75  for (int i = 0; i < Dimension; ++i)
76  parameters_[i] = 0;
77  }
78 
81  }
82 
85 
88  virtual void setEstimate(const parameter_t& estimate)=0;
89 
92  virtual void setParameters(const double* parameters) {
93  OKVIS_ASSERT_TRUE_DBG(Exception, parameters != 0, "Null pointer");
94  memcpy(parameters_, parameters, Dimension * sizeof(double));
95  }
96 
98 
101 
104  virtual parameter_t estimate() const = 0;
105 
108  virtual double* parameters() {
109  return parameters_;
110  }
111 
114  virtual const double* parameters() const {
115  return parameters_;
116  }
117 
120  virtual size_t dimension() const {
121  return Dimension;
122  }
123 
126  virtual size_t minimalDimension() const {
127  return MinimalDimension;
128  }
129 
131 
135  virtual bool read(std::istream& /*not implemented: is*/) {
136  return false;
137  }
138 
140  virtual bool write(std::ostream& /*not implemented: os*/) const {
141  return false;
142  }
144 
145  protected:
148 };
149 
150 } // namespace ceres
151 } // namespace okvis
152 
153 #endif /* INCLUDE_OKVIS_CERES_PARAMETERBLOCKSIZED_HPP_ */
static const int MinimalDimension
Internal (minimal) dimension.
Definition: ParameterBlockSized.hpp:68
virtual size_t minimalDimension() const
Get the internal minimal parameter dimension.
Definition: ParameterBlockSized.hpp:126
virtual void setParameters(const double *parameters)
Set exact parameters of this parameter block.
Definition: ParameterBlockSized.hpp:92
virtual ~ParameterBlockSized()
Trivial destructor.
Definition: ParameterBlockSized.hpp:80
Eigen::Vector4d parameter_t
Make the parameter type accessible.
Definition: ParameterBlockSized.hpp:71
virtual const double * parameters() const
Get parameters – as a pointer.
Definition: ParameterBlockSized.hpp:114
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const int Dimension
Dimension of the parameter block.
Definition: ParameterBlockSized.hpp:65
virtual void setEstimate(const parameter_t &estimate)=0
Set estimate of this parameter block.
virtual bool read(std::istream &)
Definition: ParameterBlockSized.hpp:135
double parameters_[Dimension]
Parameters.
Definition: ParameterBlockSized.hpp:147
#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
Macro for defining an exception with a given parent.
Definition: assert_macros.hpp:52
virtual parameter_t estimate() const =0
Get estimate.
Base class providing the interface for parameter blocks.
Definition: ParameterBlockSized.hpp:59
This file contains some useful assert macros.
virtual bool write(std::ostream &) const
Writing to file – not implemented.
Definition: ParameterBlockSized.hpp:140
virtual size_t dimension() const
Get the parameter dimension.
Definition: ParameterBlockSized.hpp:120
Header file for the ParameterBlock class.
virtual double * parameters()
Get parameters – as a pointer.
Definition: ParameterBlockSized.hpp:108
#define OKVIS_ASSERT_TRUE_DBG(exceptionType, condition, message)
Definition: assert_macros.hpp:211
Base class providing the interface for parameter blocks.
Definition: ParameterBlock.hpp:53