88int main(
int argc,
char** argv) {
92 int updateGraphEachN = 10;
96 arg.
param(
"update", updateGraphEachN, 10,
97 "updates after x odometry nodes, (default: 10)");
98 arg.
param(
"listTypes", listTypes,
false,
"list the registered types");
99 arg.
param(
"renameTypes", loadLookup,
"",
100 "create a lookup for loading types into other types,\n\t "
101 "TAG_IN_FILE=INTERNAL_TAG_FOR_TYPE,TAG2=INTERNAL2\n\t e.g., "
102 "VERTEX_CAM=VERTEX_SE3:EXPMAP");
104 "graph file which will be processed",
true);
115 if (loadLookup.size() > 0) {
118 if (inputFilename.size() == 0) {
119 cerr <<
"No input data specified" << endl;
121 }
else if (inputFilename ==
"-") {
122 cerr <<
"Read input from stdin" << endl;
123 if (!optimizer.
load(cin)) {
124 cerr <<
"Error loading graph" << endl;
128 cerr <<
"Read input from " << inputFilename << endl;
129 ifstream ifs(inputFilename.c_str());
131 cerr <<
"Failed to open file" << endl;
134 if (!optimizer.
load(ifs)) {
135 cerr <<
"Error loading graph" << endl;
139 cerr <<
"Loaded " << optimizer.
vertices().size() <<
" vertices" << endl;
140 cerr <<
"Loaded " << optimizer.
edges().size() <<
" edges" << endl;
142 if (optimizer.
vertices().size() == 0) {
143 cerr <<
"Graph contains no vertices" << endl;
150 cerr <<
"# incremental settings" << endl;
151 cerr <<
"#\t solve every " << updateGraphEachN << endl;
154 for (SparseOptimizer::VertexIDMap::const_iterator it = vertices.begin();
155 it != vertices.end(); ++it) {
158 maxDim = (max)(maxDim, v->dimension());
161 vector<SparseOptimizer::Edge*> edges;
162 for (SparseOptimizer::EdgeSet::iterator it = optimizer.
edges().begin();
163 it != optimizer.
edges().end(); ++it) {
167 optimizer.
edges().clear();
175 int lastOptimizedVertexCount = 0;
176 bool addNextEdge =
true;
177 bool freshlyOptimized =
false;
180 for (vector<SparseOptimizer::Edge*>::iterator it = edges.begin();
181 it != edges.end(); ++it) {
183 bool optimize =
false;
185 if (addNextEdge && !optimizer.
vertices().empty()) {
187 if (maxInGraph < idMax && !freshlyOptimized) {
198 if (!v1 && addNextEdge) {
203 maxInGraph = (max)(maxInGraph, v->
id());
207 cerr <<
"Error adding vertex " << v->
id() << endl;
209 verticesAdded.insert(v);
210 if (v->dimension() == maxDim) vertexCount++;
212 if (v->dimension() == 3) {
213 cout <<
"ADD VERTEX_XYT " << v->
id() <<
";" << endl;
214 }
else if (v->dimension() == 6) {
215 cout <<
"ADD VERTEX_XYZRPY " << v->
id() <<
";" << endl;
219 if (!v2 && addNextEdge) {
224 maxInGraph = (max)(maxInGraph, v->
id());
228 cerr <<
"Error adding vertex " << v->
id() << endl;
230 verticesAdded.insert(v);
231 if (v->dimension() == maxDim) vertexCount++;
233 if (v->dimension() == 3) {
234 cout <<
"ADD VERTEX_XYT " << v->
id() <<
";" << endl;
235 }
else if (v->dimension() == 6) {
236 cout <<
"ADD VERTEX_XYZRPY " << v->
id() <<
";" << endl;
241 if (e->dimension() == 3) {
242 static int edgeCnt = 0;
243 double* information = e->informationData();
245 e->getMeasurementData(meas);
247 cout <<
"ADD EDGE_XYT " << edgeCnt++ <<
" " << e->
vertices()[0]->id()
248 <<
" " << e->
vertices()[1]->id() <<
" " << meas[0] <<
" "
249 << meas[1] <<
" " << meas[2];
250 for (
int i = 0; i < 3; ++i)
251 for (
int j = i; j < 3; ++j) cout <<
" " << information[i * 3 + j];
253 }
else if (e->dimension() == 6) {
255 cerr <<
"NOT IMPLEMENTED YET" << endl;
257 static bool firstEdge =
true;
260 cout <<
"FIX 0;" << endl;
266 cerr <<
"Unable to add edge " << e->
vertices()[0]->id() <<
" -> "
271 freshlyOptimized =
false;
274 if (vertexCount - lastOptimizedVertexCount >= updateGraphEachN) {
275 cout <<
"SOLVE_STATE;" << endl;
276 cout <<
"QUERY_STATE;" << endl;
277 lastOptimizedVertexCount = vertexCount;
281 freshlyOptimized =
true;