7 #ifndef Tomato_Tomato_HXX 8 #define Tomato_Tomato_HXX 10 #include "CmakeConfigForTomato.h" 15 template<
typename MeasureType >
17 ::Tomato(std::string inputFileName){
23 _opts =
new TomatoOptions<InputPixelType>(inputFileName);
24 _imageCalculatorItk = CalculatorT1ImageFilterType::New();
29 template<
typename MeasureType >
37 template<
typename MeasureType >
42 typename ReadFileListFilterType::Pointer readerMag = ReadFileListFilterType::New();
43 readerMag->SetFileList(_opts->files_magnitude);
44 readerMag->SetDirName(_opts->dir_magnitude);
48 if (readerMag->GetInvTimes().empty()){
49 throw std::runtime_error(
"\nNo magnitude images read, check the paths!");
52 if (_opts->files_magnitude.empty()){
53 _opts->files_magnitude = readerMag->GetFileList();
56 typename SortInvTimesImageFilterType::Pointer sorterMag = SortInvTimesImageFilterType::New();
57 sorterMag->SetInvTimesNonSorted(readerMag->GetInvTimes());
58 sorterMag->SetEchoTimesNonSorted(readerMag->GetEchoTimes());
59 sorterMag->SetInput(readerMag->GetOutput());
60 if (_opts->parameter_type == T1) {
61 sorterMag->SortByInvTimes();
62 }
else if (_opts->parameter_type == T2){
63 sorterMag->SortByEchoTimes();
67 typename ReadFileListFilterType::Pointer readerPha = ReadFileListFilterType::New();
68 readerPha->SetFileList(_opts->files_phase);
69 readerPha->SetDirName(_opts->dir_phase);
73 if (readerPha->GetInvTimes().empty()) {
74 if (_opts->sign_calc_method != NoSign){
75 std::cerr <<
"\nNo phase images read, setting the sign_calc_method to NoSign" << std::endl;
76 _opts->sign_calc_method = NoSign;
80 if (_opts->files_phase.empty()){
81 _opts->files_phase = readerPha->GetFileList();
84 typename SortInvTimesImageFilterType::Pointer sorterPha = SortInvTimesImageFilterType::New();
85 if (_opts->sign_calc_method != NoSign) {
86 sorterPha->SetInvTimesNonSorted(readerPha->GetInvTimes());
87 sorterPha->SetEchoTimesNonSorted(readerMag->GetEchoTimes());
88 sorterPha->SetInput(readerPha->GetOutput());
89 if (_opts->parameter_type == T1) {
90 sorterPha->SortByInvTimes();
91 }
else if (_opts->parameter_type == T2){
92 sorterPha->SortByEchoTimes();
98 if (_opts->sign_calc_method != NoSign) {
99 if (sorterMag->GetInvTimesSorted() != sorterPha->GetInvTimesSorted()) {
100 throw std::runtime_error(
"\nMag and Pha inv times are not equal");
104 vnl_vector<InputPixelType > tempInv = sorterMag->GetInvTimesSorted();
105 _nSamples = (int)tempInv.size();
106 _invTimes =
new InputPixelType[_nSamples];
107 KWUtil::copyArrayToArray(_nSamples, _invTimes, tempInv.data_block());
109 if (_opts->inversion_times.empty()){
110 tempInv = sorterMag->GetInvTimesNonSorted();
111 _opts->inversion_times = std::vector<InputPixelType >(tempInv.begin(), tempInv.end());
114 vnl_vector<InputPixelType > tempEcho = sorterMag->GetEchoTimesSorted();
115 _nSamples = (int)tempEcho.size();
116 _echoTimes =
new InputPixelType[_nSamples];
117 KWUtil::copyArrayToArray(_nSamples, _echoTimes, tempEcho.data_block());
119 if (_opts->echo_times.empty()){
120 tempEcho = sorterMag->GetEchoTimesNonSorted();
121 _opts->echo_times = std::vector<InputPixelType >(tempEcho.begin(), tempEcho.end());
124 _dictionaryInput = readerMag->GetDicomIO()->GetMetaDataDictionary();
125 _imageMag = sorterMag->GetOutput();
126 if (_opts->sign_calc_method != NoSign) {
127 _imagePha = sorterPha->GetOutput();
133 template<
typename MeasureType >
139 Calculator<InputPixelType> *calculator = FactoryOfCalculators<InputPixelType>::newByFactory(_opts);
140 Model<InputPixelType> *model = FactoryOfModels<InputPixelType>::newByFactory(_opts);
141 Fitter<InputPixelType> *fitter = FactoryOfFitters<InputPixelType>::newByFactory(_opts);
142 SignCalculator<InputPixelType> *signCalculator = FactoryOfSignCalculators<InputPixelType>::newByFactory(_opts);
143 StartPointCalculator<InputPixelType> *startPointCalculator = FactoryOfStartPointCalculators<InputPixelType>::newByFactory(_opts);
146 calculator->setModel(model);
147 calculator->setFitter(fitter);
148 calculator->setSignCalculator(signCalculator);
149 calculator->setStartPointCalculator(startPointCalculator);
150 calculator->setInvTimes(_invTimes);
151 calculator->setEchoTimes(_echoTimes);
152 if (_opts->noise.size() > 0){
153 calculator->setNoise(&(_opts->noise)[0]);
155 calculator->setNSamples(_nSamples);
160 _imageCalculatorItk->SetInputMagImage(_imageMag);
161 _imageCalculatorItk->SetInputPhaImage(_imagePha);
162 if (_opts->number_of_threads > 0)
163 _imageCalculatorItk->SetNumberOfThreads(_opts->number_of_threads);
164 _imageCalculatorItk->SetCalculator(calculator);
167 itk::TimeProbe clock;
170 _imageCalculatorItk->Update();
171 }
catch( itk::ExceptionObject & err ) {
172 std::cerr <<
"ExceptionObject caught !" << std::endl;
173 std::cerr << err << std::endl;
176 _opts->calculation_time = clock.GetTotal();
177 printf(
"Calculation time: %.4fs.\n", clock.GetTotal());
181 delete signCalculator;
182 delete startPointCalculator;
188 template<
typename MeasureType >
192 if (_opts->parameter_type == Ox::T1){
194 exportT1MagSignRecovToDicom();
197 else if (_opts->parameter_type == Ox::T2){
198 return exportT2ToDicom();
201 std::cerr <<
"Tomato::exportToDicom: Export has not been implemented" << std::endl;
206 template<
typename IType,
typename EType >
207 class CastPixelAccessor
211 typedef IType InternalType;
212 typedef EType ExternalType;
214 static void Set(InternalType & output,
const ExternalType & input)
216 output =
static_cast<InternalType
>( input );
219 static ExternalType Get(
const InternalType & input )
221 return static_cast<ExternalType
>( input );
229 #endif //Tomato_Tomato_H Definition: OxCalculator.h:19