23 #include <itkImageFileWriter.h>
24 #include <itkMetaDataObject.h>
25 #include <itkVectorImage.h>
30 #include <boost/lexical_cast.hpp>
39 if( fibInfile.empty() )
40 std::cout <<
"File " << filename <<
" could not be read!";
48 int main(
int argc,
char* argv[])
53 parser.
setCategory(
"Fiber Tracking and Processing Methods");
54 parser.
setDescription(
"Modify input tractogram: fiber resampling, compression, pruning and transformation.");
81 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
82 if (parsedArgs.size()==0)
85 float smoothDist = -1;
86 if (parsedArgs.count(
"smooth"))
87 smoothDist = us::any_cast<float>(parsedArgs[
"smooth"]);
90 if (parsedArgs.count(
"compress"))
91 compress = us::any_cast<float>(parsedArgs[
"compress"]);
93 float minFiberLength = -1;
94 if (parsedArgs.count(
"minLength"))
95 minFiberLength = us::any_cast<float>(parsedArgs[
"minLength"]);
97 float maxFiberLength = -1;
98 if (parsedArgs.count(
"maxLength"))
99 maxFiberLength = us::any_cast<float>(parsedArgs[
"maxLength"]);
101 float maxAngularDev = -1;
102 if (parsedArgs.count(
"maxAngle"))
103 maxAngularDev = us::any_cast<float>(parsedArgs[
"maxAngle"]);
106 if (parsedArgs.count(
"mirror"))
107 axis = us::any_cast<int>(parsedArgs[
"mirror"]);
110 if (parsedArgs.count(
"rotate-x"))
111 rotateX = us::any_cast<float>(parsedArgs[
"rotate-x"]);
114 if (parsedArgs.count(
"rotate-y"))
115 rotateY = us::any_cast<float>(parsedArgs[
"rotate-y"]);
118 if (parsedArgs.count(
"rotate-z"))
119 rotateZ = us::any_cast<float>(parsedArgs[
"rotate-z"]);
122 if (parsedArgs.count(
"scale-x"))
123 scaleX = us::any_cast<float>(parsedArgs[
"scale-x"]);
126 if (parsedArgs.count(
"scale-y"))
127 scaleY = us::any_cast<float>(parsedArgs[
"scale-y"]);
130 if (parsedArgs.count(
"scale-z"))
131 scaleZ = us::any_cast<float>(parsedArgs[
"scale-z"]);
133 float translateX = 0;
134 if (parsedArgs.count(
"translate-x"))
135 translateX = us::any_cast<float>(parsedArgs[
"translate-x"]);
137 float translateY = 0;
138 if (parsedArgs.count(
"translate-y"))
139 translateY = us::any_cast<float>(parsedArgs[
"translate-y"]);
141 float translateZ = 0;
142 if (parsedArgs.count(
"translate-z"))
143 translateZ = us::any_cast<float>(parsedArgs[
"translate-z"]);
146 string inFileName =
us::any_cast<
string>(parsedArgs[
"input"]);
147 string outFileName =
us::any_cast<
string>(parsedArgs[
"outFile"]);
153 if (minFiberLength>0)
154 fib->RemoveShortFibers(minFiberLength);
156 if (maxFiberLength>0)
157 fib->RemoveLongFibers(maxFiberLength);
162 filter->SetInputFiberBundle(fib);
163 filter->SetAngularDeviation(maxAngularDev);
164 filter->SetDistance(10);
165 filter->SetRemoveFibers(
true);
167 fib = filter->GetOutputFiberBundle();
171 fib->ResampleSpline(smoothDist);
174 fib->Compress(compress);
177 fib->MirrorFibers(0);
179 if ((axis%100)/10==1)
180 fib->MirrorFibers(1);
183 fib->MirrorFibers(2);
186 if (rotateX > 0 || rotateY > 0 || rotateZ > 0){
187 std::cout <<
"Rotate " << rotateX <<
" " << rotateY <<
" " << rotateZ;
188 fib->RotateAroundAxis(rotateX, rotateY, rotateZ);
190 if (translateX > 0 || translateY > 0 || translateZ > 0){
191 fib->TranslateFibers(translateX, translateY, translateZ);
193 if (scaleX > 0 || scaleY > 0 || scaleZ > 0)
194 fib->ScaleFibers(scaleX, scaleY, scaleZ);
199 catch (itk::ExceptionObject e)
204 catch (std::exception e)
206 std::cout << e.what();
211 std::cout <<
"ERROR!?!";
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)
static const std::string filename
Base Class for Fiber Bundles;.
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
int main(int argc, char *argv[])
Modify input tractogram: fiber resampling, compression, pruning and transformation.
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
void setTitle(std::string title)
void setDescription(std::string description)
mitk::FiberBundle::Pointer LoadFib(std::string filename)