27#ifndef G2O_AIS_OPTIMIZABLE_GRAPH_HH_
28#define G2O_AIS_OPTIMIZABLE_GRAPH_HH_
46class HyperGraphAction;
47struct OptimizationAlgorithmProperty;
80 return v1->
id() < v2->
id();
94 return operator()(
static_cast<const Edge*
>(e1),
95 static_cast<const Edge*
>(e2));
123 virtual const double&
hessian(
int i,
int j)
const = 0;
135 virtual int copyB(
double* b_)
const = 0;
138 virtual const double&
b(
int i)
const = 0;
139 virtual double&
b(
int i) = 0;
159 bool setEstimateData(
const double* estimate);
167 int dim = estimateDimension();
168 if ((dim == -1) || (estimate.size() != std::size_t(dim)))
return false;
169 return setEstimateData(&estimate[0]);
177 template <
typename Derived>
179 int dim = estimateDimension();
180 if ((dim == -1) || (estimate.size() != dim))
return false;
181 return setEstimateData(estimate.derived().data());
188 virtual bool getEstimateData(
double* estimate)
const;
195 int dim = estimateDimension();
196 if (dim < 0)
return false;
197 estimate.resize(dim);
198 return getEstimateData(&estimate[0]);
205 template <
typename Derived>
207 int dim = estimateDimension();
209 if (dim < 0)
return false;
213 if (estimate.size() != dim) {
214 if ((estimate.RowsAtCompileTime == Eigen::Dynamic) ||
215 (estimate.ColsAtCompileTime == Eigen::Dynamic))
216 estimate.derived().resize(dim);
220 return getEstimateData(estimate.derived().data());
227 virtual int estimateDimension()
const;
234 bool setMinimalEstimateData(
const double* estimate);
242 int dim = minimalEstimateDimension();
243 if ((dim == -1) || (estimate.size() != std::size_t(dim)))
return false;
244 return setMinimalEstimateData(&estimate[0]);
252 template <
typename Derived>
254 int dim = minimalEstimateDimension();
255 if ((dim == -1) || (estimate.size() != dim))
return false;
256 return setMinimalEstimateData(estimate.derived().data());
263 virtual bool getMinimalEstimateData(
double* estimate)
const;
270 int dim = minimalEstimateDimension();
271 if (dim < 0)
return false;
272 estimate.resize(dim);
273 return getMinimalEstimateData(&estimate[0]);
280 template <
typename Derived>
282 int dim = minimalEstimateDimension();
284 if (dim < 0)
return false;
288 if (estimate.size() != dim) {
289 if ((estimate.RowsAtCompileTime == Eigen::Dynamic) ||
290 (estimate.ColsAtCompileTime == Eigen::Dynamic))
291 estimate.derived().resize(dim);
295 return getMinimalEstimateData(estimate.derived().data());
302 virtual int minimalEstimateDimension()
const;
338 bool fixed()
const {
return _fixed; }
352 virtual void setId(
int id) { _id = id; }
374 virtual bool read(std::istream& is) = 0;
376 virtual bool write(std::ostream& os)
const = 0;
378 virtual void updateCache();
433 virtual bool setMeasurementData(
const double* m);
437 virtual bool getMeasurementData(
double* m)
const;
441 virtual int measurementDimension()
const;
447 virtual bool setMeasurementFromState();
467 virtual double chi2()
const = 0;
513 int level()
const {
return _level; }
525 virtual bool read(std::istream& is) = 0;
527 virtual bool write(std::ostream& os)
const = 0;
535 bool setParameterId(
int argNum,
int paramId);
537 return *_parameters.at(argNo);
541 _parameters.resize(newSize, 0);
542 _parameterIds.resize(newSize, -1);
543 _parameterTypes.resize(newSize,
typeid(
void*).name());
553 template <
typename ParameterType>
555 if (argNo >= _parameters.size())
return false;
556 _parameterIds[argNo] = paramId;
558 _parameterTypes[argNo] =
typeid(ParameterType).name();
562 template <
typename CacheType>
564 const std::string& _type,
567 bool resolveParameters();
568 virtual bool resolveCaches();
577 return reinterpret_cast<Vertex*
>(HyperGraph::vertex(
id));
582 return reinterpret_cast<const Vertex*
>(HyperGraph::vertex(
id));
622 int maxDimension()
const;
627 _jacobianWorkspace.updateSize(*
this,
true);
634 std::set<int> dimensions()
const;
640 virtual int optimize(
int iterations,
bool online =
false);
644 virtual void preIteration(
int);
647 virtual void postIteration(
int);
665 virtual void discardTop();
669 virtual bool load(std::istream& is);
670 bool load(
const char* filename);
672 virtual bool save(std::ostream& os,
int level = 0)
const;
674 bool save(
const char* filename,
int level = 0)
const;
699 void setRenamedTypesFromString(
const std::string& types);
708 const std::set<int>& vertDims = std::set<int>())
const;
713 virtual void clearParameters();
725 bool verifyInformationMatrices(
bool verbose =
false)
const;
728 bool saveVertex(std::ostream& os, Vertex* v)
const;
731 bool saveParameter(std::ostream& os,
Parameter* v)
const;
734 bool saveEdge(std::ostream& os, Edge* e)
const;
742 return _jacobianWorkspace;
751 static bool initMultiThreading();
Abstract action that operates on an entire graph.
Container class that implements an interface for adding/removing Data elements in a linked list.
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
abstract Vertex, your types must derive from that one
int id() const
returns the id
std::set< Edge * > EdgeSet
std::set< Vertex * > VertexSet
provide memory workspace for computing the Jacobians
std::vector< std::string > _parameterTypes
int dimension() const
returns the dimensions of the error function
virtual void linearizeOplus(JacobianWorkspace &jacobianWorkspace)=0
const Parameter * parameter(int argNo) const
virtual double chi2() const =0
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
virtual void computeError()=0
bool installParameter(ParameterType *&p, size_t argNo, int paramId=-1)
int level() const
returns the level of the edge
G2O_ATTRIBUTE_DEPRECATED(virtual Vertex *createFrom())
virtual bool read(std::istream &is)=0
read the vertex from a stream, i.e., the internal state of the vertex
std::vector< int > _parameterIds
virtual void mapHessianMemory(double *d, int i, int j, bool rowMajor)=0
long long internalId() const
the internal ID of the edge
G2O_ATTRIBUTE_DEPRECATED(virtual Vertex *createTo())
virtual bool allVerticesFixed() const =0
std::vector< Parameter ** > _parameters
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
virtual double * informationData()=0
std::vector< int > _cacheIds
virtual void constructQuadraticForm()=0
RobustKernel * _robustKernel
virtual bool write(std::ostream &os) const =0
write the vertex to a stream
virtual const double * errorData() const =0
returns the error vector cached after calling the computeError;
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)=0
void setLevel(int l)
sets the level of the edge
virtual double * errorData()=0
void resizeParameters(size_t newSize)
virtual const double * informationData() const =0
virtual Vertex * createVertex(int)
size_t numParameters() const
A general case Vertex for optimization.
virtual bool setMinimalEstimateDataImpl(const double *)
virtual const double & hessian(int i, int j) const =0
get the element from the hessian matrix
virtual int stackSize() const =0
return the stack size
virtual void mapHessianMemory(double *d)=0
bool setEstimateData(const std::vector< double > &estimate)
virtual double & hessian(int i, int j)=0
bool marginalized() const
true => this node is marginalized out during the optimization
virtual bool read(std::istream &is)=0
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool setEstimateDataImpl(const double *)
void setHessianIndex(int ti)
set the temporary index of the vertex in the parameter blocks
virtual void oplusImpl(const double *v)=0
virtual bool write(std::ostream &os) const =0
write the vertex to a stream
int colInHessian() const
get the row of this vertex in the Hessian
void unlockQuadraticForm()
virtual double solveDirect(double lambda=0)=0
virtual double & b(int i)=0
OptimizableGraph * _graph
CacheContainer * _cacheContainer
bool getEstimateData(Eigen::MatrixBase< Derived > &estimate) const
virtual void clearQuadraticForm()=0
virtual const double & b(int i) const =0
get the b vector element
int dimension() const
dimension of the estimated state belonging to this node
bool setMinimalEstimateData(const Eigen::MatrixBase< Derived > &estimate)
int G2O_ATTRIBUTE_DEPRECATED(tempIndex() const)
virtual void discardTop()=0
bool fixed() const
true => this node is fixed during the optimization
virtual void push()=0
backup the position of the vertex to a stack
void setColInHessian(int c)
set the row of this vertex in the Hessian
void setToOrigin()
sets the node to the origin (used in the multilevel stuff)
OpenMPMutex _quadraticFormMutex
OptimizableGraph * graph()
virtual void setToOriginImpl()=0
sets the node to the origin (used in the multilevel stuff)
void G2O_ATTRIBUTE_DEPRECATED(setTempIndex(int ti))
bool setMinimalEstimateData(const std::vector< double > &estimate)
virtual void setId(int id)
virtual bool getEstimateData(std::vector< double > &estimate) const
virtual double hessianDeterminant() const =0
const OptimizableGraph * graph() const
bool getMinimalEstimateData(Eigen::MatrixBase< Derived > &estimate) const
virtual double * hessianData()=0
virtual double * bData()=0
return a pointer to the b vector associated with this vertex
void oplus(const double *v)
virtual int copyB(double *b_) const =0
bool setEstimateData(const Eigen::MatrixBase< Derived > &estimate)
virtual bool getMinimalEstimateData(std::vector< double > &estimate) const
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
base for all robust cost functions
std::vector< Parameter * > ParameterVector
order edges based on the internal ID, which is assigned to the edge in addEdge()
bool operator()(const HyperGraph::Edge *e1, const HyperGraph::Edge *e2) const
bool operator()(const Edge *e1, const Edge *e2) const
order vertices based on their ID
bool operator()(const Vertex *v1, const Vertex *v2) const
JacobianWorkspace & jacobianWorkspace()
the workspace for storing the Jacobians of the graph
JacobianWorkspace _jacobianWorkspace
ParameterContainer & parameters()
bool saveSubset(std::ostream &os, HyperGraph::EdgeSet &eset)
save a subgraph to a stream. Again uses the Factory system.
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
ParameterContainer _parameters
const JacobianWorkspace & jacobianWorkspace() const
std::vector< OptimizableGraph::Vertex * > VertexContainer
vector container for vertices
bool addVertex(OptimizableGraph::Vertex *v)
std::vector< HyperGraphActionSet > _graphActions
std::map< std::string, std::string > _renamedTypesLookup
void recomputeJacobianWorkspaceSize()
Parameter * parameter(int id)
std::set< HyperGraphAction * > HyperGraphActionSet
const Vertex * vertex(int id) const
returns the vertex number id appropriately casted
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
virtual bool addVertex(HyperGraph::Vertex *v)
const ParameterContainer & parameters() const
bool addParameter(Parameter *p)
bool saveSubset(std::ostream &os, HyperGraph::VertexSet &vset, int level=0)
save a subgraph to a stream. Again uses the Factory system.
virtual bool load(std::istream &is)
Vertex * vertex(int id)
returns the vertex number id appropriately casted
describe the properties of a solver