52 #define LINESIZE 81920
58 bool TreePoseGraph3::load(
const char* filename,
bool overrideCovariances,
bool twoDimensions){
67 istringstream ls(buf);
74 Pose p(0.,0.,0.,0.,0.,0.);
75 ls >>
id >>
p.x() >>
p.y() >>
p.yaw();
76 TreePoseGraph3::Vertex*
v=addVertex(
id,
p);
85 ls >>
id >>
p.x() >>
p.y() >>
p.z() >>
p.roll() >>
p.pitch() >>
p.yaw();
86 TreePoseGraph3::Vertex*
v=addVertex(
id,
p);
94 is.seekg(0, ios::beg);
100 istringstream ls(buf);
107 Pose p(0.,0.,0.,0.,0.,0.);
109 ls >> id1 >> id2 >>
p.x() >>
p.y() >>
p.yaw();
111 if (! overrideCovariances){
112 ls >>
m[0][0] >>
m[0][1] >>
m[1][1] >>
m[2][2] >>
m[0][2] >>
m[1][2];
113 m[2][0]=
m[0][2];
m[2][1]=
m[1][2];
m[1][0]=
m[0][1];
116 TreePoseGraph3::Vertex*
v1=vertex(id1);
117 TreePoseGraph3::Vertex*
v2=vertex(id2);
119 if (!addEdge(
v1,
v2,
t ,
m)){
120 cerr <<
"Fatal, attempting to insert an edge between non existing nodes, skipping";
121 cerr <<
"edge=" << id1 <<
" -> " << id2 << endl;
130 ls >> id1 >> id2 >>
p.x() >>
p.y() >>
p.z() >>
p.roll() >>
p.pitch() >>
p.yaw();
132 if (! overrideCovariances){
133 for (
int i=0;
i<6;
i++)
134 for (
int j=
i;
j<6;
j++)
137 TreePoseGraph3::Vertex*
v1=vertex(id1);
138 TreePoseGraph3::Vertex*
v2=vertex(id2);
140 if (!addEdge(
v1,
v2,
t ,
m)){
141 cerr <<
"Fatal, attempting to insert an edge between non existing nodes, skipping";
142 cerr <<
"edge=" << id1 <<
" -> " << id2 << endl;
152 bool TreePoseGraph3::loadEquivalences(
const char* filename){
161 istringstream ls(buf);
167 Edge*
e=edge(id1,id2);
171 suppressed.push_back(
e);
176 for (EdgeList::iterator it=suppressed.begin(); it!=suppressed.end(); it++){
178 if (
e->v1->id >
e->v2->id)
185 bool TreePoseGraph3::saveGnuplot(
const char* filename){
189 for (TreePoseGraph3::VertexMap::iterator it=
vertices.begin(); it!=
vertices.end(); it++){
190 TreePoseGraph3::Vertex*
v=it->second;
191 v->pose=
v->transformation.toPoseType();
193 for (TreePoseGraph3::EdgeMap::const_iterator it=
edges.begin(); it!=
edges.end(); it++){
194 const TreePoseGraph3::Edge *
e=it->second;
195 const Vertex*
v1=
e->v1;
196 const Vertex*
v2=
e->v2;
198 os <<
v1->pose.x() <<
" " <<
v1->pose.y() <<
" " <<
v1->pose.z() <<
" "
199 <<
v1->pose.roll() <<
" " <<
v1->pose.pitch() <<
" " <<
v1->pose.yaw() <<endl;
200 os <<
v2->pose.x() <<
" " <<
v2->pose.y() <<
" " <<
v2->pose.z() <<
" "
201 <<
v2->pose.roll() <<
" " <<
v2->pose.pitch() <<
" " <<
v2->pose.yaw() <<endl;
208 bool TreePoseGraph3::save(
const char* filename){
213 for (TreePoseGraph3::VertexMap::iterator it=
vertices.begin(); it!=
vertices.end(); it++){
214 TreePoseGraph3::Vertex*
v=it->second;
215 v->pose=
v->transformation.toPoseType();
219 <<
v->pose.x() <<
" "
220 <<
v->pose.y() <<
" "
221 <<
v->pose.z() <<
" "
222 <<
v->pose.roll() <<
" "
223 <<
v->pose.pitch() <<
" "
224 <<
v->pose.yaw() << endl;
226 for (TreePoseGraph3::EdgeMap::const_iterator it=
edges.begin(); it!=
edges.end(); it++){
227 const TreePoseGraph3::Edge *
e=it->second;
228 os <<
"EDGE3 " <<
e->v1->id <<
" " <<
e->v2->id <<
" ";
229 Pose p=
e->transformation.toPoseType();
230 os <<
p.x() <<
" " <<
p.y() <<
" " <<
p.z() <<
" " <<
p.roll() <<
" " <<
p.pitch() <<
" " <<
p.yaw() <<
" ";
231 for (
int i=0;
i<6;
i++)
232 for (
int j=
i;
j<6;
j++)
233 os <<
e->informationMatrix[
i][
j] <<
" ";
245 std::cout <<
"(" <<
v->id <<
"," <<
v->level <<
")" << endl;
249 void TreePoseGraph3::printDepth( std::ostream& os ){
251 treeDepthVisit(ip,
root);
254 void TreePoseGraph3::printWidth( std::ostream& os ){
256 treeBreadthVisit(ip);
270 assert(
v->parentEdge->v1==
v->parent);
271 assert(
v->parentEdge->v2==
v);
272 v->transformation=tNode;
276 void TreePoseGraph3::initializeOnTree(){
278 treeDepthVisit(pp,
root);
282 void TreePoseGraph3::printEdgesStat(std::ostream& os){
283 for (TreePoseGraph3::EdgeMap::const_iterator it=
edges.begin(); it!=
edges.end(); it++){
284 const TreePoseGraph3::Edge *
e=it->second;
285 os <<
"EDGE " <<
e->v1->id <<
" " <<
e->v2->id <<
" ";
286 Pose p=
e->transformation.toPoseType();
287 os <<
p.x() <<
" " <<
p.y() <<
" " <<
p.z() <<
" " <<
p.roll() <<
" " <<
p.pitch() <<
" " <<
p.yaw() << endl;
288 os <<
" top=" <<
e->top->id <<
" length=" <<
e->length << endl;
292 void TreePoseGraph3::revertEdgeInfo(Edge*
e){
295 e->transformation=
e->transformation.inv();
298 void TreePoseGraph3::initializeFromParentEdge(Vertex* v){
300 v->transformation=tp;
302 v->parameters=
v->parentEdge->transformation;
306 void TreePoseGraph3::collapseEdge(Edge*
e){
311 for (EdgeList::iterator it=
v2->edges.begin(); it!=
v2->edges.end(); it++){
317 for (EdgeList::iterator it=
v1->edges.begin(); it!=
v1->edges.end(); it++){
332 for (EdgeList::iterator it2=
v2->edges.begin(); it2!=
v2->edges.end(); it2++){
351 e2->transformation=T1x_pred;
352 e2->informationMatrix=I1x_pred;
357 std::list<Transformation> tList;
358 std::list<InformationMatrix> iList;
359 std::list<Vertex*> vList;
362 for (EdgeList::iterator it2=
v2->edges.begin(); it2!=
v2->edges.end(); it2++){
365 if ( ((*it2)->v1!=
v1)){
367 for (EdgeList::iterator it1=
v1->edges.begin(); it1!=
v1->edges.end(); it1++){
368 if ((*it1)->v2==(*it2)->v2)
382 tList.push_back(e2x->transformation);
383 iList.push_back(e2x->informationMatrix);
384 vList.push_back(e2x->v2);
387 removeVertex(
v2->id);
389 std::list<Transformation>::iterator
t=tList.begin();
390 std::list<InformationMatrix>::iterator
i=iList.begin();
391 std::list<Vertex*>::iterator
v=vList.begin();
392 while (
i!=iList.end()){
393 addEdge(
v1,*
v,*
t,*
i);
400 void TreePoseGraph3::recomputeAllTransformations(){
402 treeDepthVisit(tp,
root);