27 #ifndef G2O_AIS_OPTIMIZABLE_GRAPH_HH_ 28 #define G2O_AIS_OPTIMIZABLE_GRAPH_HH_ 43 #include "../stuff/macros.h" 47 class HyperGraphAction;
48 struct OptimizationAlgorithmProperty;
88 virtual bool read(std::istream& is) = 0;
90 virtual bool write(std::ostream& os)
const = 0;
105 return v1->
id() < v2->
id();
113 bool operator() (
const Edge* e1,
const Edge* e2)
const 134 virtual Vertex* clone()
const ;
154 virtual const double& hessian(
int i,
int j)
const = 0;
155 virtual double& hessian(
int i,
int j) = 0;
156 virtual double hessianDeterminant()
const = 0;
157 virtual double* hessianData() = 0;
160 virtual void mapHessianMemory(
double*
d) = 0;
166 virtual int copyB(
double* b_)
const = 0;
169 virtual const double& b(
int i)
const = 0;
170 virtual double& b(
int i) = 0;
172 virtual double* bData() = 0;
177 virtual void clearQuadraticForm() = 0;
183 virtual double solveDirect(
double lambda=0) = 0;
190 bool setEstimateData(
const double* estimate);
199 int dim = estimateDimension();
200 assert((dim == -1) || (estimate.size() == std::size_t(dim)));
202 return setEstimateData(&estimate[0]);
209 virtual bool getEstimateData(
double* estimate)
const;
216 int dim = estimateDimension();
219 estimate.resize(dim);
220 return getEstimateData(&estimate[0]);
227 virtual int estimateDimension()
const;
234 bool setMinimalEstimateData(
const double* estimate);
243 int dim = minimalEstimateDimension();
244 assert((dim == -1) || (estimate.size() == std::size_t(dim)));
246 return setMinimalEstimateData(&estimate[0]);
253 virtual bool getMinimalEstimateData(
double* estimate)
const ;
260 int dim = minimalEstimateDimension();
263 estimate.resize(dim);
264 return getMinimalEstimateData(&estimate[0]);
271 virtual int minimalEstimateDimension()
const;
274 virtual void push() = 0;
277 virtual void pop() = 0;
283 virtual int stackSize()
const = 0;
318 virtual void setId(
int id) {_id = id;}
340 virtual bool read(std::istream& is) = 0;
342 virtual bool write(std::ostream& os)
const = 0;
344 virtual void updateCache();
363 virtual void oplusImpl(
const double* v) = 0;
366 virtual void setToOriginImpl() = 0;
388 virtual Edge* clone()
const;
391 virtual bool allVerticesFixed()
const = 0;
394 virtual void computeError() = 0;
398 virtual bool setMeasurementData(
const double* m);
402 virtual bool getMeasurementData(
double* m)
const;
406 virtual int measurementDimension()
const;
412 virtual bool setMeasurementFromState();
422 virtual const double* errorData()
const = 0;
423 virtual double* errorData() = 0;
426 virtual const double* informationData()
const = 0;
427 virtual double* informationData() = 0;
430 virtual double chi2()
const = 0;
438 virtual void constructQuadraticForm() = 0;
448 virtual void mapHessianMemory(
double* d,
int i,
int j,
bool rowMajor) = 0;
478 virtual bool read(std::istream& is) = 0;
480 virtual bool write(std::ostream& os)
const = 0;
488 bool setParameterId(
int argNum,
int paramId);
493 _parameterIds.resize(newSize, -1);
494 _parameterTypes.resize(newSize,
typeid(
void*).name());
504 template <
typename ParameterType>
508 _parameterIds[argNo] = paramId;
510 _parameterTypes[argNo] =
typeid(ParameterType).name();
514 template <
typename CacheType>
516 const std::string& _type,
519 bool resolveParameters();
520 virtual bool resolveCaches();
569 virtual int optimize(
int iterations,
bool online=
false);
594 virtual bool load(std::istream& is,
bool createEdges=
true);
597 virtual bool save(std::ostream& os,
int level = 0)
const;
599 bool save(
const char* filename,
int level = 0)
const;
virtual HyperGraph::HyperGraphElementType elementType() const
bool installParameter(ParameterType *&p, size_t argNo, int paramId=-1)
virtual Vertex * createFrom()
int id() const
returns the id
std::vector< OptimizableGraph::Vertex * > VertexContainer
vector container for vertices
void setColInHessian(int c)
set the row of this vertex in the Hessian
void setHessianIndex(int ti)
set the temporary index of the vertex in the parameter blocks
const OptimizableGraph * graph() const
virtual int optimize(int iterations, bool online=false)
const Data * next() const
std::vector< std::string > _parameterTypes
int dimension() const
returns the dimensions of the error function
describe the properties of a solver
void G2O_ATTRIBUTE_DEPRECATED(setTempIndex(int ti))
long long internalId() const
the internal ID of the edge
void addUserData(Data *obs)
int G2O_ATTRIBUTE_DEPRECATED(tempIndex() const)
CacheContainer * _cacheContainer
bool removePreIterationAction(HyperGraphAction *action)
remove an action that should no longer be execured before each iteration
OptimizableGraph * graph()
bool saveEdge(std::ostream &os, Edge *e) const
void setNext(Data *next_)
virtual void clearParameters()
Parameter * getParameter(int id)
return a parameter based on its ID
virtual bool getMinimalEstimateData(std::vector< double > &estimate) const
std::set< Vertex * > VertexSet
HyperGraphElementType
enum of all the types we have in our graphs
bool removePostIterationAction(HyperGraphAction *action)
remove an action that should no longer be execured after each iteration
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
virtual void pop()
pop (restore) the estimate of all variables from the stack
virtual void push()
push the estimate of all variables onto a stack
const Data * userData() const
the user data associated with this vertex
virtual bool read(std::istream &is)=0
read the data from a stream
int level() const
returns the level of the edge
int hessianIndex() const
temporary index of this node in the parameter vector obtained from linearization
bool addPostIterationAction(HyperGraphAction *action)
add an action to be executed after each iteration
int maxDimension() const
return the maximum dimension of all vertices in the graph
Vertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
static bool initMultiThreading()
virtual bool setMinimalEstimateDataImpl(const double *)
virtual void postIteration(int)
called at the end of an iteration (argument is the number of the iteration)
bool setMinimalEstimateData(const std::vector< double > &estimate)
base for all robust cost functions
Vertex * vertex(int id)
returns the vertex number id appropriately casted
const JacobianWorkspace & jacobianWorkspace() const
JacobianWorkspace & jacobianWorkspace()
the workspace for storing the Jacobians of the graph
std::vector< Parameter ** > _parameters
virtual Vertex * createTo()
virtual void setId(int id)
sets the id of the node in the graph be sure that the graph keeps consistent after changing the id ...
virtual bool setEstimateDataImpl(const double *)
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
void oplus(const double *v)
std::set< Edge * > EdgeSet
int dimension() const
dimension of the estimated state belonging to this node
virtual ~OptimizableGraph()
double chi2() const
returns the chi2 of the current configuration
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
bool isSolverSuitable(const OptimizationAlgorithmProperty &solverProperty, const std::set< int > &vertDims=std::set< int >()) const
int colInHessian() const
get the row of this vertex in the Hessian
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
bool saveSubset(std::ostream &os, HyperGraph::VertexSet &vset, int level=0)
save a subgraph to a stream. Again uses the Factory system.
size_t numParameters() const
std::vector< int > _parameterIds
RobustKernel * _robustKernel
std::vector< Parameter * > ParameterVector
order vertices based on their ID
std::map< std::string, std::string > _renamedTypesLookup
bool addParameter(Parameter *p)
const Parameter * parameter(int argNo) const
bool marginalized() const
true => this node is marginalized out during the optimization
void setUserData(Data *obs)
order edges based on the internal ID, which is assigned to the edge in addEdge()
A general case Vertex for optimization.
virtual bool addVertex(HyperGraph::Vertex *v)
std::vector< int > _cacheIds
abstract Vertex, your types must derive from that one
void setToOrigin()
sets the node to the origin (used in the multilevel stuff)
void setRenamedTypesFromString(const std::string &types)
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
void addGraph(OptimizableGraph *g)
adds all edges and vertices of the graph g to this graph.
void resizeParameters(size_t newSize)
virtual bool load(std::istream &is, bool createEdges=true)
load the graph from a stream. Uses the Factory singleton for creating the vertices and edges...
Parameter * parameter(int id)
JacobianWorkspace _jacobianWorkspace
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
virtual void setFixed(HyperGraph::VertexSet &vset, bool fixed)
fixes/releases a set of vertices
bool addParameter(Parameter *p)
add parameter to the container
bool saveVertex(std::ostream &os, Vertex *v) const
virtual void preIteration(int)
called at the beginning of an iteration (argument is the number of the iteration) ...
bool fixed() const
true => this node is fixed during the optimization
void unlockQuadraticForm()
friend struct OptimizableGraph
std::set< HyperGraphAction * > HyperGraphActionSet
virtual void discardTop()
discard the last backup of the estimate for all variables by removing it from the stack ...
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
const Vertex * vertex(int id) const
returns the vertex number id appropriately casted
void setLevel(int l)
sets the level of the edge
ParameterContainer _parameters
virtual bool write(std::ostream &os) const =0
write the data to a stream
bool verifyInformationMatrices(bool verbose=false) const
virtual bool getEstimateData(std::vector< double > &estimate) const
provide memory workspace for computing the Jacobians
std::vector< HyperGraphActionSet > _graphActions
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
bool setEstimateData(const std::vector< double > &estimate)
OpenMPMutex _quadraticFormMutex
std::set< int > dimensions() const
bool addPreIterationAction(HyperGraphAction *action)
add an action to be executed before each iteration
Abstract action that operates on an entire graph.
OptimizableGraph * _graph