28 #include <Eigen/StdVector> 29 #include <Eigen/Geometry> 45 double errorOfSolution(
int numPoints, Eigen::Vector2d* points,
const Eigen::Vector3d& circle)
47 Eigen::Vector2d center = circle.head<2>();
48 double radius = circle(2);
50 for (
int i = 0; i < numPoints; ++i) {
51 double d = (points[i] - center).norm() - radius;
68 virtual bool read(std::istream& )
74 virtual bool write(std::ostream& )
const 87 Eigen::Vector3d::ConstMapType v(update);
102 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
106 virtual bool read(std::istream& )
111 virtual bool write(std::ostream& )
const 121 const Eigen::Vector2d& center = circle->
estimate().head<2>();
122 const double& radius = circle->
estimate()(2);
124 _error(0) = (measurement() - center).norm() - radius;
128 int main(
int argc,
char** argv)
133 std::vector<int> gaugeList;
135 arg.
param(
"numPoints", numPoints, 100,
"number of points sampled from the circle");
136 arg.
param(
"i", maxIterations, 10,
"perform n iterations");
137 arg.
param(
"v", verbose,
false,
"verbose output of the optimization process");
142 Eigen::Vector2d center(4.0, 2.0);
144 Eigen::Vector2d* points =
new Eigen::Vector2d[numPoints];
147 for (
int i = 0; i < numPoints; ++i) {
150 points[i].x() = center.x() + r * cos(angle);
151 points[i].y() = center.y() + r * sin(angle);
161 MyLinearSolver* linearSolver =
new MyLinearSolver();
162 MyBlockSolver* solver_ptr =
new MyBlockSolver(linearSolver);
171 circle->
setEstimate(Eigen::Vector3d(3.0, 3.0, 3.0));
174 for (
int i = 0; i < numPoints; ++i) {
191 cout <<
"Iterative least squares solution" << endl;
192 cout <<
"center of the circle " << circle->
estimate().head<2>().transpose() << endl;
193 cout <<
"radius of the cirlce " << circle->
estimate()(2) << endl;
207 Eigen::MatrixXd A(numPoints, 3);
208 Eigen::VectorXd b(numPoints);
209 for (
int i = 0; i < numPoints; ++i) {
210 A(i, 0) = -2*points[i].x();
211 A(i, 1) = -2*points[i].y();
213 b(i) = -pow(points[i].x(), 2) - pow(points[i].y(), 2);
215 Eigen::Vector3d solution = (A.transpose()*A).ldlt().solve(A.transpose() * b);
217 solution(2) = sqrt(pow(solution(0), 2) + pow(solution(1), 2) - solution(2));
218 cout <<
"Linear least squares solution" << endl;
219 cout <<
"center of the circle " << solution.head<2>().transpose() << endl;
220 cout <<
"radius of the cirlce " << solution(2) << endl;
221 cout <<
"error " <<
errorOfSolution(numPoints, points, solution) << endl;
virtual void oplusImpl(const double *update)
#define __PRETTY_FUNCTION__
Command line parsing of argc and argv.
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
static double gaussRand(double mean, double sigma)
Implementation of the Levenberg Algorithm.
int optimize(int iterations, bool online=false)
measurement for a point on the circle
virtual void setMeasurement(const Measurement &m)
int main(int argc, char **argv)
void setVertex(size_t i, Vertex *v)
virtual void setId(int id)
sets the id of the node in the graph be sure that the graph keeps consistent after changing the id ...
static double uniformRand(double lowerBndr, double upperBndr)
bool parseArgs(int argc, char **argv, bool exitOnError=true)
a circle located at x,y with radius r
void setVerbose(bool verbose)
linear solver which uses CSparse
void setAlgorithm(OptimizationAlgorithm *algorithm)
EIGEN_STRONG_INLINE void setInformation(const InformationType &information)
virtual bool write(std::ostream &) const
write the vertex to a stream
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex
const EstimateType & estimate() const
return the current estimate of the vertex
Implementation of a solver operating on the blocks of the Hessian.
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
double errorOfSolution(int numPoints, Eigen::Vector2d *points, const Eigen::Vector3d &circle)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgePointOnCircle()
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
virtual bool write(std::ostream &) const
write the vertex to a stream
virtual bool read(std::istream &)
read the vertex from a stream, i.e., the internal state of the vertex