Skip to content

Commit 09831b6

Browse files
paskinocasperdcl
andauthored
refactor test (#192)
Co-Authored-By: Casper da Costa-Luis <imaging@cdcl.ml>
1 parent 5053226 commit 09831b6

10 files changed

Lines changed: 624 additions & 14 deletions

File tree

Core/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ include_directories(strain PUBLIC
9898
)
9999

100100
if(BUILD_TEST)
101-
add_executable (tests ${CMAKE_CURRENT_SOURCE_DIR}/tests.cpp )
102-
#TARGET_LINK_LIBRARIES (tests cilDVC Eigen3::Eigen)
103-
target_link_libraries (tests cildvc_static)
104-
include_directories(tests PUBLIC
105-
${CMAKE_CURRENT_SOURCE_DIR} )
101+
add_subdirectory(tests)
106102
endif()
107103

108104
# BKB: commenting out next 2 lines for make of Core to work

Core/tests/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add_executable (tests ${CMAKE_CURRENT_SOURCE_DIR}/tests.cpp )
2+
target_link_libraries (tests cildvc_static)
3+
include_directories(tests PUBLIC ${CMAKE_SOURCE_DIR}/Core )
4+
5+
add_executable(test1 test_DataCloud.cpp)
6+
target_link_libraries (test1 cildvc_static)
7+
include_directories(test1 PUBLIC ${CMAKE_SOURCE_DIR}/Core )
8+
9+
10+
install(TARGETS tests test1
11+
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
12+
)
13+
14+
15+
message (WARNING "Adding test test1")
16+
17+
add_test(NAME DATACLOUD_test
18+
COMMAND test1 datacloud_input.txt
19+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
20+

Core/tests/datacloud_input.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
###############################################################################
2+
#
3+
#
4+
# example dvc process control file
5+
#
6+
#
7+
###############################################################################
8+
9+
# all lines beginning with a # character are ignored
10+
# some parameters are conditionally required, depending on the setting of other parameters
11+
# for example, if subvol_thresh is off, the threshold description parameters are not required
12+
13+
### file names
14+
reference_filename reference.npy ### reference tomography image volume
15+
correlate_filename correlate.npy ### correlation tomography image volume
16+
17+
point_cloud_filename grid_input.roi ### file of search point locations
18+
output_filename 42kpoints_out ### base name for output files
19+
20+
### description of the image data files, all must be the same size and structure
21+
22+
vol_bit_depth 8 ### 8 or 16
23+
vol_hdr_lngth 96 ### fixed-length header size, may be zero
24+
vol_wide 20 ### width in pixels of each slice
25+
vol_high 30 ### height in pixels of each slice
26+
vol_tall 40 ### number of slices in the stack
27+
28+
### parameters defining the subvolumes that will be created at each search point
29+
30+
subvol_geom sphere ### cube, sphere
31+
subvol_size 10 ### side length or diameter, in voxels
32+
subvol_npts 8000 ### number of points to distribute within the subvol
33+
34+
subvol_thresh off ### on or off, evaluate subvolumes based on threshold
35+
# gray_thresh_min 27 ### lower limit of a gray threshold range if subvol_thresh is on
36+
# gray_thresh_max 127 ### upper limit of a gray threshold range if subvol_thresh is on
37+
# min_vol_fract 0.2 ### only search if subvol fraction is greater than
38+
39+
### required parameters defining the basic the search process
40+
41+
disp_max 3 ### in voxels, used for range checking and global search limits
42+
num_srch_dof 6 ### 3, 6, or 12
43+
obj_function znssd ### sad, ssd, zssd, nssd, znssd
44+
interp_type tricubic ### trilinear, tricubic
45+
46+
### optional parameters tuning and refining the search process
47+
48+
rigid_trans 3.0 4.0 0.0 ### rigid body offset of target volume, in voxels
49+
basin_radius 0.0 ### coarse-search resolution, in voxels, 0.0 = none
50+
subvol_aspect 1.0 1.0 1.0 ### subvolume aspect ratio
51+
52+
num_points_to_process 10
53+

Core/tests/grid_input.roi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1 543.814 391.457 630.000
2+
2 527.698 419.369 630.000
3+
3 511.583 447.282 630.000
4+
4 571.821 407.627 630.000
5+
5 555.706 435.540 630.000
6+
6 539.590 463.452 630.000
7+
7 615.944 395.884 630.000
8+
8 599.829 423.797 630.000
9+
9 583.713 451.710 630.000
10+
10 567.598 479.622 630.000

Core/tests/test_DataCloud.cpp

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#include "dvc.h"
2+
3+
/******************************************************************************/
4+
void echo_vect_upto(std::vector<double> vect, unsigned int n)
5+
{
6+
std::cout << std::setprecision(6) << std::fixed;
7+
8+
for (unsigned int i = 0; i<vect.size(); i++)
9+
if (i<n) std::cout << vect[i] << "\t";
10+
11+
}
12+
13+
/******************************************************************************/
14+
int main(int argc, char *argv[])
15+
{
16+
int nProcessors = omp_get_num_procs();
17+
18+
int OMP_NUM_THREADS = omp_get_max_threads();
19+
20+
if (omp_get_max_threads() > nProcessors || !OMP_NUM_THREADS)
21+
{
22+
omp_set_num_threads(nProcessors);
23+
}
24+
25+
#pragma omp parallel
26+
{
27+
if (omp_get_thread_num() == 0)
28+
{
29+
cout << "Running with threads = " << omp_get_num_threads() << endl;
30+
}
31+
}
32+
33+
InputRead in;
34+
35+
std::string help("help");
36+
std::string example("example");
37+
std::string manual("manual");
38+
39+
bool first_point = true;
40+
41+
// command entered with no arguments
42+
if (argc == 1)
43+
{
44+
std::cout << endl;
45+
std::cout << "Options:" << endl;
46+
std::cout << "dvc dvc_in\t\t// execute dvc code with dvc_in controlling the run" << endl;
47+
std::cout << "dvc help\t\t// provide additional detail about running the dvc code" << endl;
48+
std::cout << "dvc example\t\t// print dvc_in_example with brief keyword descriptions" << endl;
49+
std::cout << "dvc manual\t\t// print dvc_manual with more detailed information" << endl;
50+
std::cout << endl;
51+
return 1;
52+
}
53+
54+
// trap help on the command line
55+
if (argv[1] == help)
56+
{
57+
std::cout << endl;
58+
std::cout << "Program execution is controlled by a key_word based input file." << endl;
59+
std::cout << "Please refer to an example input file for content and format." << endl;
60+
std::cout << "To run the code type dvc followed by the name of the input file." << endl;
61+
std::cout << "The input file is evaluated and, if all is good, the run starts." << endl;
62+
std::cout << "Common problems are incorrect file paths, missing keywords, and invalid parameters." << endl;
63+
std::cout << "A message is sent to the console window if an input file problem is encountered." << endl;
64+
std::cout << "Progrm execution can be lengthy, on the order of hours for large point clouds." << endl;
65+
std::cout << "Results are written to output_filename.disp during execution." << endl;
66+
std::cout << "Information about the run is written to output_filename.stat during execution." << endl;
67+
std::cout << "Both files are simple text, and can be opened and viewed at any time." << endl;
68+
std::cout << endl;
69+
return 0;
70+
}
71+
72+
// trap example on the command line
73+
if (argv[1] == example)
74+
{
75+
std::cout << "\ndvc_in_example printed in the current working directory" << endl << endl;
76+
std::ofstream dvc_inp("dvc_in_example");
77+
in.print_input_example(dvc_inp, "fio_name");
78+
in.print_input_example(dvc_inp, "vox_data");
79+
in.print_input_example(dvc_inp, "sub_vols");
80+
in.print_input_example(dvc_inp, "opt_mthd");
81+
in.print_input_example(dvc_inp, "opt_tune");
82+
dvc_inp.seekp(0, dvc_inp.beg);
83+
dvc_inp.close();
84+
return 0;
85+
}
86+
87+
// trap manual on the command line
88+
if (argv[1] == manual)
89+
{
90+
std::cout << "\ndvc_manual printed in the current working directory" << endl << endl;
91+
std::ofstream dvc_man("dvc_manual");
92+
in.print_manual_intro(dvc_man);
93+
in.print_manual_section(dvc_man, "fio_name");
94+
in.print_manual_section(dvc_man, "vox_data");
95+
in.print_manual_section(dvc_man, "sub_vols");
96+
in.print_manual_section(dvc_man, "opt_mthd");
97+
in.print_manual_section(dvc_man, "opt_tune");
98+
in.print_manual_output(dvc_man);
99+
dvc_man.seekp(0, dvc_man.beg);
100+
dvc_man.close();
101+
return 0;
102+
}
103+
104+
// check to see if the command line argument is an accessible file
105+
106+
std::string fname(argv[1]);
107+
if (!in.input_file_accessible(fname)) return -1;
108+
109+
// instantiate storage for run control parameters within Utility
110+
111+
RunControl run;
112+
113+
// parse and check the input file
114+
115+
if (!in.input_file_read(&run)) return -2;
116+
117+
// instantiate a DataCloud
118+
// organize_cloud can be lengthy, does (# points)*(# points) sorting
119+
120+
DataCloud data;
121+
122+
if (!in.read_point_cloud(&run, data.points, data.labels)) return -3;
123+
124+
data.organize_cloud(&run);
125+
126+
std::cout << "Checking results " << std::endl;
127+
128+
std::vector<std::vector<int>> solution = {};
129+
std::vector<int> row = {
130+
0, 1, 3, 4, 2, 7, 5, 6, 8, 9,
131+
1, 0, 2, 4, 3, 5, 8, 9, 7, 6,
132+
2, 1, 5, 4, 0, 9, 3, 8, 7, 6,
133+
3, 4, 0, 7, 1, 8, 6, 5, 9, 2,
134+
4, 5, 3, 8, 1, 9, 2, 0, 7, 6,
135+
5, 4, 2, 9, 8, 1, 3, 0, 7, 6,
136+
6, 7, 3, 8, 4, 0, 1, 9, 5, 2,
137+
7, 6, 8, 3, 4, 9, 0, 5, 1, 2,
138+
8, 9, 7, 4, 5, 3, 6, 1, 2, 0,
139+
9, 8, 5, 4, 7, 2, 3, 1, 0, 6 };
140+
for (int i = 0; i < 10; i++) {
141+
std::vector<int> drow = {};
142+
for (int j = 0; j < 10; j++) {
143+
drow.push_back(row[i * 10 + j]);
144+
}
145+
}
146+
147+
std::ifstream infile("grid_input.roi.sorted");
148+
int a, b, c, d, e, f, g, h, l, m;
149+
int result = 0, j = 0;
150+
while (infile >> a >> b >> c >> d >> e >> f >> g >> h >> l >> m)
151+
{
152+
std::vector<int> riga = { a,b,c,d,e,f,g,h,l,m};
153+
for (int i = 0; i < 10; i++) {
154+
//std::cout << "Checking results " << row[i + j* 10] << " " << riga[i] << std::endl;
155+
if (row[i + j * 10] != riga[i]) {
156+
result++;
157+
}
158+
159+
}
160+
j++;
161+
}
162+
163+
std::cout << "Final result is " << result << std::endl;
164+
165+
return result;
166+
}
167+
/******************************************************************************/

0 commit comments

Comments
 (0)