Debian Codegraph @

doc/README_IF_IT_WAS_WORKING_AND_IT_DOES_NOT.txt

raw
1 There is some relevant change in the devel release of g2o.
2
3 Here is the list
4
5 *CHANGE IN THE ACCESSORS*
6 The following non const accessors have been removed
7
8 Vertex class:
9 EstType& Vertex::estimate(); // use Vertex::setEstimate(const EstType& est);
10
11 Edge class:
12 MeasType& Edge::measurement(); // use Edge::setMeasurement(const MeasType& m);
13 MeasType& Edge::inverseMeasurement(); // the inverse measurement should be computed directly by setMeasurement. not possible to set it by hand to avoid inconsistencies
14
15 SE3Quat class:
16 Vector3d& SE3Quat::translation(); // use SE3Quat::setTranslation(...) instead;
17 Quarerniond& SE3Quat::rotation(); // use SE3Quat::setRotation(...) instead; This also ensures that the quaternion is normalized and w>0.
18 double& opertor[]; // we disabled the write access to se3 elements to avoid inconsistencied in the representation.
19 // people like to introduce inconsistencies in the representation.
20
21 SE2 class:
22 Vector2d& SE2::translation(); // use SE2::setTranslation(...) instead.
23 Rotation2Dd& SE2::rotation(); // use SE2::setRotation(...) instead. This ensures that the orientation is normalized
24 double& opertor[]; // removed, same as in the list before.
25
26
27 *PARAMETERS*
28 It is possible to add parameters blocks in a graph.
29 Parameters are be quantities that are fixed during the optimization,
30 like the offset of a sensor or the intrinsics of a camera.
31
32 Parameters are identified by a unique int id.
33 See the Parameters class in optimizable_graph.
34
35
36 If you want to create a parameter block for a graph you have to
37
38 1) extend the class Parameters
39
40 class MyParams: public Parameters {
41 ...
42 ...
43 virtual void read(istream& os) {
44 //implement here your read function;
45 }
46
47 virtual void write(ostream& os) {
48 //implement here your write function;
49 }
50
51 }
52
53 2) register the parameters in the metatype system
54
55 factory->registerType("MY_PARAMS", new HyperGraphElementCreator<MyParams>);
56 The parameters are always saved at the beginning of a graph file
57
58
59 3) to insert parameters in a graph you have to
60
61 // create the parameters
62 MyParams* p=new MyParams();
63
64 // set an id
65 p->setId(0);
66
67 // add them to the graph
68 if (opt->addParameters(p)){
69 cerr << "success" << endl;
70 } else {
71 cerr << "fail" << endl;
72 }
73
74 4) to access the parameters by id you can use the
75 OptimizableGraph::parameters(int id) function;
76
77 MyParams* p = dynamic_cast<MyParams*>opt->(parameters(id));
78
79
80 *CACHE*
81
82 A cache is some structure that contains intermediate
83 calculations that depend on the estimate stored in a vertex.
84 Cache stores some intermediate result that would be computer
85 over and over again, during the computeError() of edges that involve the same vertex.
86 g2o now supports the caches, however it is good practice to use them
87 only when an initial system is running well, to get faster computation.
88
89 For instance a cache of an SE3 can contain a rotation matrix,
90 its opposite, a useful quantity to compute the Jacobian and so on.
91
92 Each vertex can have zero or more cache blocks,
93 whose pointers are stored in a vector within the vertex
94 (in _cacheVector).
95 Thus each cache block is indexed within a vertex by a unique
96 id (VertexCache::_id), that corresponds to its position in the
97 _cacheVector.
98
99 Cache blocks are dynamic, in the sense that they are created
100 only by those edges that require them, when they are inserted
101 in a graph (addEdge.)
102 To construct a cache, an edge should:
103 - tell which cache_id is associated to each of the
104 connected vertices. These ids are stored in a vector
105 stored inside the edge (_cacheIds).
106 - implement a function that "creates" a cache for a certain vertex
107 VertexCache* createCache(int vertexNum, OptimizableGraph* g).
108
109
110 So in short, if you want to use a cache you should:
111 1) Extend the VertexCache class to do the right things
112 In this class you have to implement the update() method,
113 that will be called whenever the estimate of the
114 corresponding vertex changes.
115
116 2) In an edge where you want to use a cache, you should
117 define a createCache(int vertexNum) function that creates a
118 new instance of cache for the vertex at position
119 vertexNum within Edge::_vertices.
120
121 3) Before inserting an edge that uses a cache in a graph,
122 you should tell the system which cache id is associated to
123 each vertex of the edge. This is done by filling the _cacheIds
124 vector with the ids. An id of -1 means no cache.
125
126 4) Each method that changes the estimate of a vertex
127 (e.g. oplus) should update the cache accordingly.
128
129
130 As an example:
131
132 class MyCache: public VertexCache{
133 MyCache(Vertex*v, int id): VertexCache(v, id);
134 virtual void update(){
135 // update here the cache
136 //contents based on the vertex estimate
137 }
138 };
139
140 class EdgeThatUsesACache: public EdgeThatDoesNotUseACache{
141 EdgeThatUsesACache(): EdgeThatDoesNotUseACache{
142 // resize the cache vector, all empty caches
143 _cacheIds.resize(vertices().size(), -1);
144 }
145
146
147 virtual VertexCache* createCache(int vertexNum) {
148 OptimizableGraph::Vertex*v
149 = (OptimizableGraph::Vertex*)vertices()[vertexNum];
150
151 if (vertexNum==0){
152 return new MyCache(v, _cacheIds[0]);
153 }
154 if (vertexNum==1){
155 return new AnotherCache(v, _cacheIds[1]);
156 }
157 ....
158 }
159
160 void computeError() {
161 // get the cache of the first vertex
162 OptimizableGraph::Vertex*v =
163 (OptimizableGraph::Vertex*v)
164 vertices[0];
165 MyCache* c1=
166 static_cast<MyCache*>
167 (v->getCache(_cacheIds[0]));
168
169 // do things with the cache....
170
171 }
172 };
173
174
175 When inserting an edge that uses the cache in a graph, you should do the following actions *in sequence*:
176 1) set the vertices in the edge
177
178 EdgeThatUsesACache e = new EdgeThatUsesACache();
179 e->vertices[0]=v0;
180 e->vertices[1]=v1;
181 ...
182 e->vertices[n]=vn;
183
184
185 2) assign a cache ID to each vertex in the edge that has a cache that is used for that edge. *The cacheId should be unique for each type of cache, and as small as possible*.
186
187 e->setCacheId(0,first_cache_id);
188 e->setCacheId(1,second_cache_id);
189 e->setCacheId(2,third_cache_id);
190
191 3) Add the edge in the graph. This will take care of all necessary bookkeeping.
192
193 g.addEdge(e);
194
195 *meaning of the cache_id*
196 The cache id is the position of a cache in the _vertexCache vector.
197 If you have multiple edges that leave from a vertex and use the same cache id,
198 only one cache block will be allocated for that id, and it will be shared among
199 all edges.
200
201
202 CACHE VERY IMPORTANT
203 Any vertex type that uses a cache should call the updateCache() function in each method that can change the estimate.
204 These include, for instance (oplus(...), setEstimate(...)
205
206 For instance
207
208 class MyVertexThatUsesACache {
209 //
210 void oplus(double* u){
211 // do the oplus things here
212
213 updateCache(); // update the cache vector when the estimate is changes
214 }
215
216 ...
217 };