Skip to content

Commit

Permalink
ENH: Custom tracking and filter directories and multiple filter support
Browse files Browse the repository at this point in the history
  • Loading branch information
NicerNewerCar committed Oct 11, 2023
1 parent 16e4606 commit dc6204d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
48 changes: 32 additions & 16 deletions autoscoper/src/ui/AutoscoperMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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);
Expand All @@ -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++) {

Expand All @@ -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;

Expand Down
26 changes: 24 additions & 2 deletions libautoscoper/src/Trial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace xromm
std::vector<std::string> volumeFlips;
std::vector<std::string> renderResolution;
std::vector<std::string> optimizationOffsets;
std::string trackingFolder = "Tracking";
std::string filterFolder = "xParameters";

parse(file,
version,
Expand All @@ -97,7 +99,9 @@ namespace xromm
voxelSizes,
volumeFlips,
renderResolution,
optimizationOffsets);
optimizationOffsets,
trackingFolder,
filterFolder);

file.close();

Expand All @@ -119,6 +123,9 @@ namespace xromm
convertToAbsolutePaths(volumeFiles, configLocation);
}

tracking_folder = trackingFolder;
filter_folder = filterFolder;

validate(mayaCams,
camRootDirs,
volumeFiles,
Expand Down Expand Up @@ -189,7 +196,9 @@ namespace xromm
std::vector<std::string>& voxelSizes,
std::vector<std::string>& volumeFlips,
std::vector<std::string>& renderResolution,
std::vector<std::string>& optimizationOffsets) {
std::vector<std::string>& optimizationOffsets,
std::string& trackingFolder,
std::string& filterFolder) {

std::string line, key, value;
while (std::getline(file, line)) {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion libautoscoper/src/Trial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -106,7 +110,9 @@ class Trial
std::vector<std::string>& voxelSizes,
std::vector<std::string>& volumeFlips,
std::vector<std::string>& renderResolution,
std::vector<std::string>& optimizationOffsets);
std::vector<std::string>& optimizationOffsets,
std::string& trackingFolder,
std::string& filterFolder);

void parseVersion(const std::string& text, std::vector<int>& version);

Expand Down

0 comments on commit dc6204d

Please sign in to comment.