45 const int Gm2dlIO::ID_LASERPOSE = numeric_limits<int>::max();
46 const int Gm2dlIO::ID_ODOMCALIB = numeric_limits<int>::max() - 1;
48 bool Gm2dlIO::readGm2dl(
const std::string& filename,
SparseOptimizer& optimizer,
bool overrideCovariances)
51 ifstream is(filename.c_str());
55 bool laserOffsetInitDone =
false;
58 laserOffset->
setId(ID_LASERPOSE);
60 cerr <<
"Unable to add laser offset" << endl;
65 stringstream currentLine;
68 int bytesRead =
readLine(is, currentLine);
73 if (tag ==
"VERTEX" || tag ==
"VERTEX2" || tag ==
"VERTEX_SE2"){
76 currentLine >>
id >> p.x() >> p.y() >> p.z();
82 cerr <<
"vertex " <<
id <<
" is already in the graph, reassigning "<< endl;
90 }
else if (tag ==
"EDGE" || tag ==
"EDGE2" || tag ==
"EDGE_SE2"){
91 if (! laserOffsetInitDone) {
92 cerr <<
"Error: need laser offset" << endl;
99 currentLine >> id1 >> id2 >> p.x() >> p.y() >> p.z();
100 if (overrideCovariances){
101 m = Eigen::Matrix3d::Identity();
103 if (tag ==
"EDGE_SE2")
104 currentLine >> m(0, 0) >> m(0, 1) >> m(0, 2) >> m(1, 1) >> m(1, 2) >> m(2, 2);
106 currentLine >> m(0, 0) >> m(0, 1) >> m(1, 1) >> m(2, 2) >> m(0, 2) >> m(1, 2);
115 cerr <<
"vertex " << id1 <<
" is not existing, cannot add edge (" << id1 <<
"," << id2 <<
")" << endl;
120 cerr <<
"vertex " << id2 <<
" is not existing, cannot add edge (" << id1 <<
"," << id2 <<
")" << endl;
138 cerr <<
"error in adding edge " << id1 <<
"," << id2 << endl;
144 }
else if (tag ==
"ROBOTLASER1") {
145 if (previousVertex) {
147 rl2->
read(currentLine);
148 if (! laserOffsetInitDone) {
149 laserOffsetInitDone =
true;
162 bool Gm2dlIO::writeGm2dl(
const std::string& filename,
const SparseOptimizer& optimizer)
164 ofstream fout(filename.c_str());
168 Factory* factory = Factory::instance();
170 for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer.
vertices().begin(); it != optimizer.
vertices().end(); ++it) {
172 fout <<
"VERTEX2 " << v->
id() <<
" ";
177 string tag = factory->
tag(data);
178 if (tag.size() > 0) {
187 for (HyperGraph::EdgeSet::const_iterator it = optimizer.
edges().begin(); it != optimizer.
edges().end(); ++it) {
189 edgesToSave.push_back(const_cast<OptimizableGraph::Edge*>(e));
193 for (OptimizableGraph::EdgeContainer::const_iterator it = edgesToSave.begin(); it != edgesToSave.end(); ++it) {
198 fout <<
"EDGE2 " << calibEdge->
vertex(0)->
id() <<
" " << calibEdge->
vertex(1)->
id();
200 fout <<
" " << meas.x() <<
" " << meas.y() <<
" " << meas.z();
201 const Eigen::Matrix3d& m = calibEdge->
information();
202 fout <<
" " << m(0, 0) <<
" " << m(0, 1) <<
" " << m(1, 1) <<
" " 203 << m(2, 2) <<
" " << m(0, 2) <<
" " << m(1, 2);
217 cerr <<
"Laser offset not found" << endl;
221 for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer.
vertices().begin(); it != optimizer.
vertices().end(); ++it) {
225 if (v->
id() == ID_LASERPOSE)
238 int Gm2dlIO::readRobotLaser(
const std::string& filename,
DataQueue& queue)
240 ifstream is(filename.c_str());
247 stringstream currentLine;
249 int bytesRead =
readLine(is, currentLine);
254 if (tag ==
"ROBOTLASER1") {
256 rl2->
read(currentLine);
virtual bool write(std::ostream &os) const =0
write the vertex to a stream
virtual bool write(std::ostream &os) const =0
write the data to a stream
int id() const
returns the id
const Vertex * vertex(size_t i) const
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
const Data * userData() const
the user data associated with this vertex
Vector3D toVector() const
convert to a 3D vector (x, y, theta)
scanmatch measurement that also calibrates an offset for the laser
laser measurement obtained by a robot
void setOdomPose(const SE2 &odomPose)
2D pose Vertex, (x,y,theta)
void setLaserParams(const LaserParameters &laserParams)
void setVertex(size_t i, Vertex *v)
virtual bool read(std::istream &is)
read the data from a stream
const VertexIDMap & vertices() const
Vertex * vertex(int id)
returns the vertex number id appropriately casted
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 ...
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
void setMeasurement(const SE2 &m)
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
const EdgeSet & edges() const
void fromVector(const Vector3D &v)
assign from a 3D vector (x, y, theta)
create vertices and edges based on TAGs in, for example, a file
int readLine(std::istream &is, std::stringstream ¤tLine)
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
a simple queue to store data and retrieve based on a timestamp
order edges based on the internal ID, which is assigned to the edge in addEdge()
A general case Vertex for optimization.
const LaserParameters & laserParams() const
the parameters of the laser
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
void setUserData(Data *obs)
const EstimateType & estimate() const
return the current estimate of the vertex
SE2 inverse() const
invert :-)
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
parameters for a 2D range finder