forked from frankyeh/DSI-Studio
/
main.cpp
137 lines (120 loc) · 4.43 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <iterator>
#include <string>
#include <QApplication>
#include <QCleanlooksStyle>
#include <QMetaObject>
#include <QMetaMethod>
#include <QMessageBox>
#include <QDir>
#include "mainwindow.h"
#include "mat_file.hpp"
#include "boost/program_options.hpp"
#include "image/image.hpp"
#include "mapping/fa_template.hpp"
#include <iostream>
#include <iterator>
namespace po = boost::program_options;
int rec(int ac, char *av[]);
int trk(int ac, char *av[]);
int src(int ac, char *av[]);
int ana(int ac, char *av[]);
fa_template fa_template_imp;
void prog_debug(const char* file,const char* fun)
{
}
QStringList search_files(QString dir,QString filter)
{
QStringList dir_list,src_list;
dir_list << dir;
for(unsigned int i = 0;i < dir_list.size();++i)
{
QDir cur_dir = dir_list[i];
QStringList new_list = cur_dir.entryList(QStringList(""),QDir::AllDirs|QDir::NoDotAndDotDot);
for(unsigned int index = 0;index < new_list.size();++index)
dir_list << cur_dir.absolutePath() + "/" + new_list[index];
QStringList file_list = cur_dir.entryList(QStringList(filter),QDir::Files|QDir::NoSymLinks);
for (unsigned int index = 0;index < file_list.size();++index)
src_list << dir_list[i] + "/" + file_list[index];
}
return src_list;
}
std::string program_base;
bool load_fa_template(void)
{
std::string fa_template_path = program_base;
fa_template_path += "FMRIB58_FA_1mm.nii.gz";
if(!fa_template_imp.load_from_file(fa_template_path.c_str()))
{
std::string error_str = "Cannot find the fa template file at ";
error_str += fa_template_path;
QMessageBox::information(0,"Error",error_str.c_str(),0);
return false;
}
return true;
}
int main(int ac, char *av[])
{
{
int pos = 0;
for(int index = 0;av[0][index];++index)
if(av[0][index] == '\\' || av[0][index] == '/')
pos = index;
program_base = std::string(&(av[0][0]),&(av[0][0])+pos+1);
}
if(ac > 2)
{
{
std::cout << "DSI Studio " << __DATE__ << ", Fang-Cheng Yeh" << std::endl;
// options for general options
po::options_description desc("reconstruction options");
desc.add_options()
("help", "help message")
("action", po::value<std::string>(), "rec:diffusion reconstruction trk:fiber tracking")
("source", po::value<std::string>(), "assign the .src or .fib file name")
;
po::variables_map vm;
po::store(po::command_line_parser(ac, av).options(desc).allow_unregistered().run(),vm);
if (vm.count("help"))
{
std::cout << "example: perform reconstruction" << std::endl;
std::cout << " --action=rec --source=test.src.gz --method=4 " << std::endl;
std::cout << "options:" << std::endl;
rec(0,0);
std::cout << "example: perform fiber tracking" << std::endl;
std::cout << " --action=trk --source=test.src.gz.fib.gz --method=0 --fiber_count=5000" << std::endl;
std::cout << "options:" << std::endl;
trk(0,0);
return 1;
}
if (!vm.count("action") || !vm.count("source"))
{
std::cout << "invalid command, use --help for more detail" << std::endl;
return 1;
}
if(vm["action"].as<std::string>() == std::string("rec"))
return rec(ac,av);
if(vm["action"].as<std::string>() == std::string("trk"))
return trk(ac,av);
if(vm["action"].as<std::string>() == std::string("src"))
return src(ac,av);
if(vm["action"].as<std::string>() == std::string("ana"))
return ana(ac,av);
}
return 1;
}
QApplication::setStyle(new QCleanlooksStyle);
QApplication a(ac,av);
a.setOrganizationName("LabSolver");
a.setApplicationName("DSI Studio");
QFont font;
font.setFamily(QString::fromUtf8("Arial"));
a.setFont(font);
if(!load_fa_template())
return -1;
MainWindow w;
w.setFont(font);
w.showMaximized();
w.setWindowTitle(QString("DSI Studio ") + __DATE__ + " build");
return a.exec();
}