2 #include <tclap/CmdLine.h> 8 void eventCallback(itk::Object* caller,
const itk::EventObject& event,
void* clientData)
10 itk::ProcessObject *processObject = (itk::ProcessObject*) caller;
11 std::cout <<
"\033[K\rProgression: " << (int)(processObject->GetProgress() * 100) <<
"%" << std::flush;
20 template <
class ComponentType,
unsigned int ImageDimension>
24 itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
28 typedef typename FilterType::InputImageType InputImageType;
29 typedef typename FilterType::OutputImageType OutputImageType;
30 typedef typename FilterType::MaskImageType MaskImageType;
32 typename FilterType::Pointer filter = FilterType::New();
33 filter->SetInput(anima::readImage<InputImageType>(args.
input));
34 filter->SetFlippedAxis(args.
axis);
37 filter->SetComputationMask(anima::readImage<MaskImageType>(args.
mask));
39 filter->SetNumberOfWorkUnits(args.
nthreads);
40 filter->AddObserver(itk::ProgressEvent(), callback);
43 std::cout << std::endl;
45 anima::writeImage<OutputImageType>(args.
output, filter->GetOutput());
48 template <
class ComponentType>
55 int main(
int argc,
char **argv)
58 TCLAP::CmdLine cmd(
"Flip tensors in a DTI volume.\nINRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
60 TCLAP::ValueArg<std::string> inArg(
"i",
"input",
"Input tensor image.",
true,
"",
"input image", cmd);
61 TCLAP::ValueArg<std::string> outArg(
"o",
"output",
"Output tensor image.",
true,
"",
"output image", cmd);
63 TCLAP::ValueArg<std::string> maskArg(
"m",
"mask",
"Computation mask",
false,
"",
"mask image", cmd);
64 TCLAP::ValueArg<std::string> axisArg(
"a",
"axis",
"Axis to be flipped (choices are X, Y [default] or Z).",
false,
"Y",
"axis name", cmd);
66 TCLAP::ValueArg<unsigned int> nbpArg(
"p",
"nthreads",
"Number of thread to use (default: all)",
false, itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),
"number of thread", cmd);
72 catch (TCLAP::ArgException& e)
74 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
79 itk::ImageIOBase::Pointer
imageIO = itk::ImageIOFactory::CreateImageIO(inArg.getValue().c_str(),
80 itk::ImageIOFactory::ReadMode);
83 std::cerr <<
"Itk could not find suitable IO factory for the input" << std::endl;
88 imageIO->SetFileName(inArg.getValue());
89 imageIO->ReadImageInformation();
92 args.
input = inArg.getValue();
93 args.
output = outArg.getValue();
94 args.
mask = maskArg.getValue();
96 std::string axisStr = axisArg.getValue();
97 std::transform(axisStr.begin(),axisStr.end(),axisStr.begin(),[](
unsigned char c){
return std::tolower(c); });
105 catch (itk::ExceptionObject &err)
107 std::cerr << err << std::endl;
void flipTensors(itk::ImageIOBase::Pointer imageIO, const arguments &args)
void retrieveNbDimensions(itk::ImageIOBase::Pointer imageIO, const arguments &args)
int main(int argc, char **argv)
itk::ImageIOBase::Pointer imageIO
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
#define ANIMA_RETRIEVE_COMPONENT_TYPE(imageIO, function,...)
#define ANIMA_RETRIEVE_NUMBER_OF_DIMENSIONS(imageIO, ComponentType, function,...)