MTF
Spline.h
1 #ifndef MTF_SPLINE_H
2 #define MTF_SPLINE_H
3 
4 #include "StateSpaceModel.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
9 
10  enum class InterpolationType {
11  Bilinear, Biquadratic, Bicubic
12  };
13  static const char* toString(InterpolationType data_type);
14 
15  // resolution of spline control patch, i.e. each spline control point
16  // influences control_size_x*control_size_y pixels around it;
17  int control_size_x, control_size_y;
18  // overlap in pixels between the influence regions of neighboring spline control points;
19  double control_overlap;
20  // interpolation method to compute the displacements of individual pixels
21  // based on those of the spline control points;
22  InterpolationType interp_type;
23  bool static_wts;
24  bool debug_mode;
25 
26  SplineParams(const SSMParams *ssm_params,
27  int _control_size_x, int _control_size_y,
28  double _control_overlap,
29  InterpolationType _interp_type,
30  bool _static_wts, bool _debug_mode);
31  SplineParams(const SplineParams *params = nullptr);
32 };
33 
34 class Spline : public StateSpaceModel{
35 
36 public:
37 
38  typedef SplineParams ParamType;
39  typedef SplineParams::InterpolationType InterpolationType;
40 
41  Spline( const ParamType *params_in = nullptr);
42 
43  void getCorners(cv::Mat &cv_corners) override;
44  using StateSpaceModel::getCorners;
45 
46  void additiveUpdate(const VectorXd& state_update) override{
47  compositionalUpdate(state_update);
48  }
49  void setCorners(const CornersT& corners) override;
50  using StateSpaceModel::setCorners;
51 
52  void compositionalUpdate(const VectorXd& state_update) override;
53  void setState(const VectorXd& state) override;
54 
55  void cmptInitPixJacobian(MatrixXd &jacobian_prod, const PixGradT &am_jacobian) override;
56  void cmptPixJacobian(MatrixXd &jacobian_prod, const PixGradT &am_jacobian) override;
57  void cmptWarpedPixJacobian(MatrixXd &jacobian_prod,
58  const PixGradT &pix_jacobian) override;
59 
60  void cmptApproxPixJacobian(MatrixXd &jacobian_prod,
61  const PixGradT &pix_jacobian) override;
62 
63  void cmptInitPixHessian(MatrixXd &pix_hess_ssm, const PixHessT &pix_hess_coord,
64  const PixGradT &pix_grad) override;
65 
66  void cmptWarpedPixHessian(MatrixXd &pix_hess_ssm, const PixHessT &pix_hess_coord,
67  const PixGradT &pix_grad) override;
68  void cmptApproxPixHessian(MatrixXd &pix_hess_ssm, const PixHessT &pix_hess_coord,
69  const PixGradT &pix_grad) override;
70  void cmptPixHessian(MatrixXd &pix_hess_ssm, const PixHessT &pix_hess_coord,
71  const PixGradT &pix_grad) override;
72 
73  void invertState(VectorXd& inv_state, const VectorXd& state) override;
74 
75  void updateGradPts(double grad_eps) override;
76  void updateHessPts(double hess_eps) override;
77 
78  bool supportsSPI() override{ return true; }
79 
80  void getInitPixGrad(Matrix2Xd &jacobian_prod, int pix_id) override;
81  void getCurrPixGrad(Matrix2Xd &jacobian_prod, int pix_id) override;
82 
83  void generatePerturbation(VectorXd &state_update) override;
84 
85 protected:
86  ParamType params;
87 
88  PtsT norm_pts;
89  CornersT norm_corners;
90  PtsT init_control_pts, curr_control_pts;
91  VectorXd ctrl_idx, ctrl_idy;
92  // resolution of spline control point grid
93  unsigned int control_res_x, control_res_y;
94  unsigned int n_control_pts;
97  VectorXd dist_norm_x, dist_norm_y;
98  MatrixXd norm_dist_x, norm_dist_y, interp_wts;
99  Matrix2Xd ssm_grad;
100  double max_dist_x, max_dist_y;
101  void initInterpolationWeights();
102  void updateInterpolationWeights();
103  double getWeight(double x, double y);
104  CornersT rand_d;
105  Vector2d rand_t;
106  CornersT disturbed_corners;
107 };
108 
109 _MTF_END_NAMESPACE
110 
111 #endif
Definition: Spline.h:34
Definition: StateSpaceModel.h:35
int n_bounding_pts
no. of pts that lie on the region boundary
Definition: Spline.h:96
Definition: Spline.h:8
Definition: StateSpaceModel.h:49