Skip to content

Commit 7923db4

Browse files
authored
Merge pull request #102 from Florent2305/fusion
Add work of Thomas Durantel
2 parents fc05522 + 35df1d1 commit 7923db4

12 files changed

+1807
-478
lines changed

Anima/diffusion/odf/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
add_subdirectory(generalized_fa)
2-
add_subdirectory(odf_estimator)
2+
add_subdirectory(odf_estimator)
3+
add_subdirectory(tod_estimator)
4+
add_subdirectory(odf_average)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
if(BUILD_TOOLS)
2+
3+
project(animaODFAverage)
4+
5+
# ############################################################################
6+
# List Sources
7+
# ############################################################################
8+
9+
list_source_files(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR})
10+
11+
# ############################################################################
12+
# add executable
13+
# ############################################################################
14+
15+
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_CFILES})
16+
17+
# ############################################################################
18+
# Link
19+
# ############################################################################
20+
21+
target_link_libraries(${PROJECT_NAME} ${ITKIO_LIBRARIES} AnimaSHTools)
22+
23+
# ############################################################################
24+
# install
25+
# ############################################################################
26+
27+
set_exe_install_rules(${PROJECT_NAME})
28+
29+
endif()
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include <animaODFAverageImageFilter.h>
2+
#include <animaReadWriteFunctions.h>
3+
4+
#include <fstream>
5+
6+
#include <itkTimeProbe.h>
7+
8+
#include <tclap/CmdLine.h>
9+
10+
// Update progression of the process
11+
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
12+
{
13+
itk::ProcessObject *processObject = (itk::ProcessObject *)caller;
14+
std::cout << "\033[K\rProgression: " << (int)(processObject->GetProgress() * 100) << "%" << std::flush;
15+
}
16+
17+
int main(int argc, char **argv)
18+
{
19+
TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ', ANIMA_VERSION);
20+
21+
TCLAP::ValueArg<std::string> inArg(
22+
"i", "input-odf-file",
23+
"A path or file name specifying the text file in which the ODF images are listed.",
24+
true, "", "odf image list", cmd);
25+
TCLAP::ValueArg<std::string> weightArg(
26+
"w", "input-weight-file",
27+
"A path or file name specifying the text file in which the weight images are listed.",
28+
true, "", "weight image list", cmd);
29+
TCLAP::ValueArg<std::string> outArg(
30+
"o", "output-file",
31+
"A path or file name specifying the output average ODF image.",
32+
true, "", "output odf image", cmd);
33+
34+
TCLAP::ValueArg<unsigned int> nbpArg(
35+
"T", "nb-threads",
36+
"An integer value specifying the number of threads to run on (default: all cores).",
37+
false, itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(), "number of threads", cmd);
38+
39+
try
40+
{
41+
cmd.parse(argc, argv);
42+
}
43+
catch (TCLAP::ArgException &e)
44+
{
45+
std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
46+
return EXIT_FAILURE;
47+
}
48+
49+
itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
50+
callback->SetCallback(eventCallback);
51+
52+
std::ifstream odfFile(inArg.getValue().c_str());
53+
if (!odfFile.is_open())
54+
{
55+
std::cerr << "Please provide usable file with input ODFs" << std::endl;
56+
return EXIT_FAILURE;
57+
}
58+
59+
std::ifstream weightFile(weightArg.getValue().c_str());
60+
if (!weightFile.is_open())
61+
{
62+
std::cerr << "Please provide usable file with input weight images" << std::endl;
63+
return EXIT_FAILURE;
64+
}
65+
66+
using FilterType = anima::ODFAverageImageFilter;
67+
using InputImageType = FilterType::InputImageType;
68+
using OutputImageType = FilterType::OutputImageType;
69+
using WeightImageType = FilterType::WeightImageType;
70+
71+
FilterType::Pointer mainFilter = FilterType::New();
72+
73+
std::vector<std::string> inputFiles;
74+
std::vector<std::string> weightFiles;
75+
76+
while (!odfFile.eof())
77+
{
78+
char tmpStr[2048], weightStr[2048];
79+
80+
odfFile.getline(tmpStr, 2048);
81+
if (odfFile.fail())
82+
{
83+
std::cerr << "Error: Failed to read an ODF image." << std::endl;
84+
return EXIT_FAILURE;
85+
}
86+
87+
weightFile.getline(weightStr, 2048);
88+
if (weightFile.fail())
89+
{
90+
std::cerr << "Error: Failed to read a weight image." << std::endl;
91+
return EXIT_FAILURE;
92+
}
93+
94+
if (strcmp(tmpStr, "") == 0 || strcmp(weightStr, "") == 0)
95+
continue;
96+
97+
inputFiles.push_back(tmpStr);
98+
weightFiles.push_back(weightStr);
99+
}
100+
101+
odfFile.close();
102+
weightFile.close();
103+
104+
unsigned int numInputs = weightFiles.size();
105+
106+
for (unsigned int i = 0; i < numInputs; ++i)
107+
{
108+
mainFilter->SetInput(i, anima::readImage<InputImageType>(inputFiles[i]));
109+
mainFilter->AddWeightImage(i, anima::readImage<WeightImageType>(weightFiles[i]));
110+
}
111+
112+
mainFilter->AddObserver(itk::ProgressEvent(), callback);
113+
mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
114+
115+
itk::TimeProbe tmpTimer;
116+
117+
tmpTimer.Start();
118+
119+
try
120+
{
121+
mainFilter->Update();
122+
}
123+
catch (itk::ExceptionObject &e)
124+
{
125+
std::cerr << e << std::endl;
126+
return EXIT_FAILURE;
127+
}
128+
129+
tmpTimer.Stop();
130+
131+
std::cout << "\nAveraging done in " << tmpTimer.GetTotal() << "s" << std::endl;
132+
133+
anima::writeImage(outArg.getValue(), mainFilter->GetOutput());
134+
135+
return EXIT_SUCCESS;
136+
}

0 commit comments

Comments
 (0)