47 bool overrideCovariances) {
49 ifstream is(filename.c_str());
50 if (!is.good())
return false;
52 bool laserOffsetInitDone =
false;
57 cerr <<
"Unable to add laser offset" << endl;
62 stringstream currentLine;
65 int bytesRead =
readLine(is, currentLine);
66 if (bytesRead == -1)
break;
69 if (tag ==
"VERTEX" || tag ==
"VERTEX2" || tag ==
"VERTEX_SE2") {
72 currentLine >>
id >> p.x() >> p.y() >> p.z();
78 cerr <<
"vertex " <<
id <<
" is already in the graph, reassigning "
87 }
else if (tag ==
"EDGE" || tag ==
"EDGE2" || tag ==
"EDGE_SE2") {
88 if (!laserOffsetInitDone) {
89 cerr <<
"Error: need laser offset" << endl;
96 currentLine >> id1 >> id2 >> p.x() >> p.y() >> p.z();
97 if (overrideCovariances) {
98 m = Eigen::Matrix3d::Identity();
100 if (tag ==
"EDGE_SE2")
101 currentLine >> m(0, 0) >> m(0, 1) >> m(0, 2) >> m(1, 1) >> m(1, 2) >>
104 currentLine >> m(0, 0) >> m(0, 1) >> m(1, 1) >> m(2, 2) >> m(0, 2) >>
114 cerr <<
"vertex " << id1 <<
" is not existing, cannot add edge (" << id1
115 <<
"," << id2 <<
")" << endl;
120 cerr <<
"vertex " << id2 <<
" is not existing, cannot add edge (" << id1
121 <<
"," << id2 <<
")" << endl;
142 cerr <<
"error in adding edge " << id1 <<
"," << id2 << endl;
148 }
else if (tag ==
"ROBOTLASER1") {
149 if (previousVertex) {
151 rl2->
read(currentLine);
152 if (!laserOffsetInitDone) {
153 laserOffsetInitDone =
true;
169 ofstream fout(filename.c_str());
175 for (SparseOptimizer::VertexIDMap::const_iterator it =
177 it != optimizer.
vertices().end(); ++it) {
180 fout <<
"VERTEX2 " << v->
id() <<
" ";
185 string tag = factory->
tag(data);
186 if (tag.size() > 0) {
196 for (HyperGraph::EdgeSet::const_iterator it = optimizer.
edges().begin();
197 it != optimizer.
edges().end(); ++it) {
202 sort(edgesToSave.begin(), edgesToSave.end(),
205 for (OptimizableGraph::EdgeContainer::const_iterator it = edgesToSave.begin();
206 it != edgesToSave.end(); ++it) {
211 fout <<
"EDGE2 " << calibEdge->
vertex(0)->
id() <<
" "
213 Eigen::Vector3d meas = calibEdge->
measurement().toVector();
214 fout <<
" " << meas.x() <<
" " << meas.y() <<
" " << meas.z();
215 const Eigen::Matrix3d& m = calibEdge->
information();
216 fout <<
" " << m(0, 0) <<
" " << m(0, 1) <<
" " << m(1, 1) <<
" "
217 << m(2, 2) <<
" " << m(0, 2) <<
" " << m(1, 2);
231 cerr <<
"Laser offset not found" << endl;
235 for (SparseOptimizer::VertexIDMap::const_iterator it =
237 it != optimizer.
vertices().end(); ++it) {
253 ifstream is(filename.c_str());
254 if (!is.good())
return false;
259 stringstream currentLine;
261 int bytesRead =
readLine(is, currentLine);
262 if (bytesRead == -1)
break;
265 if (tag ==
"ROBOTLASER1") {
267 rl2->
read(currentLine);
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
const EstimateType & estimate() const
return the current estimate of the vertex
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
scanmatch measurement that also calibrates an offset for the laser
void setMeasurement(const SE2 &m)
create vertices and edges based on TAGs in, for example, a file
static Factory * instance()
return the instance
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
static bool readGm2dl(const std::string &filename, SparseOptimizer &optimizer, bool overrideCovariances=false)
static const int ID_LASERPOSE
static const int ID_ODOMCALIB
static int readRobotLaser(const std::string &filename, DataQueue &queue)
static bool updateLaserData(SparseOptimizer &optimizer)
static bool writeGm2dl(const std::string &filename, const SparseOptimizer &optimizer)
const Data * userData() const
the user data associated with this vertex
void setUserData(Data *obs)
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
virtual bool write(std::ostream &os) const =0
write the data to a stream
void setVertex(size_t i, Vertex *v)
const Vertex * vertex(size_t i) const
int id() const
returns the id
const EdgeSet & edges() const
const VertexIDMap & vertices() const
A general case Vertex for optimization.
virtual bool write(std::ostream &os) const =0
write the vertex to a stream
virtual void setId(int id)
void setLaserParams(const LaserParameters &laserParams)
const LaserParameters & laserParams() const
the parameters of the laser
laser measurement obtained by a robot
virtual bool read(std::istream &is)
read the data from a stream
void setOdomPose(const SE2 &odomPose)
SE2 inverse() const
invert :-)
void fromVector(const Vector3 &v)
assign from a 3D vector (x, y, theta)
2D pose Vertex, (x,y,theta)
int readLine(std::istream &is, std::stringstream ¤tLine)
parameters for a 2D range finder
order edges based on the internal ID, which is assigned to the edge in addEdge()
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
Vertex * vertex(int id)
returns the vertex number id appropriately casted