forked from theICTlab/3DUNDERWORLD-SLS-GPU_CPU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunTest.cpp
137 lines (117 loc) · 4.85 KB
/
RunTest.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <fstream>
#include <core/ImageFileProcessor.h>
#include <core/ReconstructorCPU.h>
#include <sstream>
#include <gtest/gtest.h>
const float MAX_DIFF = 0.5;
inline bool comparePlyLine(std::string line1, std::string line2)
{
if (!std::isdigit(line1[0]) && !std::isdigit(line1[1])) // if is header
return line1 == line2;
std::istringstream ssline1(line1);
std::istringstream ssline2(line2);
std::string num1, num2;
while (std::getline(ssline1, num1, ' ') && std::getline(ssline2, num2, ' '))
if ( std::fabs( std::stof(num1) - std::stof(num2) ) > MAX_DIFF)
return false;
return true;
}
inline bool compareObjLine(std::string line1, std::string line2)
{
std::istringstream ssline1(line1);
std::istringstream ssline2(line2);
std::string num1, num2;
if (std::getline(ssline1, num1, ' ') && std::getline(ssline2, num2, ' ')) // Skip first split
{
while (std::getline(ssline1, num1, ' ') && std::getline(ssline2, num2, ' '))
if ( std::fabs( std::stof(num1) - std::stof(num2) ) > MAX_DIFF)
return false;
}
return true;
}
bool compareObjFiles(std::string file1, std::string file2)
{
std::fstream is1, is2;
std::string buf1, buf2;
is1.open(file1); is2.open(file2);
while (std::getline( is1, buf1))
{
if (! std::getline(is2, buf2)) return false; // shorter
if (! compareObjLine(buf1, buf2)) return false;
}
if (std::getline(is2, buf2)) return false; // longer
return true;
}
bool comparePlyFiles(std::string file1, std::string file2)
{
std::fstream is1, is2;
std::string buf1, buf2;
is1.open(file1); is2.open(file2);
while (std::getline( is1, buf1))
{
if (! std::getline(is2, buf2)) return false; // shorter
if (! comparePlyLine(buf1, buf2)) return false;
}
if (std::getline(is2, buf2)) return false; // longer
return true;
}
TEST( RunCPUTest, Arch)
{
const std::string L_IMGS = std::string(TEST_DATA_PATH) + "/arch/leftCam/dataset1/";
const std::string L_CFG = std::string(TEST_DATA_PATH) + "/arch/leftCam/calib/output/calib.xml";
const std::string R_IMGS = std::string(TEST_DATA_PATH) + "/arch/rightCam/dataset1/";
const std::string R_CFG = std::string(TEST_DATA_PATH) + "/arch/rightCam/calib/output/calib.xml";
const std::string SUFFIX = "tif";
const size_t W=1280, H=800;
const std::string TEST_PLY = std::string(TEST_REF_PATH) + "/arch.ply";
const std::string TEST_OBJ = std::string(TEST_REF_PATH) + "/arch.obj";
const std::string O_PLY="arch.ply", O_OBJ="arch.obj";
auto RC = SLS::ImageFileProcessor("RightCamera");
RC.loadImages(R_IMGS, "", 4, 0, SUFFIX);
RC.loadConfig(R_CFG);
auto LC = SLS::ImageFileProcessor("LeftCamera");
LC.loadImages(L_IMGS, "", 4, 0, SUFFIX);
LC.loadConfig(L_CFG);
SLS::Projector proj(W, H);
SLS::ReconstructorCPU rec;
auto pc = rec.reconstruct(std::vector<SLS::Buckets>{
LC.generateBuckets(proj.getWidth(), proj.getHeight(),
proj.getRequiredNumFrames()),
RC.generateBuckets(proj.getWidth(), proj.getHeight(),
proj.getRequiredNumFrames()),
});
pc.exportPointCloud( O_PLY, "ply");
pc.exportPointCloud( O_OBJ, "obj");
EXPECT_TRUE(compareObjFiles(TEST_OBJ, O_OBJ));
EXPECT_TRUE(comparePlyFiles(TEST_PLY, TEST_PLY));
}
TEST( RunCPUTest, Alexander)
{
const std::string L_IMGS = std::string(TEST_DATA_PATH) + "/alexander/leftCam/dataset1/";
const std::string L_CFG = std::string(TEST_DATA_PATH) + "/alexander/leftCam/calib/output/calib.xml";
const std::string R_IMGS = std::string(TEST_DATA_PATH) + "/alexander/rightCam/dataset1/";
const std::string R_CFG = std::string(TEST_DATA_PATH) + "/alexander/rightCam/calib/output/calib.xml";
const std::string SUFFIX = "jpg";
const size_t W=1024, H=768;
const std::string TEST_PLY = std::string(TEST_REF_PATH) + "/alexander.ply";
const std::string TEST_OBJ = std::string(TEST_REF_PATH) + "/alexander.obj";
const std::string O_PLY="alexander.ply", O_OBJ="alexander.obj";
SLS::Projector proj(W, H);
auto RC = SLS::ImageFileProcessor("RightCamera");
RC.loadImages(R_IMGS, "", 4, 0, SUFFIX);
RC.loadConfig(R_CFG);
auto LC = SLS::ImageFileProcessor("LeftCamera");
LC.loadImages(L_IMGS, "", 4, 0, SUFFIX);
LC.loadConfig(L_CFG);
SLS::ReconstructorCPU rec;
auto pc = rec.reconstruct(std::vector<SLS::Buckets>{
LC.generateBuckets(proj.getWidth(), proj.getHeight(),
proj.getRequiredNumFrames()),
RC.generateBuckets(proj.getWidth(), proj.getHeight(),
proj.getRequiredNumFrames()),
});
pc.exportPointCloud( O_PLY, "ply");
pc.exportPointCloud( O_OBJ, "obj");
EXPECT_TRUE(compareObjFiles(TEST_OBJ, O_OBJ));
EXPECT_TRUE(comparePlyFiles(TEST_PLY, TEST_PLY));
}