Optimized Belief Propagation (CPU and GPU)
EvaluateImpResultsBp.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
28 #include "EvaluateImpResultsBp.h"
30 #include <filesystem>
31 
32 //retrieve path of belief propagation implementation results
33 std::filesystem::path EvaluateImpResultsBp::GetImpResultsPath() const
34 {
35  std::filesystem::path current_path = std::filesystem::current_path();
36  while (true) {
37  //create directory iterator corresponding to current path
38  std::filesystem::directory_iterator dir_iter =
39  std::filesystem::directory_iterator(current_path);
40 
41  //set variable corresponding to iterator past end of directory since it's
42  //used multiple times
43  auto dir_end_iter = std::filesystem::end(dir_iter);
44 
45  //check if any of the directories in the current path correspond to the
46  //belief propagation directory; if so return iterator to directory;
47  //otherwise return iterator to end indicating that directory not
48  //found in current path
49  std::filesystem::directory_iterator it =
50  std::find_if(std::filesystem::begin(dir_iter),
51  dir_end_iter,
52  [](const auto &p) {
53  return p.path().stem() ==
55 
56  //check if return from find_if at iterator end and therefore didn't find
57  //belief propagation directory; if that's the case continue to outer
58  //directory
59  //for now assuming stereo sets directory exists in some outer directory and
60  //program won't work without it
61  if (it == dir_end_iter)
62  {
63  //if current path same as parent path, throw error
64  if (current_path == current_path.parent_path()) {
65  throw std::filesystem::filesystem_error(
66  "Belief propagation directory not found", std::error_code());
67  }
68  //continue to next outer directory
69  current_path = current_path.parent_path();
70  }
71 
72  //retrieve and return path for implementation results which is a subfolder
73  //inside of belief propagation directory
74  if (it != dir_end_iter) {
75  const std::filesystem::path impResultsPath{
76  it->path() / run_eval::kImpResultsFolderName};
77  if (!(std::filesystem::is_directory(impResultsPath))) {
78  //create directory if it doesn't exist
79  std::filesystem::create_directory(impResultsPath);
80  }
81  return impResultsPath;
82  }
83  }
84 }
Belief propagation implementation constants related to file processing.
Declares child class of EvaluateImpResults that defines member functions for belief propagation evalu...
constexpr std::string_view kBeliefPropDirectoryName
constexpr std::string_view kImpResultsFolderName