4#include <NDEVR/Matrix.h>
5#include <Eigen/StdVector>
8#include "robust_kernel.h"
12 using namespace Eigen;
20 template <s
int04 t_dims,
typename E>
27 struct HessianHelper {
42 typedef Eigen::Map<MatrixX<g_type>, MatrixX<g_type>::Flags & Eigen::PacketAccessBit
44 : Eigen::Unaligned> HessianBlockType;
61 lib_assert(i <
_vertices.size(),
"index out of bounds");
72 int elemsUpToCol = ((j - 1) * j) / 2;
73 return elemsUpToCol + i;
82 Eigen::Vector3<g_type> rho;
98 lib_assert(jacobianWorkspace.maxNumVertices() > i,
"Bad vertex size");
99 lib_assert(jacobianWorkspace.maxDimension() >=
cast<uint04>(t_dims * v->
dimension()),
"Bad vertex dimension");
106 virtual void linearizeOplus()
108 const g_type delta = g_type(1e-9);
109 const g_type scalar = g_type(1.0) / (2 * delta);
123 lib_assert(vi_dim < 16,
"not enough memory");
124 std::fill(add_vi, add_vi + vi_dim, g_type(0.0));
128 for (
int d = 0; d < vi_dim; ++d) {
147 _error = errorBeforeNumeric;
176 lib_assert(
false,
"check this");
181 uint04 maxIdx = (n * (n - 1)) / 2;
215 MatrixX<g_type> AtO = A.transpose() * omega;
217 lib_assert(fromDim >= 0,
"Dimension");
218 Eigen::Map<MatrixX<g_type>> fromMap(from->hessianData(), fromDim, fromDim);
219 Eigen::Map<VectorX<g_type>> fromB(from->
bData(), fromDim);
222 fromMap.noalias() += AtO * A;
223 fromB.noalias() += A.transpose() * weightedError;
229 bool jstatus = !(to->
fixed());
237 hhelper.
matrix.noalias() += B.transpose() * AtO.transpose();
239 hhelper.
matrix.noalias() += AtO * B;
255 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
g_type chi2() const final override
Computes the chi-squared error: e^T * Omega * e.
BaseEdge()
Default constructor.
InformationType robustInformation(const Eigen::Vector3< g_type > &rho) const
calculate the robust information matrix by updating the information matrix of the error
static constexpr sint04 Dimension
Compile-time dimension of the error vector.
InformationType _information
The information (inverse covariance) matrix.
Eigen::Matrix< g_type, t_dims, t_dims > InformationType
Fixed-size information (inverse covariance) matrix type.
const ErrorVector & error() const
Returns a const reference to the error vector.
ErrorVector _error
The current error vector.
Eigen::Matrix< g_type, t_dims, 1 > ErrorVector
Fixed-size error vector type.
E Measurement
The measurement type stored by this edge.
bool allVerticesFixed() const final override
Returns true if all connected vertices are fixed.
BaseEdge< t_dims, E >::ErrorVector ErrorVector
The error vector type.
void mapHessianMemory(g_type *d, int i, int j, bool rowMajor) final override
maps the internal matrix to some external memory location, you need to provide the memory before call...
Buffer< HessianHelper > _hessian
Off-diagonal Hessian blocks (upper triangle).
virtual uint04 vertexCount() const final override
Returns the number of connected vertices.
void linearizeOplusAndConstructQuadraticForm(JacobianWorkspace &jacobianWorkspace) final override
Linearizes the constraint in the edge in the manifold space, and store the result in the given worksp...
MatrixX< g_type >::MapType JacobianType
Dynamic-size Jacobian map type.
Buffer< OptimizableGraph::OGVertex * > _vertices
The connected vertices.
static const int Dimension
Dimension of the error vector.
virtual const HyperGraph::HGVertex * vertex(uint04 i) const final override
Returns a const pointer to the i-th vertex.
virtual void setVertex(uint04 i, HyperGraph::HGVertex *v) final override
Sets the i-th vertex, with bounds and type checking.
void resize(uint04 size)
Resizes the edge to connect a given number of vertices.
Buffer< JacobianType > _jacobianOplus
jacobians of the edge (w.r.t. oplus)
static int computeUpperTriangleIndex(int i, int j)
Computes the linear index for the upper-triangular storage of off-diagonal Hessian blocks.
BaseEdge< t_dims, E >::InformationType InformationType
The information matrix type.
BaseMultiEdge()
Default constructor.
virtual HyperGraph::HGVertex * vertex(uint04 i) final override
Returns a mutable pointer to the i-th vertex.
void computeQuadraticForm(const InformationType &omega, const ErrorVector &weightedError)
Computes the quadratic form contributions for all vertex pairs.
void constructQuadraticForm()
Constructs the quadratic form (Hessian and gradient) from the linearized multi-edge.
BaseEdge< t_dims, E >::Measurement Measurement
The measurement type.
The equivelent of std::vector but with a bit more control.
abstract Vertex, your types must derive from that one
provide memory workspace for computing the Jacobians
virtual void computeError()=0
Computes the error of the edge and stores it internally.
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
A general case Vertex for optimization.
bool fixed() const
true => this node is fixed during the optimization
virtual sint04 dimension() const =0
dimension of the estimated state belonging to this node
virtual g_type * bData()=0
return a pointer to the b vector associated with this vertex
virtual void push()=0
backup the position of the vertex to a stack
void oplus(const g_type *v)
Update the position of the node from the parameters in v.
virtual void pop()=0
restore the position of the vertex by retrieving the position from the stack
virtual void robustify(g_type squaredError, Eigen::Vector3< g_type > &rho) const =0
compute the scaling factor for a error: The error is e^T Omega e The output rho is rho[0]: The actual...
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
helper for mapping the Hessian memory of the upper triangular block
Eigen::Map< MatrixX< g_type > > matrix
the mapped memory
bool transposed
the block has to be transposed