73 {
74 string outputfilename;
75 string inputFilename;
77 arg.
param(
"o", outputfilename,
"",
"output final version of the graph");
79 "graph file which will be processed", true);
80
83
84
85
86 if (inputFilename.size() == 0) {
87 cerr << "No input data specified" << endl;
88 return 0;
89 } else if (inputFilename == "-") {
90 cerr << "Read input from stdin" << endl;
91 if (!inGraph.
load(cin)) {
92 cerr << "Error loading graph" << endl;
93 return 2;
94 }
95 } else {
96 cerr << "Read input from " << inputFilename << endl;
97 ifstream ifs(inputFilename.c_str());
98 if (!ifs) {
99 cerr << "Failed to open file" << endl;
100 return 1;
101 }
102 if (!inGraph.
load(ifs)) {
103 cerr << "Error loading graph" << endl;
104 return 2;
105 }
106 }
107 cerr <<
"Loaded " << inGraph.
vertices().size() <<
" vertices" << endl;
108 cerr <<
"Loaded " << inGraph.
edges().size() <<
" edges" << endl;
109
110 cerr << "filling in linfoMap and odoms" << endl;
113
114 int currentId = -1000;
115 bool firstVertexFound = false;
116 for (OptimizableGraph::VertexIDMap::iterator it = inGraph.
vertices().begin();
117 it != inGraph.
vertices().end(); ++it) {
118 currentId = currentId > it->first ? currentId : it->first;
119
121 if (pose) {
126 if (!firstVertexFound) {
127 firstVertexFound = true;
129 }
130 }
131
133 if (s) {
136 lmap.insert(make_pair(s->
id(), linfo));
137 }
138 }
139
140 currentId++;
141
142 cerr << "filling in edges and odoms" << endl;
143 for (OptimizableGraph::EdgeSet::iterator it = inGraph.
edges().begin();
144 it != inGraph.
edges().end(); ++it) {
146 if (ods) {
153 }
154
159
160 if (es || el || espl) {
164 if (!pose) continue;
166 LineInfoMap::iterator lit = lmap.find(segment->
id());
167 assert(lit != lmap.end());
172
176 if (el) {
180 }
181 if (es) {
184 Matrix2d el2info;
185 el2info << 10000, 0, 0, 1000;
189 if (!p1) {
192 p1->
setId(currentId++);
195
200 Eigen::Matrix<double, 1, 1> p1i;
201 p1i(0, 0) = 1e6;
204 }
205 if (!p2) {
208 p2->
setId(currentId++);
211
216 Eigen::Matrix<double, 1, 1> p2i;
217 p2i(0, 0) = 1e6;
220 }
221
226 Matrix2d p1i = si.block<2, 2>(0, 0);
229
234 Matrix2d p2i = si.block<2, 2>(2, 2);
237 }
238
239 if (espl) {
241 Vector2d lparams;
242 lparams[0] = espl->
theta();
244 lparams[1] = n.dot(espl->
point());
245 Matrix2d li;
246 li << si(2, 2), 0, 0, 1000;
250
252 if (!pX) {
253 cerr <<
"mkp: " << line->
id() << endl;
255 pX->
setId(currentId++);
257
258 Vector2d estPx;
262 } else {
265 }
267
272 Eigen::Matrix<double, 1, 1> pXi;
273 pXi(0, 0) = 1e6;
276 }
277
282 Matrix2d pXi = si.block<2, 2>(0, 0);
285 }
286 }
287 }
288
289 if (outputfilename.size() > 0) {
290 if (outputfilename == "-") {
291 cerr << "saving to stdout";
293 } else {
294 cerr << "saving " << outputfilename << " ... ";
295 outGraph.
save(outputfilename.c_str());
296 }
297 cerr << "done." << endl;
298 }
299
300
301
302
303
304
305 return 0;
306}
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
virtual void setMeasurement(const Measurement &m)
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
void setInformation(const InformationType &information)
const EstimateType & estimate() const
return the current estimate of the vertex
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Command line parsing of argc and argv.
bool parseArgs(int argc, char **argv, bool exitOnError=true)
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
G2O_TYPES_SLAM2D_ADDONS_API Vector2 measurementP2()
G2O_TYPES_SLAM2D_ADDONS_API Vector2 measurementP1()
2D edge between two Vertex2
virtual void setMeasurement(const SE2 &m)
const VertexContainer & vertices() const
int id() const
returns the id
const EdgeSet & edges() const
const VertexIDMap & vertices() const
virtual void setId(int id)
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
2D pose Vertex, (x,y,theta)
Vector2 estimateP1() const
Vector2 estimateP2() const
std::map< int, LineInfo > LineInfoMap
Jet< T, N > cos(const Jet< T, N > &f)
Jet< T, N > sin(const Jet< T, N > &f)
Eigen::Vector2d computeLineParameters(const Eigen::Vector2d &p1, const Eigen::Vector2d &p2)
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
virtual bool load(std::istream &is)
Vertex * vertex(int id)
returns the vertex number id appropriately casted