54 #define LINESIZE 81920 60 bool TreePoseGraph2::load(
const char* filename,
bool overrideCovariances){
62 ifstream is(filename);
69 istringstream ls(buf);
73 if (tag==
"VERTEX" || tag==
"VERTEX2"){
76 ls >>
id >> p.
x() >> p.
y() >> p.
theta();
82 if (tag==
"EDGE" || tag==
"EDGE2"){
86 ls >> id1 >> id2 >> p.
x() >> p.
y() >> p.
theta();
87 if (overrideCovariances){
97 TreePoseGraph2::Vertex* v1=vertex(id1);
98 TreePoseGraph2::Vertex* v2=vertex(id2);
100 addEdge(v1, v2,t ,m);
107 bool TreePoseGraph2::loadEquivalences(
const char* filename){
108 ifstream is(filename);
116 istringstream ls(buf);
122 Edge*
e=edge(id1,id2);
126 suppressed.push_back(e);
131 for (EdgeList::iterator it=suppressed.begin(); it!=suppressed.end(); it++){
133 if (e->v1->id > e->v2->id)
137 for (TreePoseGraph2::VertexMap::iterator it=
vertices.begin(); it!=
vertices.end(); it++){
138 Vertex* v=it->second;
141 for (TreePoseGraph2::EdgeMap::iterator it=edges.begin(); it!=edges.end(); it++){
142 TreePoseGraph2::Edge *
e=it->second;
143 e->v1->edges.push_back(e);
144 e->v2->edges.push_back(e);
149 bool TreePoseGraph2::saveGnuplot(
const char* filename){
150 ofstream os(filename);
154 for (TreePoseGraph2::EdgeMap::const_iterator it=edges.begin(); it!=edges.end(); it++){
155 const TreePoseGraph2::Edge *
e=it->second;
156 const Vertex* v1=e->v1;
157 const Vertex* v2=e->v2;
159 os << v1->pose.x() <<
" " << v1->pose.y() <<
" " << v1->pose.theta() << endl;
160 os << v2->pose.x() <<
" " << v2->pose.y() <<
" " << v2->pose.theta() << endl;
167 bool TreePoseGraph2::save(
const char* filename){
168 ofstream os(filename);
172 for (TreePoseGraph2::VertexMap::const_iterator it=
vertices.begin(); it!=
vertices.end(); it++){
173 const TreePoseGraph2::Vertex* v=it->second;
176 << v->pose.x() <<
" " 177 << v->pose.y() <<
" " 178 << v->pose.theta()<< endl;
180 for (TreePoseGraph2::EdgeMap::const_iterator it=edges.begin(); it!=edges.end(); it++){
181 const TreePoseGraph2::Edge *
e=it->second;
182 os <<
"EDGE " << e->v1->id <<
" " << e->v2->id <<
" ";
183 Pose p=e->transformation.toPoseType();
184 os << p.
x() <<
" " << p.
y() <<
" " << p.
theta() <<
" ";
185 os << e->informationMatrix.values[0][0] <<
" " 186 << e->informationMatrix.values[0][1] <<
" " 187 << e->informationMatrix.values[1][1] <<
" " 188 << e->informationMatrix.values[2][2] <<
" " 189 << e->informationMatrix.values[0][2] <<
" " 190 << e->informationMatrix.values[1][2] << endl;
201 std::cout <<
"(" << v->id <<
"," << v->level <<
")" << endl;
205 void TreePoseGraph2::printDepth( std::ostream& os ){
207 treeDepthVisit(ip,
root);
210 void TreePoseGraph2::printWidth( std::ostream& os ){
212 treeBreadthVisit(ip);
233 assert(v->parentEdge->v1==v->parent);
234 assert(v->parentEdge->v2==v);
239 void TreePoseGraph2::initializeOnTree(){
241 treeDepthVisit(pp,
root);
245 void TreePoseGraph2::printEdgesStat(std::ostream& os){
246 for (TreePoseGraph2::EdgeMap::const_iterator it=edges.begin(); it!=edges.end(); it++){
247 const TreePoseGraph2::Edge *
e=it->second;
248 os <<
"EDGE " << e->v1->id <<
" " << e->v2->id <<
" ";
249 Pose p=e->transformation.toPoseType();
250 os << p.
x() <<
" " << p.
y() <<
" " << p.
theta() <<
" ";
251 os << e->informationMatrix.values[0][0] <<
" " 252 << e->informationMatrix.values[0][1] <<
" " 253 << e->informationMatrix.values[1][1] <<
" " 254 << e->informationMatrix.values[2][2] <<
" " 255 << e->informationMatrix.values[0][2] <<
" " 256 << e->informationMatrix.values[1][2] << endl;
257 os <<
" top=" << e->top->id <<
" length=" << e->length << endl;
261 void TreePoseGraph2::revertEdgeInfo(Edge*
e){
264 R.
values[0][0]=e->transformation.rotationMatrix[0][0];
265 R.
values[0][1]=e->transformation.rotationMatrix[0][1];
268 R.
values[1][0]=e->transformation.rotationMatrix[1][0];
269 R.
values[1][1]=e->transformation.rotationMatrix[1][1];
286 e->transformation=it;
287 e->informationMatrix=IM;
290 void TreePoseGraph2::initializeFromParentEdge(Vertex* v){
292 v->transformation=tp;
294 v->parameters=v->pose;
295 v->parameters.x()-=v->parent->pose.x();
296 v->parameters.y()-=v->parent->pose.y();
297 v->parameters.theta()-=v->parent->pose.theta();
298 v->parameters.theta()=
atan2(
sin(v->parameters.theta()),
cos(v->parameters.theta()));
301 void TreePoseGraph2::collapseEdge(Edge*
e){
302 EdgeMap::iterator ie_it=edges.find(e);
303 if (ie_it==edges.end())
315 for (EdgeList::iterator it=v2->edges.begin(); it!=v2->edges.end(); it++){
321 for (EdgeList::iterator it=v1->edges.begin(); it!=v1->edges.end(); it++){
336 for (EdgeList::iterator it2=v2->edges.begin(); it2!=v2->edges.end(); it2++){
368 e2->transformation=T1x_pred;
369 e2->informationMatrix=I1x_pred;
374 std::list<Transformation> tList;
375 std::list<InformationMatrix> iList;
376 std::list<Vertex*> vList;
379 for (EdgeList::iterator it2=v2->edges.begin(); it2!=v2->edges.end(); it2++){
382 if ( ((*it2)->v1!=v1)){
384 for (EdgeList::iterator it1=v1->edges.begin(); it1!=v1->edges.end(); it1++){
385 if ((*it1)->v2==(*it2)->v2)
420 e1x->informationMatrix=IM;
423 tList.push_back(e2x->transformation);
424 iList.push_back(e2x->informationMatrix);
425 vList.push_back(e2x->v2);
428 removeVertex(v2->id);
430 std::list<Transformation>::iterator t=tList.begin();
431 std::list<InformationMatrix>::iterator i=iList.begin();
432 std::list<Vertex*>::iterator v=vList.begin();
433 while (i!=iList.end()){
434 addEdge(v1,*v,*t,*i);
Operations2D< double > ::CovarianceType Covariance
SMatrix3< T > transpose() const
A class to represent symmetric 3x3 matrices.
GLM_FUNC_DECL genType e()
static const float vertices[]
Defines the graph of 2D poses, with specific functionalities such as loading, saving, merging constraints, and etc.
GLM_FUNC_DECL genType cos(genType const &angle)
GLM_FUNC_DECL genType sin(genType const &angle)
std::list< Edge * > EdgeList
SMatrix3< T > inv() const
GLM_FUNC_QUALIFIER T atan2(T x, T y)
Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what q...
void perform(TreePoseGraph2::Vertex *v)
void perform(TreePoseGraph2::Vertex *v)
IdPrinter(std::ostream &_os)
2D Point (x,y) with orientation (theta)
A class (struct) for realizing the pose update of the individual nodes. Assumes the correct order of ...
A class (struct) used to print vertex information to a stream. Needed for debugging.