-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPhisFunc.cpp
executable file
·55 lines (50 loc) · 1.62 KB
/
PhisFunc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by hyacinth on 2017/4/17.
//
#include "PhisFunc.h"
#include "sophus/se3.hpp"
#include "common.h"
bool validRow(int x)
{
return ((x>=0) && (x<=480));
}
bool validCol(int y)
{
return ((y>=0) && (y<=640));
}
double PhisFunc(double fx,double fy,double cx,double cy,
cv::Mat &depth_image, const myPoint &point, Eigen::Matrix<double, 6, 1> &twist,
double delta, double eta, double &weight, bool needTwist, bool doDbgPrint /*= false*/)
{
//transform to local coordinates
Sophus::SE3d se (Sophus::SE3d::exp(twist));
Eigen::Matrix<double , 4, 4> homogenous = se.matrix();
Eigen::Vector4d trans_point (point.x, point.y, point.z, 1);
if (needTwist)
trans_point = homogenous * trans_point;
myPoint t_point(trans_point(0),trans_point(1),trans_point(2));
//calculate SDF function
int px = int(fx*t_point.x/t_point.z + cx);
int py = int(fy*t_point.y/t_point.z + cy);
if (!(validRow(py) && validCol(px)))
{
return -999;
}
float depth_val = depth_image.at<float>(py, px);
if (depth_val < 1e-8)
{
// printf("depth_val < 1e-8; point.xyz: %f, %f, %f\n", point.x, point.y, point.z);
return -999;
}
// double trueSDF = depth_image.at<float>(py,px) - t_point.z;
double trueSDF = depth_val - t_point.z;
double SDF;
if (trueSDF >= delta) SDF = 1;
else if (trueSDF <= -delta) SDF = -1;
else SDF = trueSDF / delta;
weight = 0;
if (trueSDF > -eta) weight = 1;
if(doDbgPrint)
printf(" >>depth_val: %f, t_point.z: %f, trueSDF: %f\n", depth_val, t_point.z, trueSDF);
return SDF;
}