27 #ifndef G2O_AIS_OPTIMIZABLE_GRAPH_HH_ 28 #define G2O_AIS_OPTIMIZABLE_GRAPH_HH_ 48 class HyperGraphAction;
49 struct OptimizationAlgorithmProperty;
85 return v1->
id() < v2->
id();
93 bool operator() (
const Edge* e1,
const Edge* e2)
const 114 virtual Vertex* clone()
const ;
122 virtual const double& hessian(
int i,
int j)
const = 0;
123 virtual double& hessian(
int i,
int j) = 0;
124 virtual double hessianDeterminant()
const = 0;
125 virtual double* hessianData() = 0;
128 virtual void mapHessianMemory(
double* d) = 0;
134 virtual int copyB(
double* b_)
const = 0;
137 virtual const double& b(
int i)
const = 0;
138 virtual double& b(
int i) = 0;
140 virtual double* bData() = 0;
145 virtual void clearQuadraticForm() = 0;
151 virtual double solveDirect(
double lambda=0) = 0;
158 bool setEstimateData(
const double* estimate);
167 int dim = estimateDimension();
168 assert((dim == -1) || (estimate.size() == std::size_t(dim)));
170 return setEstimateData(&estimate[0]);
177 virtual bool getEstimateData(
double* estimate)
const;
184 int dim = estimateDimension();
187 estimate.resize(dim);
188 return getEstimateData(&estimate[0]);
195 virtual int estimateDimension()
const;
202 bool setMinimalEstimateData(
const double* estimate);
211 int dim = minimalEstimateDimension();
212 assert((dim == -1) || (estimate.size() == std::size_t(dim)));
214 return setMinimalEstimateData(&estimate[0]);
221 virtual bool getMinimalEstimateData(
double* estimate)
const ;
228 int dim = minimalEstimateDimension();
231 estimate.resize(dim);
232 return getMinimalEstimateData(&estimate[0]);
239 virtual int minimalEstimateDimension()
const;
242 virtual void push() = 0;
245 virtual void pop() = 0;
248 virtual void discardTop() = 0;
251 virtual int stackSize()
const = 0;
286 virtual void setId(
int id) {_id = id;}
307 virtual bool read(std::istream& is) = 0;
309 virtual bool write(std::ostream& os)
const = 0;
311 virtual void updateCache();
330 virtual void oplusImpl(
const double* v) = 0;
333 virtual void setToOriginImpl() = 0;
356 virtual Edge* clone()
const;
359 virtual bool allVerticesFixed()
const = 0;
362 virtual void computeError() = 0;
366 virtual bool setMeasurementData(
const double* m);
370 virtual bool getMeasurementData(
double* m)
const;
374 virtual int measurementDimension()
const;
380 virtual bool setMeasurementFromState();
390 virtual const double* errorData()
const = 0;
391 virtual double* errorData() = 0;
394 virtual const double* informationData()
const = 0;
395 virtual double* informationData() = 0;
398 virtual double chi2()
const = 0;
406 virtual void constructQuadraticForm() = 0;
416 virtual void mapHessianMemory(
double* d,
int i,
int j,
bool rowMajor) = 0;
447 virtual bool read(std::istream& is) = 0;
449 virtual bool write(std::ostream& os)
const = 0;
457 bool setParameterId(
int argNum,
int paramId);
461 _parameters.resize(newSize, 0);
462 _parameterIds.resize(newSize, -1);
463 _parameterTypes.resize(newSize,
typeid(
void*).name());
472 template <
typename ParameterType>
474 if (argNo>=_parameters.size())
476 _parameterIds[argNo] = paramId;
478 _parameterTypes[argNo] =
typeid(ParameterType).name();
482 template <
typename CacheType>
484 const std::string& _type,
487 bool resolveParameters();
488 virtual bool resolveCaches();
532 int maxDimension()
const;
537 std::set<int> dimensions()
const;
543 virtual int optimize(
int iterations,
bool online=
false);
546 virtual void preIteration(
int);
548 virtual void postIteration(
int);
565 virtual void discardTop();
568 virtual bool load(std::istream& is,
bool createEdges=
true);
569 bool load(
const char* filename,
bool createEdges=
true);
571 virtual bool save(std::ostream& os,
int level = 0)
const;
573 bool save(
const char* filename,
int level = 0)
const;
597 void setRenamedTypesFromString(
const std::string&
types);
609 virtual void clearParameters();
612 return _parameters.addParameter(p);
616 return _parameters.getParameter(
id);
625 bool verifyInformationMatrices(
bool verbose =
false)
const;
628 bool saveVertex(std::ostream& os,
Vertex* v)
const;
631 bool saveParameter(std::ostream& os,
Parameter* v)
const;
634 bool saveEdge(std::ostream& os,
Edge* e)
const;
649 static bool initMultiThreading();
stuff to open files and other unsorted components ProjectiveCamera types
bool installParameter(ParameterType *&p, size_t argNo, int paramId=-1)
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
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
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
virtual Vertex * createVertex(int)
int G2O_ATTRIBUTE_DEPRECATED(tempIndex() const)
CacheContainer * _cacheContainer
G2O_ATTRIBUTE_DEPRECATED(virtual Vertex *createTo())
OptimizableGraph * graph()
virtual bool getMinimalEstimateData(std::vector< double > &estimate) const
std::set< Vertex * > VertexSet
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
int level() const
returns the level of the edge
int hessianIndex() const
temporary index of this node in the parameter vector obtained from linearization
Vertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
virtual bool setMinimalEstimateDataImpl(const double *)
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 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
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
size_t numParameters() const
std::vector< int > _parameterIds
RobustKernel * _robustKernel
std::vector< Parameter * > ParameterVector
G2O_ATTRIBUTE_DEPRECATED(virtual Vertex *createFrom())
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
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 resizeParameters(size_t newSize)
Parameter * parameter(int id)
JacobianWorkspace _jacobianWorkspace
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
bool fixed() const
true => this node is fixed during the optimization
void unlockQuadraticForm()
std::set< HyperGraphAction * > HyperGraphActionSet
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
Container class that implements an interface for adding/removing Data elements in a linked list...
ParameterContainer _parameters
virtual bool getEstimateData(std::vector< double > &estimate) const
provide memory workspace for computing the Jacobians
std::vector< HyperGraphActionSet > _graphActions
bool setEstimateData(const std::vector< double > &estimate)
OpenMPMutex _quadraticFormMutex
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
const ParameterContainer & parameters() const
Abstract action that operates on an entire graph.
ParameterContainer & parameters()
OptimizableGraph * _graph