g2o
Public Member Functions | Public Attributes | List of all members
EdgeObservationBAL Class Reference

edge representing the observation of a world feature by a camera More...

Inheritance diagram for EdgeObservationBAL:
Inheritance graph
[legend]
Collaboration diagram for EdgeObservationBAL:
Collaboration graph
[legend]

Public Member Functions

 EdgeObservationBAL ()
 
virtual bool read (std::istream &)
 read the vertex from a stream, i.e., the internal state of the vertex More...
 
virtual bool write (std::ostream &) const
 write the vertex to a stream More...
 
template<typename T >
void cross (const T x[3], const T y[3], T result[3]) const
 
template<typename T >
dot (const T x[3], const T y[3]) const
 
template<typename T >
squaredNorm (const T x[3]) const
 
template<typename T >
bool operator() (const T *camera, const T *point, T *error) const
 
void computeError ()
 
void linearizeOplus ()
 
- Public Member Functions inherited from g2o::BaseBinaryEdge< 2, Vector2d, VertexCameraBAL, VertexPointBAL >
 BaseBinaryEdge ()
 
virtual OptimizableGraph::VertexcreateFrom ()
 
virtual OptimizableGraph::VertexcreateTo ()
 
virtual OptimizableGraph::VertexcreateVertex (int i)
 
virtual void resize (size_t size)
 
virtual bool allVerticesFixed () const
 
virtual void linearizeOplus (JacobianWorkspace &jacobianWorkspace)
 
const JacobianXiOplusTypejacobianOplusXi () const
 returns the result of the linearization in the manifold space for the node xi More...
 
const JacobianXjOplusTypejacobianOplusXj () const
 returns the result of the linearization in the manifold space for the node xj More...
 
virtual void constructQuadraticForm ()
 
virtual void mapHessianMemory (double *d, int i, int j, bool rowMajor)
 
- Public Member Functions inherited from g2o::BaseEdge< D, Vector2d >
 BaseEdge ()
 
virtual ~BaseEdge ()
 
virtual double chi2 () const
 computes the chi2 based on the cached error value, only valid after computeError has been called. More...
 
virtual const double * errorData () const
 returns the error vector cached after calling the computeError; More...
 
virtual double * errorData ()
 
const ErrorVectorerror () const
 
ErrorVectorerror ()
 
EIGEN_STRONG_INLINE const InformationTypeinformation () const
 information matrix of the constraint More...
 
EIGEN_STRONG_INLINE InformationTypeinformation ()
 
EIGEN_STRONG_INLINE void setInformation (const InformationType &information)
 
virtual const double * informationData () const
 returns the memory of the information matrix, usable for example with a Eigen::Map<MatrixXD> More...
 
virtual double * informationData ()
 
EIGEN_STRONG_INLINE const Measurementmeasurement () const
 accessor functions for the measurement represented by the edge More...
 
virtual void setMeasurement (const Measurement &m)
 
virtual int rank () const
 
virtual void initialEstimate (const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
 
- Public Member Functions inherited from g2o::OptimizableGraph::Edge
 Edge ()
 
virtual ~Edge ()
 
virtual Edgeclone () const
 
virtual bool setMeasurementData (const double *m)
 
virtual bool getMeasurementData (double *m) const
 
virtual int measurementDimension () const
 
virtual bool setMeasurementFromState ()
 
RobustKernelrobustKernel () const
 if NOT NULL, error of this edge will be robustifed with the kernel More...
 
void setRobustKernel (RobustKernel *ptr)
 
virtual double initialEstimatePossible (const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
 
int level () const
 returns the level of the edge More...
 
void setLevel (int l)
 sets the level of the edge More...
 
int dimension () const
 returns the dimensions of the error function More...
 
 G2O_ATTRIBUTE_DEPRECATED (virtual Vertex *createFrom())
 
 G2O_ATTRIBUTE_DEPRECATED (virtual Vertex *createTo())
 
long long internalId () const
 the internal ID of the edge More...
 
OptimizableGraphgraph ()
 
const OptimizableGraphgraph () const
 
bool setParameterId (int argNum, int paramId)
 
const Parameterparameter (int argNo) const
 
size_t numParameters () const
 
void resizeParameters (size_t newSize)
 
- Public Member Functions inherited from g2o::HyperGraph::Edge
 Edge (int id=InvalidId)
 creates and empty edge with no vertices More...
 
const VertexContainervertices () const
 
VertexContainervertices ()
 
const Vertexvertex (size_t i) const
 
Vertexvertex (size_t i)
 
void setVertex (size_t i, Vertex *v)
 
int id () const
 
void setId (int id)
 
virtual HyperGraphElementType elementType () const
 
int numUndefinedVertices () const
 
- Public Member Functions inherited from g2o::HyperGraph::HyperGraphElement
virtual ~HyperGraphElement ()
 
HyperGraphElementclone () const
 
- Public Member Functions inherited from g2o::HyperGraph::DataContainer
 DataContainer ()
 
virtual ~DataContainer ()
 
const DatauserData () const
 the user data associated with this vertex More...
 
DatauserData ()
 
void setUserData (Data *obs)
 
void addUserData (Data *obs)
 

Public Attributes

 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 

Additional Inherited Members

- Public Types inherited from g2o::BaseBinaryEdge< 2, Vector2d, VertexCameraBAL, VertexPointBAL >
typedef VertexCameraBAL VertexXiType
 
typedef VertexPointBAL VertexXjType
 
typedef BaseEdge< D, Vector2d >::Measurement Measurement
 
typedef Eigen::Matrix< double, D, Di, D==1?Eigen::RowMajor:Eigen::ColMajor >::AlignedMapType JacobianXiOplusType
 
typedef Eigen::Matrix< double, D, Dj, D==1?Eigen::RowMajor:Eigen::ColMajor >::AlignedMapType JacobianXjOplusType
 
typedef BaseEdge< D, Vector2d >::ErrorVector ErrorVector
 
typedef BaseEdge< D, Vector2d >::InformationType InformationType
 
typedef Eigen::Map< Eigen::Matrix< double, Di, Dj, Di==1?Eigen::RowMajor:Eigen::ColMajor >, Eigen::Matrix< double, Di, Dj, Di==1?Eigen::RowMajor:Eigen::ColMajor >::Flags &Eigen::AlignedBit?Eigen::Aligned:Eigen::Unaligned > HessianBlockType
 
typedef Eigen::Map< Eigen::Matrix< double, Dj, Di, Dj==1?Eigen::RowMajor:Eigen::ColMajor >, Eigen::Matrix< double, Dj, Di, Dj==1?Eigen::RowMajor:Eigen::ColMajor >::Flags &Eigen::AlignedBit?Eigen::Aligned:Eigen::Unaligned > HessianBlockTransposedType
 
- Public Types inherited from g2o::BaseEdge< D, Vector2d >
typedef Vector2d Measurement
 
typedef Eigen::Matrix< double, D, 1, Eigen::ColMajor > ErrorVector
 
typedef Eigen::Matrix< double, D, D, Eigen::ColMajor > InformationType
 
- Static Public Attributes inherited from g2o::BaseBinaryEdge< 2, Vector2d, VertexCameraBAL, VertexPointBAL >
static const int Di
 
static const int Dj
 
static const int Dimension
 
- Static Public Attributes inherited from g2o::BaseEdge< D, Vector2d >
static const int Dimension
 
- Protected Member Functions inherited from g2o::BaseEdge< D, Vector2d >
InformationType robustInformation (const Vector3D &rho)
 
- Protected Member Functions inherited from g2o::OptimizableGraph::Edge
template<typename ParameterType >
bool installParameter (ParameterType *&p, size_t argNo, int paramId=-1)
 
template<typename CacheType >
void resolveCache (CacheType *&cache, OptimizableGraph::Vertex *, const std::string &_type, const ParameterVector &parameters)
 
bool resolveParameters ()
 
virtual bool resolveCaches ()
 
- Protected Attributes inherited from g2o::BaseBinaryEdge< 2, Vector2d, VertexCameraBAL, VertexPointBAL >
bool _hessianRowMajor
 
HessianBlockType _hessian
 
HessianBlockTransposedType _hessianTransposed
 
JacobianXiOplusType _jacobianOplusXi
 
JacobianXjOplusType _jacobianOplusXj
 
- Protected Attributes inherited from g2o::BaseEdge< D, Vector2d >
Measurement _measurement
 
InformationType _information
 
ErrorVector _error
 
- Protected Attributes inherited from g2o::OptimizableGraph::Edge
int _dimension
 
int _level
 
RobustKernel_robustKernel
 
long long _internalId
 
std::vector< int > _cacheIds
 
std::vector< std::string > _parameterTypes
 
std::vector< Parameter ** > _parameters
 
std::vector< int > _parameterIds
 
- Protected Attributes inherited from g2o::HyperGraph::Edge
VertexContainer _vertices
 
int _id
 unique id More...
 
- Protected Attributes inherited from g2o::HyperGraph::DataContainer
Data_userData
 

Detailed Description

edge representing the observation of a world feature by a camera

see: http://grail.cs.washington.edu/projects/bal/ We use a pinhole camera model; the parameters we estimate for each camera area rotation R, a translation t, a focal length f and two radial distortion parameters k1 and k2. The formula for projecting a 3D point X into a camera R,t,f,k1,k2 is: P = R * X + t (conversion from world to camera coordinates) p = -P / P.z (perspective division) p' = f * r(p) * p (conversion to pixel coordinates) where P.z is the third (z) coordinate of P.

In the last equation, r(p) is a function that computes a scaling factor to undo the radial distortion: r(p) = 1.0 + k1 * ||p||^2 + k2 * ||p||^4.

This gives a projection in pixels, where the origin of the image is the center of the image, the positive x-axis points right, and the positive y-axis points up (in addition, in the camera coordinate system, the positive z-axis points backwards, so the camera is looking down the negative z-axis, as in OpenGL).

Definition at line 156 of file bal_example.cpp.

Constructor & Destructor Documentation

EdgeObservationBAL::EdgeObservationBAL ( )
inline

Definition at line 160 of file bal_example.cpp.

161  {
162  }

Member Function Documentation

void EdgeObservationBAL::computeError ( )
inlinevirtual

Implements g2o::OptimizableGraph::Edge.

Definition at line 246 of file bal_example.cpp.

References g2o::BaseVertex< D, T >::estimate().

247  {
248  const VertexCameraBAL* cam = static_cast<const VertexCameraBAL*>(vertex(0));
249  const VertexPointBAL* point = static_cast<const VertexPointBAL*>(vertex(1));
250 
251  (*this)(cam->estimate().data(), point->estimate().data(), _error.data());
252  }
const Vertex * vertex(size_t i) const
Definition: hyper_graph.h:186
3D world feature
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
camera vertex which stores the parameters for a pinhole camera
Definition: bal_example.cpp:65
template<typename T >
void EdgeObservationBAL::cross ( const T  x[3],
const T  y[3],
result[3] 
) const
inline

Definition at line 175 of file bal_example.cpp.

176  {
177  result[0] = x[1] * y[2] - x[2] * y[1];
178  result[1] = x[2] * y[0] - x[0] * y[2];
179  result[2] = x[0] * y[1] - x[1] * y[0];
180  }
template<typename T >
T EdgeObservationBAL::dot ( const T  x[3],
const T  y[3] 
) const
inline

Definition at line 183 of file bal_example.cpp.

183 { return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]);}
void EdgeObservationBAL::linearizeOplus ( )
inlinevirtual

Linearizes the oplus operator in the vertex, and stores the result in temporary variables _jacobianOplusXi and _jacobianOplusXj

Reimplemented from g2o::BaseBinaryEdge< 2, Vector2d, VertexCameraBAL, VertexPointBAL >.

Definition at line 254 of file bal_example.cpp.

References g2o::BaseVertex< D, T >::estimate().

255  {
256  // use numeric Jacobians
257  //BaseBinaryEdge<2, Vector2d, VertexCameraBAL, VertexPointBAL>::linearizeOplus();
258  //return;
259 
260  const VertexCameraBAL* cam = static_cast<const VertexCameraBAL*>(vertex(0));
261  const VertexPointBAL* point = static_cast<const VertexPointBAL*>(vertex(1));
262  typedef ceres::internal::AutoDiff<EdgeObservationBAL, double, VertexCameraBAL::Dimension, VertexPointBAL::Dimension> BalAutoDiff;
263 
264  Matrix<double, Dimension, VertexCameraBAL::Dimension, Eigen::RowMajor> dError_dCamera;
265  Matrix<double, Dimension, VertexPointBAL::Dimension, Eigen::RowMajor> dError_dPoint;
266  double *parameters[] = { const_cast<double*>(cam->estimate().data()), const_cast<double*>(point->estimate().data()) };
267  double *jacobians[] = { dError_dCamera.data(), dError_dPoint.data() };
268  double value[Dimension];
269  bool diffState = BalAutoDiff::Differentiate(*this, parameters, Dimension, value, jacobians);
270 
271  // copy over the Jacobians (convert row-major -> column-major)
272  if (diffState) {
273  _jacobianOplusXi = dError_dCamera;
274  _jacobianOplusXj = dError_dPoint;
275  } else {
276  assert(0 && "Error while differentiating");
277  _jacobianOplusXi.setZero();
278  _jacobianOplusXi.setZero();
279  }
280  }
const Vertex * vertex(size_t i) const
Definition: hyper_graph.h:186
3D world feature
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
camera vertex which stores the parameters for a pinhole camera
Definition: bal_example.cpp:65
template<typename T >
bool EdgeObservationBAL::operator() ( const T *  camera,
const T *  point,
T *  error 
) const
inline

templatized function to compute the error as described in the comment above

Definition at line 192 of file bal_example.cpp.

193  {
194  // Rodrigues' formula for the rotation
195  T p[3];
196  T theta = sqrt(squaredNorm(camera));
197  if (theta > T(0)) {
198  T v[3];
199  v[0] = camera[0] / theta;
200  v[1] = camera[1] / theta;
201  v[2] = camera[2] / theta;
202  T cth = cos(theta);
203  T sth = sin(theta);
204 
205  T vXp[3];
206  cross(v, point, vXp);
207  T vDotp = dot(v, point);
208  T oneMinusCth = T(1) - cth;
209 
210  for (int i = 0; i < 3; ++i)
211  p[i] = point[i] * cth + vXp[i] * sth + v[i] * vDotp * oneMinusCth;
212  } else {
213  // taylor expansion for theta close to zero
214  T aux[3];
215  cross(camera, point, aux);
216  for (int i = 0; i < 3; ++i)
217  p[i] = point[i] + aux[i];
218  }
219 
220  // translation of the camera
221  p[0] += camera[3];
222  p[1] += camera[4];
223  p[2] += camera[5];
224 
225  // perspective division
226  T projectedPoint[2];
227  projectedPoint[0] = - p[0] / p[2];
228  projectedPoint[1] = - p[1] / p[2];
229 
230  // conversion to pixel coordinates
231  T radiusSqr = projectedPoint[0]*projectedPoint[0] + projectedPoint[1]*projectedPoint[1];
232  T f = T(camera[6]);
233  T k1 = T(camera[7]);
234  T k2 = T(camera[8]);
235  T r_p = T(1) + k1 * radiusSqr + k2 * radiusSqr * radiusSqr;
236  T prediction[2];
237  prediction[0] = f * r_p * projectedPoint[0];
238  prediction[1] = f * r_p * projectedPoint[1];
239 
240  error[0] = prediction[0] - T(measurement()(0));
241  error[1] = prediction[1] - T(measurement()(1));
242 
243  return true;
244  }
void cross(const T x[3], const T y[3], T result[3]) const
const ErrorVector & error() const
Definition: base_edge.h:63
T dot(const T x[3], const T y[3]) const
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
T squaredNorm(const T x[3]) const
virtual bool EdgeObservationBAL::read ( std::istream &  is)
inlinevirtual

read the vertex from a stream, i.e., the internal state of the vertex

Implements g2o::OptimizableGraph::Edge.

Definition at line 163 of file bal_example.cpp.

References __PRETTY_FUNCTION__.

164  {
165  cerr << __PRETTY_FUNCTION__ << " not implemented yet" << endl;
166  return false;
167  }
#define __PRETTY_FUNCTION__
Definition: macros.h:89
template<typename T >
T EdgeObservationBAL::squaredNorm ( const T  x[3]) const
inline

Definition at line 186 of file bal_example.cpp.

186 { return dot<T>(x, x);}
virtual bool EdgeObservationBAL::write ( std::ostream &  os) const
inlinevirtual

write the vertex to a stream

Implements g2o::OptimizableGraph::Edge.

Definition at line 168 of file bal_example.cpp.

References __PRETTY_FUNCTION__.

169  {
170  cerr << __PRETTY_FUNCTION__ << " not implemented yet" << endl;
171  return false;
172  }
#define __PRETTY_FUNCTION__
Definition: macros.h:89

Member Data Documentation

EdgeObservationBAL::EIGEN_MAKE_ALIGNED_OPERATOR_NEW

Definition at line 159 of file bal_example.cpp.


The documentation for this class was generated from the following file: