本文整理汇总了C++中optimizablegraph::Vertex::setFixed方法的典型用法代码示例。如果您正苦于以下问题:C++ Vertex::setFixed方法的具体用法?C++ Vertex::setFixed怎么用?C++ Vertex::setFixed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optimizablegraph::Vertex
的用法示例。
在下文中一共展示了Vertex::setFixed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setFixed
void OptimizableGraph::setFixed(HyperGraph::VertexSet& vset, bool fixed)
{
for (HyperGraph::VertexSet::iterator it=vset.begin(); it!=vset.end(); ++it) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
v->setFixed(fixed);
}
}
示例2:
bool G2oSlamInterface::fixNode(const std::vector<int>& nodes)
{
for (size_t i = 0; i < nodes.size(); ++i) {
OptimizableGraph::Vertex* v = _optimizer->vertex(nodes[i]);
if (v)
v->setFixed(true);
}
return true;
}
示例3: load
bool OptimizableGraph::load(istream& is, bool createEdges)
{
// scna for the paramers in the whole file
if (!_parameters.read(is,&_renamedTypesLookup))
return false;
#ifndef NDEBUG
cerr << "Loaded " << _parameters.size() << " parameters" << endl;
#endif
is.clear();
is.seekg(ios_base::beg);
set<string> warnedUnknownTypes;
stringstream currentLine;
string token;
Factory* factory = Factory::instance();
HyperGraph::GraphElemBitset elemBitset;
elemBitset[HyperGraph::HGET_PARAMETER] = 1;
elemBitset.flip();
Vertex* previousVertex = 0;
Data* previousData = 0;
while (1) {
int bytesRead = readLine(is, currentLine);
if (bytesRead == -1)
break;
currentLine >> token;
//cerr << "Token=" << token << endl;
if (bytesRead == 0 || token.size() == 0 || token[0] == '#')
continue;
// handle commands encoded in the file
bool handledCommand = false;
if (token == "FIX") {
handledCommand = true;
int id;
while (currentLine >> id) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(vertex(id));
if (v) {
# ifndef NDEBUG
cerr << "Fixing vertex " << v->id() << endl;
# endif
v->setFixed(true);
} else {
cerr << "Warning: Unable to fix vertex with id " << id << ". Not found in the graph." << endl;
}
}
}
if (handledCommand)
continue;
// do the mapping to an internal type if it matches
if (_renamedTypesLookup.size() > 0) {
map<string, string>::const_iterator foundIt = _renamedTypesLookup.find(token);
if (foundIt != _renamedTypesLookup.end()) {
token = foundIt->second;
}
}
if (! factory->knowsTag(token)) {
if (warnedUnknownTypes.count(token) != 1) {
warnedUnknownTypes.insert(token);
cerr << CL_RED(__PRETTY_FUNCTION__ << " unknown type: " << token) << endl;
}
continue;
}
HyperGraph::HyperGraphElement* element = factory->construct(token, elemBitset);
if (dynamic_cast<Vertex*>(element)) { // it's a vertex type
//cerr << "it is a vertex" << endl;
previousData = 0;
Vertex* v = static_cast<Vertex*>(element);
int id;
currentLine >> id;
bool r = v->read(currentLine);
if (! r)
cerr << __PRETTY_FUNCTION__ << ": Error reading vertex " << token << " " << id << endl;
v->setId(id);
if (!addVertex(v)) {
cerr << __PRETTY_FUNCTION__ << ": Failure adding Vertex, " << token << " " << id << endl;
delete v;
} else {
previousVertex = v;
}
}
示例4: main
int main(int argc, char** argv)
{
bool fixLaser;
int maxIterations;
bool verbose;
string inputFilename;
string outputfilename;
string rawFilename;
string odomTestFilename;
string dumpGraphFilename;
// command line parsing
CommandArgs commandLineArguments;
commandLineArguments.param("i", maxIterations, 10, "perform n iterations");
commandLineArguments.param("v", verbose, false, "verbose output of the optimization process");
commandLineArguments.param("o", outputfilename, "", "output final version of the graph");
commandLineArguments.param("test", odomTestFilename, "", "apply odometry calibration to some test data");
commandLineArguments.param("dump", dumpGraphFilename, "", "write the graph to the disk");
commandLineArguments.param("fixLaser", fixLaser, false, "keep the laser offset fixed during optimization");
commandLineArguments.paramLeftOver("gm2dl-input", inputFilename, "", "gm2dl file which will be processed");
commandLineArguments.paramLeftOver("raw-log", rawFilename, "", "raw log file containing the odometry");
commandLineArguments.parseArgs(argc, argv);
SparseOptimizer optimizer;
optimizer.setVerbose(verbose);
optimizer.setForceStopFlag(&hasToStop);
allocateSolverForSclam(optimizer);
// loading
if (! Gm2dlIO::readGm2dl(inputFilename, optimizer, false)) {
cerr << "Error while loading gm2dl file" << endl;
}
DataQueue robotLaserQueue;
int numLaserOdom = Gm2dlIO::readRobotLaser(rawFilename, robotLaserQueue);
if (numLaserOdom == 0) {
cerr << "No raw information read" << endl;
return 0;
}
cerr << "Read " << numLaserOdom << " laser readings from file" << endl;
bool gaugeFreedom = optimizer.gaugeFreedom();
OptimizableGraph::Vertex* gauge = optimizer.findGauge();
if (gaugeFreedom) {
if (! gauge) {
cerr << "# cannot find a vertex to fix in this thing" << endl;
return 2;
} else {
cerr << "# graph is fixed by node " << gauge->id() << endl;
gauge->setFixed(true);
}
} else {
cerr << "# graph is fixed by priors" << endl;
}
addOdometryCalibLinksDifferential(optimizer, robotLaserQueue);
// sanity check
HyperDijkstra d(&optimizer);
UniformCostFunction f;
d.shortestPaths(gauge, &f);
//cerr << PVAR(d.visited().size()) << endl;
if (d.visited().size()!=optimizer.vertices().size()) {
cerr << CL_RED("Warning: d.visited().size() != optimizer.vertices().size()") << endl;
cerr << "visited: " << d.visited().size() << endl;
cerr << "vertices: " << optimizer.vertices().size() << endl;
if (1)
for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer.vertices().begin(); it != optimizer.vertices().end(); ++it) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(it->second);
if (d.visited().count(v) == 0) {
cerr << "\t unvisited vertex " << it->first << " " << (void*)v << endl;
v->setFixed(true);
}
}
}
for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer.vertices().begin(); it != optimizer.vertices().end(); ++it) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(it->second);
if (v->fixed()) {
cerr << "\t fixed vertex " << it->first << endl;
}
}
VertexSE2* laserOffset = dynamic_cast<VertexSE2*>(optimizer.vertex(Gm2dlIO::ID_LASERPOSE));
VertexOdomDifferentialParams* odomParamsVertex = dynamic_cast<VertexOdomDifferentialParams*>(optimizer.vertex(Gm2dlIO::ID_ODOMCALIB));
if (fixLaser) {
cerr << "Fix position of the laser offset" << endl;
laserOffset->setFixed(true);
}
signal(SIGINT, sigquit_handler);
cerr << "Doing full estimation" << endl;
optimizer.initializeOptimization();
optimizer.computeActiveErrors();
cerr << "Initial chi2 = " << FIXED(optimizer.chi2()) << endl;
int i=optimizer.optimize(maxIterations);
//.........这里部分代码省略.........
示例5: main
int main (int argc , char ** argv){
int maxIterations;
bool verbose;
bool robustKernel;
double lambdaInit;
CommandArgs arg;
bool fixSensor;
bool fixPlanes;
bool fixFirstPose;
bool fixTrajectory;
bool planarMotion;
bool listSolvers;
string strSolver;
cerr << "graph" << endl;
arg.param("i", maxIterations, 5, "perform n iterations");
arg.param("v", verbose, false, "verbose output of the optimization process");
arg.param("solver", strSolver, "lm_var", "select one specific solver");
arg.param("lambdaInit", lambdaInit, 0, "user specified lambda init for levenberg");
arg.param("robustKernel", robustKernel, false, "use robust error functions");
arg.param("fixSensor", fixSensor, false, "fix the sensor position on the robot");
arg.param("fixTrajectory", fixTrajectory, false, "fix the trajectory");
arg.param("fixFirstPose", fixFirstPose, false, "fix the first robot pose");
arg.param("fixPlanes", fixPlanes, false, "fix the planes (do localization only)");
arg.param("planarMotion", planarMotion, false, "robot moves on a plane");
arg.param("listSolvers", listSolvers, false, "list the solvers");
arg.parseArgs(argc, argv);
SparseOptimizer* g=new SparseOptimizer();
ParameterSE3Offset* odomOffset=new ParameterSE3Offset();
odomOffset->setId(0);
g->addParameter(odomOffset);
OptimizationAlgorithmFactory* solverFactory = OptimizationAlgorithmFactory::instance();
OptimizationAlgorithmProperty solverProperty;
OptimizationAlgorithm* solver = solverFactory->construct(strSolver, solverProperty);
g->setAlgorithm(solver);
if (listSolvers){
solverFactory->listSolvers(cerr);
return 0;
}
if (! g->solver()){
cerr << "Error allocating solver. Allocating \"" << strSolver << "\" failed!" << endl;
cerr << "available solvers: " << endl;
solverFactory->listSolvers(cerr);
cerr << "--------------" << endl;
return 0;
}
cerr << "sim" << endl;
Simulator* sim = new Simulator(g);
cerr << "robot" << endl;
Robot* r=new Robot(g);
cerr << "planeSensor" << endl;
Matrix3d R=Matrix3d::Identity();
R <<
0, 0, 1,
-1, 0, 0,
0, -1, 0;
Isometry3d sensorPose=Isometry3d::Identity();
sensorPose.matrix().block<3,3>(0,0) = R;
sensorPose.translation()= Vector3d(.3 , 0.5 , 1.2);
PlaneSensor* ps = new PlaneSensor(r, 0, sensorPose);
ps->_nplane << 0.03, 0.03, 0.005;
r->_sensors.push_back(ps);
sim->_robots.push_back(r);
cerr << "p1" << endl;
Plane3D plane;
PlaneItem* pi =new PlaneItem(g,1);
plane.fromVector(Eigen::Vector4d(0.,0.,1.,5.));
static_cast<VertexPlane*>(pi->vertex())->setEstimate(plane);
pi->vertex()->setFixed(fixPlanes);
sim->_world.insert(pi);
plane.fromVector(Eigen::Vector4d(1.,0.,0.,5.));
pi =new PlaneItem(g,2);
static_cast<VertexPlane*>(pi->vertex())->setEstimate(plane);
pi->vertex()->setFixed(fixPlanes);
sim->_world.insert(pi);
cerr << "p2" << endl;
pi =new PlaneItem(g,3);
plane.fromVector(Eigen::Vector4d(0.,1.,0.,5.));
static_cast<VertexPlane*>(pi->vertex())->setEstimate(plane);
pi->vertex()->setFixed(fixPlanes);
sim->_world.insert(pi);
Quaterniond q, iq;
if (planarMotion) {
r->_planarMotion = true;
r->_nmovecov << 0.01, 0.0025, 1e-9, 0.001, 0.001, 0.025;
q = Quaterniond(AngleAxisd(0.2, Vector3d::UnitZ()).toRotationMatrix());
//.........这里部分代码省略.........