Go to the documentation of this file.
42 #ifndef EIGEN_USE_NEW_STDVECTOR
43 #define EIGEN_USE_NEW_STDVECTOR
44 #endif // EIGEN_USE_NEW_STDVECTOR
49 #include <Eigen/Geometry>
51 #include <Eigen/StdVector>
54 #include <Eigen/Cholesky>
66 #define SBA_DENSE_CHOLESKY 0
67 #define SBA_SPARSE_CHOLESKY 1
68 #define SBA_GRADIENT 2
69 #define SBA_BLOCK_JACOBIAN_PCG 3
78 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
89 std::vector<Node, Eigen::aligned_allocator<Node> >
nodes;
95 std::vector<Track, Eigen::aligned_allocator<Track> >
tracks;
158 int doSBA(
int niter,
double lambda = 1.0e-4,
int useCSparse = 0,
double initTol = 1.0e-8,
159 int maxCGiters = 100);
171 int addNode(Eigen::Matrix<double,4,1> &trans,
172 Eigen::Quaternion<double> &qrot,
174 bool isFixed =
false);
192 bool addProj(
int ci,
int pi, Eigen::Vector3d &q,
bool stereo=
true);
203 bool addMonoProj(
int ci,
int pi, Eigen::Vector2d &q);
234 void addPointPlaneMatch(
int ci0,
int pi0, Eigen::Vector3d normal0,
int ci1,
int pi1, Eigen::Vector3d normal1);
260 void mergeTracks(std::vector<std::pair<int,int> > &prs);
279 void tsplit(
int tri,
int len);
282 std::vector<Point, Eigen::aligned_allocator<Point> >
oldpoints;
285 std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> >
tps;
288 std::vector<JacobProds, Eigen::aligned_allocator<JacobProds> >
jps;
300 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
311 Eigen::Matrix<double,6,6>
prec;
315 Eigen::Matrix<double,6,1>
err;
339 void setJacobians(std::vector<
Node,Eigen::aligned_allocator<Node> > &nodes);
352 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
383 void setJacobians(std::vector<
Node,Eigen::aligned_allocator<Node> > &nodes);
397 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
406 Eigen::Matrix<double,12,1>
mean;
407 Eigen::Matrix<double,12,12>
prec;
410 Eigen::Matrix<double,12,1>
err;
429 Eigen::Matrix<double,3,6>
Hpc;
430 Eigen::Matrix<double,6,3>
Tpc;
443 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
457 int addNode(Eigen::Matrix<double,4,1> &trans,
458 Eigen::Quaternion<double> &qrot,
459 bool isFixed =
false);
469 Eigen::Vector3d &tmean,
470 Eigen::Quaterniond &qpmean,
471 Eigen::Matrix<double,6,6> &prec);
474 std::vector<Node,Eigen::aligned_allocator<Node> >
nodes;
483 std::vector<ConP2,Eigen::aligned_allocator<ConP2> >
p2cons;
486 std::vector<ConScale,Eigen::aligned_allocator<ConScale> >
scons;
493 double calcCost(
bool tcost =
false);
500 void writeSparseA(
char *fname,
bool useCSparse =
false);
512 double initTol = 1.0e-8,
int CGiters = 50);
522 void addConstraint(
int pr,
int p0,
int p1, Eigen::Matrix<double,12,1> &mean, Eigen::Matrix<double,12,12> &prec);
std::vector< Track, Eigen::aligned_allocator< Track > > tracks
Set of tracks for each point P (projections onto camera frames).
int addNode(Eigen::Matrix< double, 4, 1 > &trans, Eigen::Quaternion< double > &qrot, const fc::CamParams &cp, bool isFixed=false)
Adds a node to the system.
double calcCost()
Calculate the total cost of the system by adding the squared error over all projections.
Eigen::Matrix< double, 6, 6 > J1t
int sv
Scale variable index.
bool addProj(int ci, int pi, Eigen::Vector3d &q, bool stereo=true)
Add a projection between point and camera, in setting up the system.
vector< map< int, int > > generateConns_()
Eigen::Matrix< double, 6, 6 > J22
int remExcessTracks(int minpts)
removes tracks that aren't needed
void addPointPlaneMatch(int ci0, int pi0, Eigen::Vector3d normal0, int ci1, int pi1, Eigen::Vector3d normal1)
Adds a pair of point-plane projection matches. Assumes the points have already been added to the syst...
double calcErr(const Node &nd0, const Node &nd1)
calculates projection error and stores it in <err>
int doSPA(int niter, double sLambda=1.0e-4, int useCSparse=SBA_SPARSE_CHOLESKY, double initTol=1.0e-8, int CGiters=50)
SysSBA holds a set of nodes and points for sparse bundle adjustment.
CSparse csp
sparse matrix object
std::vector< Point, Eigen::aligned_allocator< Point > > oldpoints
Storage for old points, for checking LM step and reverting.
double huber
Huber parameter; greater than 0.0 for Huber weighting of cost.
int addPoint(Point p)
Adds a point to the system.
bool addConstraint(int nd0, int nd1, Eigen::Vector3d &tmean, Eigen::Quaterniond &qpmean, Eigen::Matrix< double, 6, 6 > &prec)
Adds a pose constraint to the system.
double sqMinDelta
Convergence bound (square of minimum acceptable delta change)
void mergeTracks(std::vector< std::pair< int, int > > &prs)
merge tracks based on identity pairs
Eigen::Vector4d Point
Point holds 3D points using in world coordinates. Currently we just represent these as 4-vectors,...
int nd1
Node index for the second node.
void spanningTree(int node=0)
Spanning tree initialization.
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > tps
variables for each track
std::vector< JacobProds, Eigen::aligned_allocator< JacobProds > > jps
storage for Jacobian products
SysSPA holds a set of nodes and constraints for sparse pose adjustment.
bool useLocalAngles
local or global angle coordinates
double calcErr(const Node &nd0, const Node &nd1, double alpha)
calculates projection error and stores it in <err>
Eigen::Matrix< double, 12, 12 > prec
int addNode(Eigen::Matrix< double, 4, 1 > &trans, Eigen::Quaternion< double > &qrot, bool isFixed=false)
Adds a node to the system.
Eigen::Matrix< double, 6, 6 > J1
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int ndr
Reference pose index.
Eigen::MatrixXd A
linear system matrix and vector
static void initDr()
Sets up constant matrices for derivatives.
Eigen::Matrix< double, 6, 6 > J11
Eigen::Quaternion< double > qpmean
void setConnMatReduced(int maxconns)
sets up connectivity matrix by greedy spanning tree
int removeBad(double dist)
Remove projections with too high of an error.
void setupSparseSys(double sLambda, int iter, int sparseType)
static constexpr double qScale
bool readP2File(char *fname, SysSPA spa)
constraint files
int countBad(double dist)
Find number of projections with errors over a certain value.
void setupSys(double sLambda)
Eigen::Matrix< double, 6, 6 > J10
Jacobians of 0p1,0p2 with respect to global p0, p1, p2.
Eigen::Matrix< double, 6, 6 > J0
jacobian with respect to frames; uses dR'/dq from Node calculation
void tsplit(int tri, int len)
Split a track into random tracks. (What is len?)
void setupSparseSys(double sLambda, int iter, int sparseType)
bool isValid
valid or not (could be out of bounds)
void setJacobians(std::vector< Node, Eigen::aligned_allocator< Node > > &nodes)
jacobians are computed from (ti - tj)^2 - a*kij = 0
Eigen::Matrix< double, 12, 1 > err
error
Eigen::Matrix< double, 12, 1 > mean
Mean vector and precision matrix for this constraint.
int reduceLongTracks(double pct)
get rid of long tracks
std::vector< Node, Eigen::aligned_allocator< Node > > nodes
Set of nodes (camera frames) for SBA system, indexed by node number.
int nd1
Node index for the second node.
#define SBA_SPARSE_CHOLESKY
int mergeTracksSt(int tr0, int tr1)
merge two tracks if possible (no conflicts)
int nd1
Node indices, the constraint for this object.
double sqMinDelta
Convergence bound (square of minimum acceptable delta change)
int reduceTracks()
Reduce tracks by eliminating single tracks and invalid projections.
bool isValid
valid or not (could be out of bounds)
double calcAvgError()
Calculates average cost of the system.
std::vector< ConP2, Eigen::aligned_allocator< ConP2 > > p2cons
Set of P2 constraints.
std::vector< std::vector< bool > > connMat
int numBadPoints()
Find number of points with Z < 0 (projected behind the camera).
Eigen::Matrix< double, 6, 6 > J20
double calcCost(bool tcost=false)
void setProjCovariance(int ci, int pi, Eigen::Matrix3d &covar)
Sets the covariance matrix of a projection.
void useCholmod(bool yes)
use CHOLMOD or CSparse
void setJacobians(std::vector< Node, Eigen::aligned_allocator< Node > > &nodes)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int ndr
Reference pose index.
int nFixed
Number of fixed nodes.
bool useLocalAngles
local or global angle coordinates
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SysSPA()
constructor
void printStats()
Print some system stats.
Eigen::Matrix< double, 6, 6 > prec
std::vector< double > scales
set of scale for SPA system, indexed by position;
Eigen::Matrix< double, 4, 1 > oldqrot
double calcErrDist(const Node &nd0, const Node &nd1)
calculate error in distance only, no weighting
Eigen::Matrix< double, 12, 1 > calcErr(const Node &nd, const Point &pt)
calculates projection error and stores it in <err>
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int verbose
How much information to print to console.
Eigen::Vector3d tmean
Mean vector, quaternion (inverse) and precision matrix for this constraint.
Eigen::Matrix< double, 6, 3 > Tpc
bool addMonoProj(int ci, int pi, Eigen::Vector2d &q)
Add a projection between point and camera, in setting up the system.
void printStats()
print some system stats
void setupSys(double sLambda)
Eigen::Matrix< double, 3, 6 > Hpc
temp storage for Hpc, Tpc matrices in SBA
Eigen::Matrix< double, 6, 6 > J0t
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int nd0
Reference pose index.
int nFixed
Number of fixed nodes (nodes with known poses) from the first node.
NODE holds graph nodes corresponding to frames, for use in sparse bundle adjustment....
Eigen::Matrix< double, 6, 1 > err
error
void setJacobians(std::vector< Node, Eigen::aligned_allocator< Node > > nodes)
std::vector< ConScale, Eigen::aligned_allocator< ConScale > > scons
Set of scale constraints.
void writeSparseA(char *fname, bool useCSparse=false)
void updateNormals()
Update normals in point-plane matches, if any.
Eigen::Matrix< double, 4, 1 > oldtrans
SysSBA()
Default constructor.
double w
Weight for this constraint.
std::vector< Node, Eigen::aligned_allocator< Node > > nodes
set of nodes (camera frames) for SPA system, indexed by position;
double calcRMSCost(double dist=10000.0)
Calculates total RMS cost of the system, not counting projections with errors higher than <dist>.
void setConnMat(int minpts)
int doSBA(int niter, double lambda=1.0e-4, int useCSparse=0, double initTol=1.0e-8, int maxCGiters=100)
double ks
Scale factor for this constraint.
Eigen::MatrixXd A
linear system matrix and vector
bool addStereoProj(int ci, int pi, Eigen::Vector3d &q)
Add a projection between point and camera, in setting up the system.
int countProjs()
Return total number of projections.
bool isValid
valid or not (could be out of bounds)