Skip to content

Commit 43edc46

Browse files
committed
opening/creating projects, running reconstruction from CL
1 parent 990aae3 commit 43edc46

File tree

7 files changed

+166
-8
lines changed

7 files changed

+166
-8
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
2828
# The order below is important:
2929
add_subdirectory(libs/QtAwesome/QtAwesome)
3030
add_subdirectory(src)
31+
add_subdirectory(cli)
3132
add_subdirectory(ui)
3233

3334
add_executable(${PROJECT_NAME} main.cpp)
34-
target_link_libraries(${PROJECT_NAME} src ui QtAwesome)
35+
target_link_libraries(${PROJECT_NAME} src cli ui QtAwesome)

cli/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(SOURCE_FILES
2+
cli.cpp
3+
)
4+
5+
set(HEADERS
6+
cli.h
7+
)
8+
9+
add_library(cli ${SOURCE_FILES} ${HEADERS})
10+
11+
# Never include ui target here.
12+
target_link_libraries(cli src Qt5::Widgets)

cli/cli.cpp

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright 2017 Lybros.
2+
3+
#include "cli.h"
4+
5+
#include <QDateTime>
6+
#include <QDir>
7+
#include <QString>
8+
9+
#include "gflags/gflags.h"
10+
#include "glog/logging.h"
11+
12+
#include "../src/project.h"
13+
14+
/* The minimum sets of parameters in CLI mode (to pass verification) are:
15+
* new + project_name + project_path + images_path + action
16+
* open + action
17+
* temp + images_path + action
18+
*/
19+
20+
DEFINE_string(cli_mode, "",
21+
"In CLI mode you may either create a new project "
22+
"or open an existent one. Choose between open, new or temp "
23+
"(temp means new + removal after processing).");
24+
DEFINE_string(project_path, "",
25+
"If you're in 'open' cli_mode, you must specify the project.");
26+
DEFINE_string(project_name, "",
27+
"You must provide a project name in order to create a new one.");
28+
DEFINE_string(images_path, "",
29+
"You must provide a dataset in order to create a new project.");
30+
31+
DEFINE_string(action, "",
32+
"Choose if you want to extract features, match them or run "
33+
"reconstruction. Visualization is only available in 'ui' mode");
34+
35+
bool VerifyCommandlineArguments() {
36+
if (FLAGS_cli_mode != "new" &&
37+
FLAGS_cli_mode != "open" &&
38+
FLAGS_cli_mode != "temp") {
39+
LOG(ERROR) << "Wrong cli_mode value.";
40+
return false;
41+
}
42+
43+
// TODO(uladbohdan): to support more actions.
44+
if (FLAGS_action != "reconstruction") {
45+
LOG(ERROR) << "You must pass a valid action to proceed.";
46+
return false;
47+
}
48+
49+
if (FLAGS_cli_mode == "new") {
50+
if (FLAGS_project_name == "" ||
51+
FLAGS_project_path == "" ||
52+
FLAGS_images_path == "") {
53+
LOG(ERROR) << "You must provide project_name, project_path and "
54+
"images_path to create a new project.";
55+
return false;
56+
}
57+
}
58+
59+
if (FLAGS_cli_mode == "open") {
60+
if (FLAGS_project_path == "") {
61+
LOG(ERROR) << "You must provide project_path to open a project.";
62+
return false;
63+
}
64+
}
65+
66+
if (FLAGS_cli_mode == "temp") {
67+
if (FLAGS_images_path == "") {
68+
LOG(ERROR) << "You must provide images_path to create a temp project";
69+
return false;
70+
}
71+
}
72+
73+
return true;
74+
}
75+
76+
void RunCLI() {
77+
LOG(INFO) << "Running in CLI mode.";
78+
79+
if (!VerifyCommandlineArguments()) {
80+
LOG(ERROR) << "CL arguments verification failed.";
81+
return;
82+
}
83+
84+
Project* project;
85+
86+
if (FLAGS_cli_mode == "open") {
87+
project = new Project(QString::fromStdString(FLAGS_project_path));
88+
} else if (FLAGS_cli_mode == "new") {
89+
project = new Project(QString::fromStdString(FLAGS_project_name),
90+
QString::fromStdString(FLAGS_project_path),
91+
QString::fromStdString(FLAGS_images_path));
92+
} else if (FLAGS_cli_mode == "temp") {
93+
project = new Project(QDateTime::currentDateTime().toString(Qt::ISODate),
94+
QDir::tempPath(),
95+
QString::fromStdString(FLAGS_images_path));
96+
}
97+
98+
if (FLAGS_action == "reconstruction") {
99+
LOG(INFO) << "Starting reconstruction...";
100+
project->BuildModelToBinary();
101+
}
102+
103+
if (FLAGS_cli_mode == "temp") {
104+
project->RemoveProject();
105+
}
106+
107+
delete project;
108+
}

cli/cli.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2017 Lybros.
2+
3+
#ifndef CLI_CLI_H_
4+
#define CLI_CLI_H_
5+
6+
void RunCLI();
7+
8+
#endif // CLI_CLI_H_

main.cpp

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
// Copyright 2017 Lybros.
22

3+
#include <gflags/gflags.h>
4+
#include <glog/logging.h>
5+
6+
#include "cli/cli.h"
37
#include "ui/mainwindow.h"
48

59
#include <QApplication>
610

11+
DEFINE_string(mode, "ui", "Application mode. Choose between ui and cli.");
12+
713
int main(int argc, char* argv[]) {
8-
QApplication a(argc, argv);
9-
QtAwesome* awesome = new QtAwesome(&a);
10-
awesome->initFontAwesome();
14+
gflags::ParseCommandLineFlags(&argc, &argv, true);
1115

1216
google::InitGoogleLogging(argv[0]);
1317
LOG(INFO) << "Logging is enabled.";
1418

15-
MainWindow w;
16-
w.set_icons(awesome);
17-
w.show();
19+
if (FLAGS_mode == "ui") {
20+
LOG(INFO) << "Running UI.";
21+
QApplication a(argc, argv);
22+
QtAwesome* awesome = new QtAwesome(&a);
23+
awesome->initFontAwesome();
24+
25+
MainWindow w;
26+
w.set_icons(awesome);
27+
w.show();
28+
29+
return a.exec();
30+
31+
} else if (FLAGS_mode == "cli") {
32+
// Running in CLI mode means no need in using any code from ui/, as ui/ is
33+
// only a wrapper for a Project object.
34+
// In CLI mode we may simply create a Project and work with it directly.
35+
RunCLI();
36+
return 0;
37+
}
1838

19-
return a.exec();
39+
LOG(ERROR) << "'mode' flag must be either 'ui' or 'cli'. "
40+
"If not provided, default value is 'ui'.";
41+
return 0;
2042
}

src/project.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ Options* Project::GetOptions() {
171171
return options_;
172172
}
173173

174+
bool Project::RemoveProject() {
175+
return true;
176+
}
177+
174178
Project::~Project() {
175179
WriteConfigurationFile();
176180
delete options_;

src/project.h

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class Project {
8383

8484
Options* GetOptions();
8585

86+
// Method completely removes Project from filesystem.
87+
bool RemoveProject();
88+
8689
~Project();
8790

8891
private:

0 commit comments

Comments
 (0)