|
| 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