Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions g2o/apps/g2o_viewer/run_g2o_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ int RunG2OViewer::run(int argc, char** argv, CommandArgs& arg) {
"graph file which will be processed", true);
arg.parseArgs(argc, argv);

// Check if given file exists
if (inputFilename.size() > 0 && !std::ifstream(inputFilename)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call fileExists instead? see https://github.com/RainerKuemmerle/g2o/blob/master/g2o/stuff/filesys_tools.h#L80C20-L80C30
Downside would be it also passes for a directory. We probably could use some filessystem calls instead directly.

@FelixSchladt FelixSchladt Apr 20, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current approach with ifstream, does also not check if the file is a directory. Therefore we actually could use the function and would have the same result.

One approach would be to use stat to check the filetype:

bool is_regular_file(const std::string& path) {
    struct stat path_stat;
    stat(path.c_str(), &path_stat);
    return S_ISREG(path_stat.st_mode); // Return true if it's a regular file
}

This works just fine but will only work on posix compliant systems.
So far I did not find a good way to achieve this to work on windows as well as on posix without using preprocessor magic. Additionally I do not have any means to test on windows.

The right way in my opinion would be to use C++17's filesystem library, but for this the c++ version would require a bump.

So this might be a lean efficient compromise

std::cerr << "Error: unable to open file " << inputFilename << std::endl;
std::exit(1);
}

MainWindow mw;
mw.updateDisplayedSolvers();
mw.updateRobustKernels();
Expand Down