posegraph.hh

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  * This source code is part of the Tree-based Network Optimizer (TORO)
00004  *
00005  * TORO Copyright (c) 2007 Giorgio Grisetti, Cyrill Stachniss, and
00006  * Wolfram Burgard
00007  *
00008  * TORO is licences under the Common Creative License,
00009  * Attribution-NonCommercial-ShareAlike 3.0
00010  *
00011  * You are free:
00012  *   - to Share - to copy, distribute and transmit the work
00013  *   - to Remix - to adapt the work
00014  *
00015  * Under the following conditions:
00016  *
00017  *   - Attribution. You must attribute the work in the manner specified
00018  *     by the author or licensor (but not in any way that suggests that
00019  *     they endorse you or your use of the work).
00020  *  
00021  *   - Noncommercial. You may not use this work for commercial purposes.
00022  *  
00023  *   - Share Alike. If you alter, transform, or build upon this work,
00024  *     you may distribute the resulting work only under the same or
00025  *     similar license to this one.
00026  *
00027  * Any of the above conditions can be waived if you get permission
00028  * from the copyright holder.  Nothing in this license impairs or
00029  * restricts the author's moral rights.
00030  *
00031  * TORO is distributed in the hope that it will be useful,
00032  * but WITHOUT ANY WARRANTY; without even the implied 
00033  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00034  * PURPOSE.  
00035  **********************************************************************/
00036 
00043 #ifndef _TREEPOSEGRAPH_HXX_
00044 #define _TREEPOSEGRAPH_HXX_
00045 
00046 #include <iostream>
00047 #include <assert.h>
00048 
00049 #include <set>
00050 #include <list>
00051 #include <map>
00052 #include <deque>
00053 #include <vector>
00054 #include <values.h>
00055 #include <algorithm>
00056 
00057 
00060 template <class E> 
00061 struct EVComparator{
00063   enum CompareMode {CompareLevel, CompareLength};
00064   CompareMode mode;
00065 
00066   EVComparator(){
00067     mode=CompareLevel;
00068   }
00069   inline bool operator() (const E& e1, const E& e2){
00070     int o1=0, o2=0;
00071     switch (mode){
00072     case CompareLevel:
00073       o1=e1->top->level;
00074       o2=e2->top->level;
00075       break;
00076     case CompareLength:
00077       o1=e1->length;
00078       o2=e2->length;
00079       break;
00080     }
00081     return o1<o2;
00082   }
00083 };
00084 
00089 template <class Ops>
00090 struct TreePoseGraph{
00091   typedef typename Ops::BaseType BaseType;
00092   typedef typename Ops::PoseType Pose;
00093   typedef typename Ops::RotationType Rotation;
00094   typedef typename Ops::TranslationType Translation;
00095   typedef typename Ops::TransformationType Transformation;
00096   typedef typename Ops::CovarianceType Covariance;
00097   typedef typename Ops::InformationType Information;
00098   typedef typename Ops::ParametersType  Parameters;
00099   
00100   struct Vertex;
00101 
00104   struct Edge{
00105     Vertex* v1;   
00106     Vertex* v2;   
00107     Vertex* top;  
00108     int length;   
00109     Transformation transformation;    
00110     Information    informationMatrix; 
00112     bool mark;
00113     
00114     double learningRate;
00115   };
00116 
00117   typedef typename EVComparator<Edge*>::CompareMode EdgeCompareMode;
00118   typedef typename std::list< Edge* > EdgeList;
00119   typedef typename std::map< int, Vertex* > VertexMap;
00120   typedef typename std::set< Vertex* > VertexSet;
00121   typedef typename std::map< Edge*, Edge* > EdgeMap;
00122   typedef typename std::multiset< Edge*, EVComparator<Edge*> > EdgeSet;
00123 
00126   struct Vertex {
00127 
00128     // Graph-related elements
00129     int id;         
00130     EdgeList edges; 
00132     // Tree-related elements
00133     int level;         
00134     Vertex* parent;    
00135     Edge* parentEdge;  
00136     EdgeList children;   
00138     // Parameterization-related elements
00139     Transformation transformation; 
00140     Pose pose;              
00141     Parameters parameters;  
00143     bool mark;
00144   };
00145 
00147   Vertex* vertex(int id);
00148 
00150   const Vertex* vertex (int id) const;
00151 
00153   Edge* edge(int id1, int id2);
00154 
00156   const Edge* edge(int id1, int id2) const;
00157 
00159   Vertex* addVertex(int id, const Pose& pose);
00161   Vertex* removeVertex (int id);
00162 
00164   Edge* addEdge(Vertex* v1, Vertex* v2, const Transformation& t, const Information& i);
00165 
00167   Edge* removeEdge(Edge* eq);
00168 
00183   Edge* addIncrementalEdge(int id1, int id2,  const Transformation& t, const Information& i);
00184 
00188   EdgeSet* affectedEdges(Vertex* v);
00189 
00190   EdgeSet* affectedEdges(VertexSet& vl);
00191 
00193   template <class Action>
00194   void treeBreadthVisit(Action& act);
00195 
00197   template <class Action>
00198   void treeDepthVisit(Action& act, Vertex *v);
00199 
00201   int markNodesToCompress(BaseType distance);
00202 
00204   bool buildMST(int id);
00205 
00207   bool buildSimpleTree();
00208 
00210   void revertEdge(Edge* e);
00211 
00213   virtual void revertEdgeInfo(Edge* e) = 0;
00214 
00216   virtual void initializeFromParentEdge(Vertex* v) = 0;
00217 
00219   void clear();
00220 
00222   TreePoseGraph(){
00223     sortedEdges=0; 
00224     edgeCompareMode=EVComparator<Edge*>::CompareLevel;
00225   }
00226 
00228   virtual ~TreePoseGraph();
00229 
00231   EdgeSet* sortEdges();
00232 
00234   int maxPathLength();
00235 
00237   int totalPathLength();
00238 
00240   void compressIndices();
00241 
00243   int maxIndex();
00244 
00246   Vertex* root;
00247 
00249   VertexMap vertices;
00250 
00252   EdgeMap edges;
00253 
00258   EdgeSet* sortedEdges;
00259 
00260 protected:
00261   void fillEdgeInfo(Edge* e);
00262   void fillEdgesInfo();
00263   EdgeCompareMode edgeCompareMode;
00264 };
00265 
00266 //include the template implementation part
00267 
00268 #include "posegraph.hxx"
00269 
00270 #endif

Generated on Mon Nov 12 11:43:00 2007 for TORO by  doxygen 1.5.0