20 #include <metaCommand.h>
23 #include <itkImageFileWriter.h>
25 #include <boost/lexical_cast.hpp>
30 #define _USE_MATH_DEFINES
38 int main(
int argc,
char* argv[])
42 parser.
setTitle(
"Fiber Direction Extraction");
43 parser.
setCategory(
"Fiber Tracking and Processing Methods");
44 parser.
setDescription(
"Extract principal fiber directions from a tractogram");
51 parser.
addArgument(
"athresh",
"a",
mitkCommandLineParser::Float,
"Angular threshold:",
"angular threshold in degrees. closer fiber directions are regarded as one direction and clustered together.", 25,
true);
57 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
58 if (parsedArgs.size()==0)
61 string fibFile =
us::any_cast<
string>(parsedArgs[
"input"]);
64 if (parsedArgs.count(
"mask"))
65 maskImage = us::any_cast<string>(parsedArgs[
"mask"]);
67 float peakThreshold = 0.2;
68 if (parsedArgs.count(
"peakthresh"))
69 peakThreshold = us::any_cast<float>(parsedArgs[
"peakthresh"]);
71 float angularThreshold = 25;
72 if (parsedArgs.count(
"athresh"))
73 angularThreshold = us::any_cast<float>(parsedArgs[
"athresh"]);
75 string outRoot =
us::any_cast<
string>(parsedArgs[
"out"]);
78 if (parsedArgs.count(
"verbose"))
79 verbose = us::any_cast<bool>(parsedArgs[
"verbose"]);
82 if (parsedArgs.count(
"numdirs"))
83 maxNumDirs = us::any_cast<int>(parsedArgs[
"numdirs"]);
85 bool normalize =
false;
86 if (parsedArgs.count(
"normalize"))
87 normalize = us::any_cast<bool>(parsedArgs[
"normalize"]);
91 typedef itk::Image<unsigned char, 3> ItkUcharImgType;
92 typedef itk::Image< itk::Vector< float, 3>, 3 > ItkDirectionImage3DType;
93 typedef itk::VectorContainer< unsigned int, ItkDirectionImage3DType::Pointer > ItkDirectionImageContainerType;
100 if (maskImage.compare(
"")!=0)
102 std::cout <<
"Using mask image";
110 fOdfFilter->SetFiberBundle(inputTractogram);
111 fOdfFilter->SetMaskImage(itkMaskImage);
112 fOdfFilter->SetAngularThreshold(cos(angularThreshold*
M_PI/180));
113 fOdfFilter->SetNormalizeVectors(normalize);
114 fOdfFilter->SetUseWorkingCopy(
false);
115 fOdfFilter->SetSizeThreshold(peakThreshold);
116 fOdfFilter->SetMaxNumDirections(maxNumDirs);
117 fOdfFilter->Update();
121 for (
unsigned int i=0; i<directionImageContainer->Size(); i++)
124 typedef itk::ImageFileWriter< itk::TractsToVectorImageFilter<float>::ItkDirectionImageType > WriterType;
127 string outfilename = outRoot;
128 outfilename.append(
"_DIRECTION_");
129 outfilename.append(boost::lexical_cast<string>(i));
130 outfilename.append(
".nrrd");
132 writer->SetFileName(outfilename.c_str());
133 writer->SetInput(itkImg);
142 string outfilename = outRoot;
143 outfilename.append(
"_VECTOR_FIELD.fib");
150 typedef itk::ImageFileWriter< ItkUcharImgType > WriterType;
153 string outfilename = outRoot;
154 outfilename.append(
"_NUM_DIRECTIONS.nrrd");
156 writer->SetFileName(outfilename.c_str());
157 writer->SetInput(numDirImage);
162 catch (itk::ExceptionObject e)
167 catch (std::exception e)
169 std::cout << e.what();
174 std::cout <<
"ERROR!?!";
itk::SmartPointer< Self > Pointer
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
static bool SaveBaseData(mitk::BaseData *data, const std::string &path)
SaveBaseData Convenience method to save arbitrary baseData.
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false)
Image class for storing images.
Base Class for Fiber Bundles;.
void setCategory(std::string category)
static mitk::DataNode::Pointer LoadDataNode(const std::string &path)
LoadDataNode Method to load an arbitrary DataNode.
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
void setTitle(std::string title)
void setDescription(std::string description)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.