-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Florent2305/fusion
Add work of Thomas Durantel
- Loading branch information
Showing
12 changed files
with
1,807 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
add_subdirectory(generalized_fa) | ||
add_subdirectory(odf_estimator) | ||
add_subdirectory(odf_estimator) | ||
add_subdirectory(tod_estimator) | ||
add_subdirectory(odf_average) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
if(BUILD_TOOLS) | ||
|
||
project(animaODFAverage) | ||
|
||
# ############################################################################ | ||
# List Sources | ||
# ############################################################################ | ||
|
||
list_source_files(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
# ############################################################################ | ||
# add executable | ||
# ############################################################################ | ||
|
||
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_CFILES}) | ||
|
||
# ############################################################################ | ||
# Link | ||
# ############################################################################ | ||
|
||
target_link_libraries(${PROJECT_NAME} ${ITKIO_LIBRARIES} AnimaSHTools) | ||
|
||
# ############################################################################ | ||
# install | ||
# ############################################################################ | ||
|
||
set_exe_install_rules(${PROJECT_NAME}) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#include <animaODFAverageImageFilter.h> | ||
#include <animaReadWriteFunctions.h> | ||
|
||
#include <fstream> | ||
|
||
#include <itkTimeProbe.h> | ||
|
||
#include <tclap/CmdLine.h> | ||
|
||
// Update progression of the process | ||
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData) | ||
{ | ||
itk::ProcessObject *processObject = (itk::ProcessObject *)caller; | ||
std::cout << "\033[K\rProgression: " << (int)(processObject->GetProgress() * 100) << "%" << std::flush; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ', ANIMA_VERSION); | ||
|
||
TCLAP::ValueArg<std::string> inArg( | ||
"i", "input-odf-file", | ||
"A path or file name specifying the text file in which the ODF images are listed.", | ||
true, "", "odf image list", cmd); | ||
TCLAP::ValueArg<std::string> weightArg( | ||
"w", "input-weight-file", | ||
"A path or file name specifying the text file in which the weight images are listed.", | ||
true, "", "weight image list", cmd); | ||
TCLAP::ValueArg<std::string> outArg( | ||
"o", "output-file", | ||
"A path or file name specifying the output average ODF image.", | ||
true, "", "output odf image", cmd); | ||
|
||
TCLAP::ValueArg<unsigned int> nbpArg( | ||
"T", "nb-threads", | ||
"An integer value specifying the number of threads to run on (default: all cores).", | ||
false, itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(), "number of threads", cmd); | ||
|
||
try | ||
{ | ||
cmd.parse(argc, argv); | ||
} | ||
catch (TCLAP::ArgException &e) | ||
{ | ||
std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New(); | ||
callback->SetCallback(eventCallback); | ||
|
||
std::ifstream odfFile(inArg.getValue().c_str()); | ||
if (!odfFile.is_open()) | ||
{ | ||
std::cerr << "Please provide usable file with input ODFs" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
std::ifstream weightFile(weightArg.getValue().c_str()); | ||
if (!weightFile.is_open()) | ||
{ | ||
std::cerr << "Please provide usable file with input weight images" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
using FilterType = anima::ODFAverageImageFilter; | ||
using InputImageType = FilterType::InputImageType; | ||
using OutputImageType = FilterType::OutputImageType; | ||
using WeightImageType = FilterType::WeightImageType; | ||
|
||
FilterType::Pointer mainFilter = FilterType::New(); | ||
|
||
std::vector<std::string> inputFiles; | ||
std::vector<std::string> weightFiles; | ||
|
||
while (!odfFile.eof()) | ||
{ | ||
char tmpStr[2048], weightStr[2048]; | ||
|
||
odfFile.getline(tmpStr, 2048); | ||
if (odfFile.fail()) | ||
{ | ||
std::cerr << "Error: Failed to read an ODF image." << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
weightFile.getline(weightStr, 2048); | ||
if (weightFile.fail()) | ||
{ | ||
std::cerr << "Error: Failed to read a weight image." << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (strcmp(tmpStr, "") == 0 || strcmp(weightStr, "") == 0) | ||
continue; | ||
|
||
inputFiles.push_back(tmpStr); | ||
weightFiles.push_back(weightStr); | ||
} | ||
|
||
odfFile.close(); | ||
weightFile.close(); | ||
|
||
unsigned int numInputs = weightFiles.size(); | ||
|
||
for (unsigned int i = 0; i < numInputs; ++i) | ||
{ | ||
mainFilter->SetInput(i, anima::readImage<InputImageType>(inputFiles[i])); | ||
mainFilter->AddWeightImage(i, anima::readImage<WeightImageType>(weightFiles[i])); | ||
} | ||
|
||
mainFilter->AddObserver(itk::ProgressEvent(), callback); | ||
mainFilter->SetNumberOfWorkUnits(nbpArg.getValue()); | ||
|
||
itk::TimeProbe tmpTimer; | ||
|
||
tmpTimer.Start(); | ||
|
||
try | ||
{ | ||
mainFilter->Update(); | ||
} | ||
catch (itk::ExceptionObject &e) | ||
{ | ||
std::cerr << e << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
tmpTimer.Stop(); | ||
|
||
std::cout << "\nAveraging done in " << tmpTimer.GetTotal() << "s" << std::endl; | ||
|
||
anima::writeImage(outArg.getValue(), mainFilter->GetOutput()); | ||
|
||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.