diff --git a/Modules/DiffusionImaging/MiniApps/CMakeLists.txt b/Modules/DiffusionImaging/MiniApps/CMakeLists.txt index b9abc090de..43be92ff29 100755 --- a/Modules/DiffusionImaging/MiniApps/CMakeLists.txt +++ b/Modules/DiffusionImaging/MiniApps/CMakeLists.txt @@ -1,153 +1,165 @@ option(BUILD_DiffusionMiniApps "Build commandline tools for diffusion" OFF) if(BUILD_DiffusionMiniApps OR MITK_BUILD_ALL_APPS) # needed include directories include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) mitk_create_executable(DwiDenoising DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES DwiDenoising.cpp mitkCommandLineParser.cpp ) mitk_create_executable(ImageResampler DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES ImageResampler.cpp mitkCommandLineParser.cpp ) mitk_create_executable(NetworkCreation DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking MitkConnectomics PACKAGE_DEPENDS ITK CPP_FILES NetworkCreation.cpp mitkCommandLineParser.cpp ) mitk_create_executable(NetworkStatistics DEPENDS MitkCore MitkDiffusionCore MitkConnectomics PACKAGE_DEPENDS ITK CPP_FILES NetworkStatistics.cpp mitkCommandLineParser.cpp ) mitk_create_executable(ExportShImage DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES ExportShImage.cpp mitkCommandLineParser.cpp ) mitk_create_executable(Fiberfox DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES Fiberfox.cpp mitkCommandLineParser.cpp ) mitk_create_executable(MultishellMethods DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES MultishellMethods.cpp mitkCommandLineParser.cpp ) mitk_create_executable(PeaksAngularError DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES PeaksAngularError.cpp mitkCommandLineParser.cpp ) mitk_create_executable(PeakExtraction DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES PeakExtraction.cpp mitkCommandLineParser.cpp ) + mitk_create_executable(FiberExtraction + DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking + PACKAGE_DEPENDS ITK + CPP_FILES FiberExtraction.cpp mitkCommandLineParser.cpp + ) + + mitk_create_executable(FiberProcessing + DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking + PACKAGE_DEPENDS ITK + CPP_FILES FiberProcessing.cpp mitkCommandLineParser.cpp + ) + mitk_create_executable(FiberDirectionExtraction DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES FiberDirectionExtraction.cpp mitkCommandLineParser.cpp ) mitk_create_executable(LocalDirectionalFiberPlausibility DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES LocalDirectionalFiberPlausibility.cpp mitkCommandLineParser.cpp ) mitk_create_executable(StreamlineTracking DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES StreamlineTracking.cpp mitkCommandLineParser.cpp ) mitk_create_executable(GibbsTracking DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES GibbsTracking.cpp mitkCommandLineParser.cpp ) mitk_create_executable(CopyGeometry DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES CopyGeometry.cpp mitkCommandLineParser.cpp ) mitk_create_executable(DiffusionIndices DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES DiffusionIndices.cpp mitkCommandLineParser.cpp ) mitk_create_executable(TractometerMetrics DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking PACKAGE_DEPENDS ITK CPP_FILES TractometerMetrics.cpp mitkCommandLineParser.cpp ) mitk_create_executable(QballReconstruction DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES QballReconstruction.cpp mitkCommandLineParser.cpp ) mitk_create_executable(FolderRegistration DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES mitkRegistration.cpp mitkCommandLineParser.cpp ) mitk_create_executable(FileFormatConverter DEPENDS MitkCore MitkDiffusionCore MitkFiberTracking MitkDiffusionIO PACKAGE_DEPENDS ITK CPP_FILES mitkFileFormatConverter.cpp mitkCommandLineParser.cpp ) mitk_create_executable(TensorReconstruction DEPENDS MitkCore MitkDiffusionCore MitkDiffusionIO PACKAGE_DEPENDS ITK CPP_FILES TensorReconstruction.cpp mitkCommandLineParser.cpp ) mitk_create_executable(TensorDerivedMapExtraction DEPENDS MitkCore MitkDiffusionCore MitkDiffusionIO PACKAGE_DEPENDS ITK CPP_FILES TensorDerivedMapsExtraction.cpp mitkCommandLineParser.cpp ) mitk_create_executable(DICOMLoader DEPENDS MitkCore MitkDiffusionCore PACKAGE_DEPENDS ITK CPP_FILES DICOMLoader.cpp mitkCommandLineParser.cpp ) mitk_create_executable(Dicom2Nrrd DEPENDS MitkCore CPP_FILES Dicom2Nrrd.cpp mitkCommandLineParser.cpp ) if(EXECUTABLE_IS_ENABLED) MITK_INSTALL_TARGETS(EXECUTABLES ${EXECUTABLE_TARGET}) endif() endif() diff --git a/Modules/DiffusionImaging/MiniApps/FiberExtraction.cpp b/Modules/DiffusionImaging/MiniApps/FiberExtraction.cpp index 3ac292d293..b14e5a6b57 100755 --- a/Modules/DiffusionImaging/MiniApps/FiberExtraction.cpp +++ b/Modules/DiffusionImaging/MiniApps/FiberExtraction.cpp @@ -1,158 +1,156 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "MiniAppManager.h" #include #include -#include "ctkCommandLineParser.h" +#include "mitkCommandLineParser.h" #include #include #include #include #include #include #include #include #include #define _USE_MATH_DEFINES #include -int FiberExtraction(int argc, char* argv[]) +int main(int argc, char* argv[]) { std::cout << "FiberExtraction"; mitkCommandLineParser parser; parser.setTitle("Fiber Extraction"); parser.setCategory("Fiber Tracking and Processing Methods"); parser.setContributor("MBI"); parser.setDescription(""); parser.setArgumentPrefix("--", "-"); parser.addArgument("input", "i", mitkCommandLineParser::String, "Input:", "input tractogram (.fib/.trk)", us::Any(), false); parser.addArgument("out", "o", mitkCommandLineParser::String, "Output:", "output tractogram", us::Any(), false); parser.addArgument("planfirgure1", "pf1", mitkCommandLineParser::String, "Figure 1:", "first ROI", us::Any(), false); parser.addArgument("planfirgure2", "pf2", mitkCommandLineParser::String, "Figure 2:", "second ROI", us::Any()); parser.addArgument("operation", "op", mitkCommandLineParser::String, "Operation:", "logical operation (AND, OR, NOT)", us::Any()); map parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.size()==0) return EXIT_FAILURE; string inFib = us::any_cast(parsedArgs["input"]); string outFib = us::any_cast(parsedArgs["out"]); string pf1_path = us::any_cast(parsedArgs["planfirgure1"]); string operation(""); string pf2_path(""); if (parsedArgs.count("operation")) { operation = us::any_cast(parsedArgs["operation"]); if (parsedArgs.count("planfirgure2") && (operation=="AND" || operation=="OR")) pf2_path = us::any_cast(parsedArgs["planfirgure2"]); } try { typedef itk::Image ItkUcharImgType; // load fiber bundle mitk::FiberBundleX::Pointer inputTractogram = dynamic_cast(mitk::IOUtil::LoadDataNode(inFib)->GetData()); mitk::FiberBundleX::Pointer result; mitk::BaseData::Pointer input1 = mitk::IOUtil::LoadDataNode(pf1_path)->GetData(); mitk::PlanarFigure::Pointer pf1 = dynamic_cast(input1.GetPointer()); if (pf1.IsNotNull()) { mitk::BaseData::Pointer input2; mitk::PlanarFigure::Pointer pf2; if (!pf2_path.empty()) { input2 = mitk::IOUtil::LoadDataNode(pf2_path)->GetData(); pf2 = dynamic_cast(input2.GetPointer()); } mitk::PlanarFigureComposite::Pointer pfc = mitk::PlanarFigureComposite::New(); if (operation.empty()) { result = inputTractogram->ExtractFiberSubset(input1); } else if (operation=="NOT") { pfc->setOperationType(mitk::PFCOMPOSITION_NOT_OPERATION); pfc->addPlanarFigure(input1); result = inputTractogram->ExtractFiberSubset(pfc); } else if (operation=="AND" && pf2.IsNotNull()) { pfc->setOperationType(mitk::PFCOMPOSITION_AND_OPERATION); pfc->addPlanarFigure(input1); pfc->addPlanarFigure(input2); result = inputTractogram->ExtractFiberSubset(pfc); } else if (operation=="OR" && pf2.IsNotNull()) { pfc->setOperationType(mitk::PFCOMPOSITION_OR_OPERATION); pfc->addPlanarFigure(input1); pfc->addPlanarFigure(input2); result = inputTractogram->ExtractFiberSubset(pfc); } else { std::cout << "Could not process input:"; std::cout << pf1_path; std::cout << pf2_path; std::cout << operation; } } else { ItkUcharImgType::Pointer itkMaskImage = ItkUcharImgType::New(); mitk::Image::Pointer mitkMaskImage = dynamic_cast(mitk::IOUtil::LoadDataNode(pf1_path)->GetData()); mitk::CastToItkImage(mitkMaskImage, itkMaskImage); if (operation=="NOT") result = inputTractogram->ExtractFiberSubset(itkMaskImage, true, true); else result = inputTractogram->ExtractFiberSubset(itkMaskImage, true, false); } if (result.IsNotNull()) mitk::IOUtil::SaveBaseData(result, outFib); else std::cout << "No valid fiber bundle extracted."; } catch (itk::ExceptionObject e) { std::cout << e; return EXIT_FAILURE; } catch (std::exception e) { std::cout << e.what(); return EXIT_FAILURE; } catch (...) { std::cout << "ERROR!?!"; return EXIT_FAILURE; } return EXIT_SUCCESS; } -RegisterDiffusionMiniApp(FiberExtraction); diff --git a/Modules/DiffusionImaging/MiniApps/FiberProcessing.cpp b/Modules/DiffusionImaging/MiniApps/FiberProcessing.cpp index 4398eb26bf..b88d9012f9 100644 --- a/Modules/DiffusionImaging/MiniApps/FiberProcessing.cpp +++ b/Modules/DiffusionImaging/MiniApps/FiberProcessing.cpp @@ -1,210 +1,207 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "MiniAppManager.h" - #include #include #include #include #include #include #include #include #include #include #include -#include "ctkCommandLineParser.h" +#include "mitkCommandLineParser.h" #include #include #include mitk::FiberBundleX::Pointer LoadFib(std::string filename) { const std::string s1="", s2=""; std::vector fibInfile = mitk::BaseDataIO::LoadBaseDataFromFile( filename, s1, s2, false ); if( fibInfile.empty() ) std::cout << "File " << filename << " could not be read!"; mitk::BaseData::Pointer baseData = fibInfile.at(0); return dynamic_cast(baseData.GetPointer()); } -int FiberProcessing(int argc, char* argv[]) +int main(int argc, char* argv[]) { std::cout << "FiberProcessing"; mitkCommandLineParser parser; parser.setTitle("Fiber Processing"); parser.setCategory("Fiber Tracking and Processing Methods"); parser.setDescription(""); parser.setContributor("MBI"); parser.setArgumentPrefix("--", "-"); parser.addArgument("input", "i", mitkCommandLineParser::InputFile, "Input:", "input fiber bundle (.fib)", us::Any(), false); parser.addArgument("outFile", "o", mitkCommandLineParser::OutputFile, "Output:", "output fiber bundle (.fib)", us::Any(), false); parser.addArgument("smooth", "s", mitkCommandLineParser::Float, "Spline resampling:", "Resample fiber using splines with the given point distance (in mm)"); parser.addArgument("compress", "c", mitkCommandLineParser::Float, "Compress:", "Compress fiber using the given error threshold (in mm)"); parser.addArgument("minLength", "l", mitkCommandLineParser::Float, "Minimum length:", "Minimum fiber length (in mm)"); parser.addArgument("maxLength", "m", mitkCommandLineParser::Float, "Maximum length:", "Maximum fiber length (in mm)"); parser.addArgument("minCurv", "a", mitkCommandLineParser::Float, "Minimum curvature radius:", "Minimum curvature radius (in mm)"); parser.addArgument("mirror", "p", mitkCommandLineParser::Int, "Invert coordinates:", "Invert fiber coordinates XYZ (e.g. 010 to invert y-coordinate of each fiber point)"); parser.addArgument("rotate-x", "rx", mitkCommandLineParser::Float, "Rotate x-axis:", "Rotate around x-axis (if copy is given the copy is rotated, in deg)"); parser.addArgument("rotate-y", "ry", mitkCommandLineParser::Float, "Rotate y-axis:", "Rotate around y-axis (if copy is given the copy is rotated, in deg)"); parser.addArgument("rotate-z", "rz", mitkCommandLineParser::Float, "Rotate z-axis:", "Rotate around z-axis (if copy is given the copy is rotated, in deg)"); parser.addArgument("scale-x", "sx", mitkCommandLineParser::Float, "Scale x-axis:", "Scale in direction of x-axis (if copy is given the copy is scaled)"); parser.addArgument("scale-y", "sy", mitkCommandLineParser::Float, "Scale y-axis:", "Scale in direction of y-axis (if copy is given the copy is scaled)"); parser.addArgument("scale-z", "sz", mitkCommandLineParser::Float, "Scale z-axis", "Scale in direction of z-axis (if copy is given the copy is scaled)"); parser.addArgument("translate-x", "tx", mitkCommandLineParser::Float, "Translate x-axis:", "Translate in direction of x-axis (if copy is given the copy is translated, in mm)"); parser.addArgument("translate-y", "ty", mitkCommandLineParser::Float, "Translate y-axis:", "Translate in direction of y-axis (if copy is given the copy is translated, in mm)"); parser.addArgument("translate-z", "tz", mitkCommandLineParser::Float, "Translate z-axis:", "Translate in direction of z-axis (if copy is given the copy is translated, in mm)"); map parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.size()==0) return EXIT_FAILURE; float smoothDist = -1; if (parsedArgs.count("smooth")) smoothDist = us::any_cast(parsedArgs["smooth"]); float compress = -1; if (parsedArgs.count("compress")) compress = us::any_cast(parsedArgs["compress"]); float minFiberLength = -1; if (parsedArgs.count("minLength")) minFiberLength = us::any_cast(parsedArgs["minLength"]); float maxFiberLength = -1; if (parsedArgs.count("maxLength")) maxFiberLength = us::any_cast(parsedArgs["maxLength"]); float curvThres = -1; if (parsedArgs.count("minCurv")) curvThres = us::any_cast(parsedArgs["minCurv"]); int axis = 0; if (parsedArgs.count("mirror")) axis = us::any_cast(parsedArgs["mirror"]); float rotateX = 0; if (parsedArgs.count("rotate-x")) rotateX = us::any_cast(parsedArgs["rotate-x"]); float rotateY = 0; if (parsedArgs.count("rotate-y")) rotateY = us::any_cast(parsedArgs["rotate-y"]); float rotateZ = 0; if (parsedArgs.count("rotate-z")) rotateZ = us::any_cast(parsedArgs["rotate-z"]); float scaleX = 0; if (parsedArgs.count("scale-x")) scaleX = us::any_cast(parsedArgs["scale-x"]); float scaleY = 0; if (parsedArgs.count("scale-y")) scaleY = us::any_cast(parsedArgs["scale-y"]); float scaleZ = 0; if (parsedArgs.count("scale-z")) scaleZ = us::any_cast(parsedArgs["scale-z"]); float translateX = 0; if (parsedArgs.count("translate-x")) translateX = us::any_cast(parsedArgs["translate-x"]); float translateY = 0; if (parsedArgs.count("translate-y")) translateY = us::any_cast(parsedArgs["translate-y"]); float translateZ = 0; if (parsedArgs.count("translate-z")) translateZ = us::any_cast(parsedArgs["translate-z"]); string inFileName = us::any_cast(parsedArgs["input"]); string outFileName = us::any_cast(parsedArgs["outFile"]); try { mitk::FiberBundleX::Pointer fib = LoadFib(inFileName); if (minFiberLength>0) fib->RemoveShortFibers(minFiberLength); if (maxFiberLength>0) fib->RemoveLongFibers(maxFiberLength); if (curvThres>0) fib->ApplyCurvatureThreshold(curvThres, false); if (smoothDist>0) fib->ResampleSpline(smoothDist); if (compress>0) fib->Compress(compress); if (axis/100==1) fib->MirrorFibers(0); if ((axis%100)/10==1) fib->MirrorFibers(1); if (axis%10==1) fib->MirrorFibers(2); if (rotateX > 0 || rotateY > 0 || rotateZ > 0){ std::cout << "Rotate " << rotateX << " " << rotateY << " " << rotateZ; fib->RotateAroundAxis(rotateX, rotateY, rotateZ); } if (translateX > 0 || translateY > 0 || translateZ > 0){ fib->TranslateFibers(translateX, translateY, translateZ); } if (scaleX > 0 || scaleY > 0 || scaleZ > 0) fib->ScaleFibers(scaleX, scaleY, scaleZ); mitk::IOUtil::SaveBaseData(fib.GetPointer(), outFileName ); } catch (itk::ExceptionObject e) { std::cout << e; return EXIT_FAILURE; } catch (std::exception e) { std::cout << e.what(); return EXIT_FAILURE; } catch (...) { std::cout << "ERROR!?!"; return EXIT_FAILURE; } return EXIT_SUCCESS; } -RegisterDiffusionMiniApp(FiberProcessing);