Program Listing for File distortion.h

Return to documentation for file (aslam_cv2/aslam_cv_cameras/include/aslam/cameras/distortion.h)

#ifndef ASLAM_CAMERAS_DISTORTION_H_
#define ASLAM_CAMERAS_DISTORTION_H_

#include <aslam/common/macros.h>
#include <Eigen/Dense>
#include <gflags/gflags.h>

DECLARE_double(acv_inv_distortion_tolerance);

namespace aslam {

class Distortion {
 public:
  ASLAM_POINTER_TYPEDEFS(Distortion);
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW

  enum { CLASS_SERIALIZATION_VERSION = 1 };

  enum class Type {
    kNoDistortion = 0,
    kEquidistant = 1,
    kFisheye = 2,
    kRadTan = 3
  };


 protected:
  Distortion() = delete;

  Distortion(const Eigen::VectorXd& dist_coeffs,
             Type distortion_type);

 public:
  virtual ~Distortion() { };

  virtual bool operator==(const Distortion& rhs) const;

  friend std::ostream& operator<<(std::ostream& out, const Distortion& distortion);

 protected:
  Distortion(const Distortion&) = default;
  void operator=(const Distortion&) = delete;

 public:
  virtual aslam::Distortion* clone() const = 0;



  void distort(Eigen::Vector2d* point) const;

  void distort(const Eigen::Vector2d& point, Eigen::Vector2d* out_point) const;

  void distort(Eigen::Vector2d* point,
               Eigen::Matrix2d* out_jacobian) const;

  virtual void distortUsingExternalCoefficients(const Eigen::VectorXd* dist_coeffs,
                                                Eigen::Vector2d* point,
                                                Eigen::Matrix2d* out_jacobian) const = 0;

  virtual void distortParameterJacobian(const Eigen::VectorXd* dist_coeffs,
                                 const Eigen::Vector2d& point,
                                 Eigen::Matrix<double, 2, Eigen::Dynamic>* out_jacobian) const = 0;



  void undistort(Eigen::Vector2d* point) const;

  void undistort(const Eigen::Vector2d& point, Eigen::Vector2d* out_point) const;


  virtual void undistortUsingExternalCoefficients(const Eigen::VectorXd& dist_coeffs,
                                                  Eigen::Vector2d* point) const = 0;



  void setParameters(const Eigen::VectorXd& dist_coeffs);

  inline const Eigen::VectorXd& getParameters() const { return distortion_coefficients_; };

  inline double* getParametersMutable() { return &distortion_coefficients_.coeffRef(0, 0); };

  virtual int getParameterSize() const = 0;

  virtual bool distortionParametersValid(const Eigen::VectorXd& dist_coeffs) const = 0;

  virtual void printParameters(std::ostream& out, const std::string& text) const = 0;

  inline Type getType() const { return distortion_type_; }


 protected:
  Eigen::VectorXd distortion_coefficients_;

  Type distortion_type_;
};
}  // namespace aslam
#include "distortion-inl.h"
#endif  // ASLAM_CAMERAS_DISTORTION_H_