23 #include <itksys/SystemTools.hxx>
25 #include "itkImageRegionIterator.h"
26 #include "itkImageFileReader.h"
29 template<
class D,
class T >
32 m_EstimateErrorImage(false),m_Sigma(-19191919),
34 m_NumIterations(1),m_ConfidenceThreshold(-19191919.0),
35 m_ConfidenceFuzzyness(0.0),m_MinPlausibleValue(1.0)
39 template<
class D,
class T >
50 std::locale originalLocale2 = myfile2.getloc();
54 sprintf(filename2,
"%s2",filename.c_str());
55 myfile2.open (filename2);
58 ifstream myfile (filename.c_str());
60 std::locale originalLocale = myfile.getloc();
65 while (! myfile.eof() )
67 getline (myfile,line);
68 itksys::SystemTools::ReplaceString(line,what.c_str(),with.c_str());
69 myfile2 << line << std::endl;
74 itksys::SystemTools::RemoveFile(filename.c_str());
75 rename(filename2,filename.c_str());
77 myfile.imbue( originalLocale );
78 myfile2.imbue( originalLocale2 );
82 template<
class D,
class T >
90 srand((
unsigned)time(0));
91 int random_integer = rand();
92 sprintf( filename,
"dwi_%d.nhdr",random_integer);
98 catch (itk::ExceptionObject e)
100 std::cout << e << std::endl;
107 sprintf( command,
"tend estim -i %s -B kvp -o tensors_%d.nhdr -knownB0 true",
108 filename, random_integer);
111 if(m_EstimateErrorImage)
113 sprintf( command,
"%s -ee error_image_%d.nhdr", command, random_integer);
116 if(m_Sigma != -19191919)
118 sprintf( command,
"%s -sigma %f", command, m_Sigma);
121 switch(m_EstimationMethod)
124 sprintf( command,
"%s -est lls", command);
127 sprintf( command,
"%s -est mle", command);
130 sprintf( command,
"%s -est nls", command);
133 sprintf( command,
"%s -est wls", command);
137 sprintf( command,
"%s -wlsi %d", command, m_NumIterations);
139 if(m_ConfidenceThreshold != -19191919.0)
141 sprintf( command,
"%s -t %f", command, m_ConfidenceThreshold);
144 sprintf( command,
"%s -soft %f", command, m_ConfidenceFuzzyness);
145 sprintf( command,
"%s -mv %f", command, m_MinPlausibleValue);
148 std::cout <<
"Calling <" << command <<
">" << std::endl;
149 int success = system(command);
152 MITK_ERROR <<
"system command could not be called!";
156 sprintf( filename,
"dwi_%d.raw", random_integer);
160 sprintf( filename,
"tensors_%d.nhdr", random_integer);
161 file_replace(filename,
"3D-masked-symmetric-matrix",
"vector");
164 typedef itk::ImageFileReader<VectorImageType> FileReaderType;
166 reader->SetFileName(filename);
171 sprintf( filename,
"tensors_%d.raw", random_integer);
175 itkTensorImage->SetSpacing( vecImage->GetSpacing() );
176 itkTensorImage->SetOrigin( vecImage->GetOrigin() );
177 itkTensorImage->SetDirection( vecImage->GetDirection() );
178 itkTensorImage->SetLargestPossibleRegion( vecImage->GetLargestPossibleRegion() );
179 itkTensorImage->SetBufferedRegion( vecImage->GetLargestPossibleRegion() );
180 itkTensorImage->SetRequestedRegion( vecImage->GetLargestPossibleRegion() );
181 itkTensorImage->Allocate();
183 itk::ImageRegionIterator<VectorImageType> it(vecImage,
184 vecImage->GetLargestPossibleRegion());
186 itk::ImageRegionIterator<ItkTensorImageType> it2(itkTensorImage,
187 itkTensorImage->GetLargestPossibleRegion());
192 for(it=it.Begin();!it.IsAtEnd(); ++it, ++it2)
199 tensor[i-1] = vec[i] * vec[0];
206 m_OutputItk->InitializeByItk(itkTensorImage.GetPointer());
207 m_OutputItk->SetVolume( itkTensorImage->GetBufferPointer() );
210 if(m_EstimateErrorImage)
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
itk::SmartPointer< Self > Pointer
itk::Vector< TensorPixelType, 7 > VectorType
TeemDiffusionTensor3DReconstructionImageFilter()
void file_replace(std::string filename, std::string what, std::string with)
itk::DiffusionTensor3D< TensorPixelType > TensorType
static const std::string filename
virtual ~TeemDiffusionTensor3DReconstructionImageFilter()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.