Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add work of Thomas Durantel #102

Merged
merged 14 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Anima/diffusion/odf/CMakeLists.txt
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)
29 changes: 29 additions & 0 deletions Anima/diffusion/odf/odf_average/CMakeLists.txt
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()
136 changes: 136 additions & 0 deletions Anima/diffusion/odf/odf_average/animaODFAverage.cxx
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",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idem

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

"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;
}
Loading
Loading