-
Notifications
You must be signed in to change notification settings - Fork 8
/
sw_graph_vec.cpp
60 lines (46 loc) · 1.4 KB
/
sw_graph_vec.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
56
57
58
59
#include "sw_graph_vec.h"
/*********************************** class members *****************************/
////////////////////////////////////////////////////////////////////////////////////
void alpha_expansion_vec:: computeKnnNeighbours(int Knn)
{
neighbrs_.clear();
vector<vector<float> > dist;
neighbrs_ = knnNeighbours(Knn, input_, input_, dist);
}
///////////////////////////////////////////////////////////////////////////////////
double alpha_expansion_vec:: data_term(int id, int label)
{
Vec3 normal = input_[id];
Vec3 center = centers_[label];
normal.normalize();
center.normalize();
double u = normal * center;
u = min(u, 1.0);
u = max(-1.0, u); //abs(u)> 1 则返回NAN
return acos(u)* 180/ 3.1416;
}
///////////////////////////////////////////////////////////////////////////////////
double alpha_expansion_vec:: smooth_term(int xid, int yid, int xlabel, int ylabel)
{
double E = 0;
if(xlabel != ylabel)
{
Vec3 normal0 = input_[xid];
Vec3 normal1 = input_[yid];
normal0.normalize();
normal1.normalize();
double u = normal0 * normal1;
u = min(u, (double)1.0);
u = max((double)-1.0, u); //abs(u)> 1 则返回NAN
double angle = acos(u)* 180/ 3.1416;
if(angle < angle_thresh_)
{
E += 3*lambda_;
}
else
{
E += lambda_;
}
}
return E;
}