From dc6204d8aa41544a2ad022f2d2bffdd2735e5341 Mon Sep 17 00:00:00 2001 From: Anthony Lombardi Date: Wed, 11 Oct 2023 14:41:01 -0400 Subject: [PATCH 1/2] ENH: Custom tracking and filter directories and multiple filter support --- autoscoper/src/ui/AutoscoperMainWindow.cpp | 48 ++++++++++++++-------- libautoscoper/src/Trial.cpp | 26 +++++++++++- libautoscoper/src/Trial.hpp | 8 +++- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/autoscoper/src/ui/AutoscoperMainWindow.cpp b/autoscoper/src/ui/AutoscoperMainWindow.cpp index e97f8275..97014e6d 100644 --- a/autoscoper/src/ui/AutoscoperMainWindow.cpp +++ b/autoscoper/src/ui/AutoscoperMainWindow.cpp @@ -1158,25 +1158,40 @@ bool AutoscoperMainWindow::openTrial(QString filename){ std::cout << "Root Path is: " << test << std::endl; - // Store Default Values: - default_filter_folder = "xParameters"; - default_filter_name = "control_settings"; - default_tracking_folder = "Tracking"; - - /////// FILTER PATH: - QString filter_path = default_root_path; - filter_path += "/"; - filter_path += default_filter_folder; - filter_path += "/"; - filter_path += default_filter_name; - filter_path += ".vie"; + // Find filter files + std::string filter_dir = default_root_path.toStdString(); + filter_dir += "/"; + filter_dir += tracker->trial()->filter_folder; + std::string ext = ".vie"; + + std::cerr << "Filter directory: " << filter_dir << std::endl; + + std::vector filter_files; + for (auto & file : std::filesystem::directory_iterator(filter_dir)) { + if (file.path().extension() == ext) { + std::cerr << "\tFilter found: " << file.path().filename() << std::endl; + filter_files.push_back(file.path().string()); + } + } - // std::cerr << "Filter Path is: " << filter_path.toStdString().c_str() << std::endl; + if (filter_files.size() != cameraViews.size() && filter_files.size() != 1 && filter_files.size() != 0) { + std::cerr << "Mismatch between number of filter files and number of cameras!\n" + << "Number of filter files: " << filter_files.size() << "\n" + << "Number of cameras: " << cameraViews.size() << "\n" + << "Number of cameras should be equal to number of filter files or 1 or 0." << std::endl; + } + // Load filter files for (int j = 0; j < cameraViews.size(); j++) { - loadFilterSettings(j, filter_path); + if (filter_files.size() == 1) { // If trial has only one filter file, load it for all cameras + loadFilterSettings(j, QString::fromStdString(filter_files[0])); + } + else if (filter_files.size() == cameraViews.size()) { // If trial has a filter file for each camera, load it + loadFilterSettings(j, QString::fromStdString(filter_files[j])); + } // If there is a mismatch or zero files, don't load any filter files } + /////// TRACKED PATH: size_t pos_trck = trial_filename.find(".cfg"); std::string task_name_tmp = trial_filename.substr(pos + 1, pos_trck - pos - 1); @@ -1186,9 +1201,10 @@ bool AutoscoperMainWindow::openTrial(QString filename){ QString tracking_path_root = default_root_path; QString tracking_path; + QString tracking_folder = QString::fromStdString(tracker->trial()->tracking_folder); std::cout << "Tracking Data Directory: " - << qPrintable(tracking_path_root) << "/" << qPrintable(default_tracking_folder) << std::endl; + << qPrintable(tracking_path_root) << "/" << qPrintable(tracking_folder) << std::endl; for (int iVol = 0; iVol < tracker->trial()->num_volumes; iVol++) { @@ -1198,7 +1214,7 @@ bool AutoscoperMainWindow::openTrial(QString filename){ tracking_path = tracking_path_root; tracking_path += "/"; - tracking_path += default_tracking_folder; + tracking_path += tracking_folder; tracking_path += "/"; tracking_path += tracking_filename; diff --git a/libautoscoper/src/Trial.cpp b/libautoscoper/src/Trial.cpp index 12fba0e2..5226e57a 100644 --- a/libautoscoper/src/Trial.cpp +++ b/libautoscoper/src/Trial.cpp @@ -88,6 +88,8 @@ namespace xromm std::vector volumeFlips; std::vector renderResolution; std::vector optimizationOffsets; + std::string trackingFolder = "Tracking"; + std::string filterFolder = "xParameters"; parse(file, version, @@ -97,7 +99,9 @@ namespace xromm voxelSizes, volumeFlips, renderResolution, - optimizationOffsets); + optimizationOffsets, + trackingFolder, + filterFolder); file.close(); @@ -119,6 +123,9 @@ namespace xromm convertToAbsolutePaths(volumeFiles, configLocation); } + tracking_folder = trackingFolder; + filter_folder = filterFolder; + validate(mayaCams, camRootDirs, volumeFiles, @@ -189,7 +196,9 @@ namespace xromm std::vector& voxelSizes, std::vector& volumeFlips, std::vector& renderResolution, - std::vector& optimizationOffsets) { + std::vector& optimizationOffsets, + std::string& trackingFolder, + std::string& filterFolder) { std::string line, key, value; while (std::getline(file, line)) { @@ -244,6 +253,19 @@ namespace xromm parseVersion(value, version); continue; } + else if (key.compare("TrackingFolder") == 0) { + std::getline(lineStream, value); + trimLineEndings(value); + trackingFolder = value; + } + else if (key.compare("FilterFolder") == 0) { + std::getline(lineStream, value); + trimLineEndings(value); + filterFolder = value; + } + else { + std::cout << "Unknown key: " << key << std::endl; + } } } diff --git a/libautoscoper/src/Trial.hpp b/libautoscoper/src/Trial.hpp index d8368493..aacb17ce 100644 --- a/libautoscoper/src/Trial.hpp +++ b/libautoscoper/src/Trial.hpp @@ -86,6 +86,10 @@ class Trial int render_width; int render_height; + // Trial file info + std::string filter_folder; + std::string tracking_folder; + KeyCurve * getXCurve(int volumeID); KeyCurve * getYCurve(int volumeID); KeyCurve * getZCurve(int volumeID); @@ -106,7 +110,9 @@ class Trial std::vector& voxelSizes, std::vector& volumeFlips, std::vector& renderResolution, - std::vector& optimizationOffsets); + std::vector& optimizationOffsets, + std::string& trackingFolder, + std::string& filterFolder); void parseVersion(const std::string& text, std::vector& version); From 269e9de397d89729cf8fa949c7837f073f51b9a9 Mon Sep 17 00:00:00 2001 From: Anthony Lombardi Date: Wed, 11 Oct 2023 14:45:09 -0400 Subject: [PATCH 2/2] ENH: Save custom paths to cfg --- libautoscoper/src/Trial.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libautoscoper/src/Trial.cpp b/libautoscoper/src/Trial.cpp index 5226e57a..89a7c608 100644 --- a/libautoscoper/src/Trial.cpp +++ b/libautoscoper/src/Trial.cpp @@ -422,6 +422,10 @@ namespace xromm file << "Version 1.1" << std::endl; + file << "FilterFolder " << filter_folder << std::endl; + + file << "TrackingFolder " << tracking_folder << std::endl; + for (const std::string& mayaCamsFile: mayaCamsFiles) { file << "mayaCam_csv " << mayaCamsFile << std::endl; }