Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:e6d42e6731ce66e3c09de07ac49964c03139e990
  • Code
  • Branches (11)
  • Releases (5)
    • Branches
    • Releases
    • HEAD
    • refs/heads/T2
    • refs/heads/develop
    • refs/heads/developCI
    • refs/heads/developCI2
    • refs/heads/developCI3
    • refs/heads/gh-pages
    • refs/heads/master
    • refs/heads/newBuild
    • refs/tags/v0.1
    • refs/tags/v0.11
    • refs/tags/v0.4
    • v0.4.3
    • v0.4.2
    • v0.4.1
    • v0.3
    • v0.2
  • 8a4e5a9
  • /
  • app
  • /
  • Tomato.hxx
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
content badge
swh:1:cnt:0bc10ef3980d213db5c2820195bae7d08bba08ae
directory badge
swh:1:dir:f2e8799163c708ce94ba0700f39fa7ff0fd48271
revision badge
swh:1:rev:c6d23f52bf7d7de2698a41518f6c2638decc9d6b
snapshot badge
swh:1:snp:e6d42e6731ce66e3c09de07ac49964c03139e990

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: c6d23f52bf7d7de2698a41518f6c2638decc9d6b authored by Konrad Werys on 26 October 2018, 15:54:52 UTC
minor changes
Tip revision: c6d23f5
Tomato.hxx
/*!
 * \file Tomato.h
 * \author Konrad Werys
 * \date 2018/08/14
 */

#ifndef Tomato_Tomato_HXX
#define Tomato_Tomato_HXX

#include "CmakeConfigForTomato.h"
#ifdef USE_ITK

namespace Ox {

    template< typename MeasureType >
    Tomato<MeasureType>
    ::Tomato(std::string inputFileName){

        _nSamples = 0;
        _invTimes = 0; // nullptr
        _echoTimes = 0; // nullptr

        _opts = new TomatoOptions<InputPixelType>(inputFileName);
        _imageCalculatorItk = CalculatorT1ImageFilterType::New();
        //_sorterMag = SortInvTimesImageFilterType::New();
        //_sorterPha = SortInvTimesImageFilterType::New();
    }

    template< typename MeasureType >
    Tomato<MeasureType>
    ::~Tomato(){
        delete _opts;
        delete [] _invTimes;
        delete [] _echoTimes;
    }

    template< typename MeasureType >
    int
    Tomato<MeasureType>
    ::readAndSort(){
        typename ReadFileListFilterType::Pointer readerMag = ReadFileListFilterType::New();
        readerMag->SetFileList(_opts->files_magnitude);
        readerMag->Update();

        typename ReadFileListFilterType::Pointer readerPha = ReadFileListFilterType::New();
        readerPha->SetFileList(_opts->files_phase);
        readerPha->Update();

        typename SortInvTimesImageFilterType::Pointer sorterMag = SortInvTimesImageFilterType::New();
        sorterMag->SetInvTimesNonSorted(readerMag->GetInvTimes());
        sorterMag->SetInput(readerMag->GetOutput());
        sorterMag->Update();

        typename SortInvTimesImageFilterType::Pointer sorterPha = SortInvTimesImageFilterType::New();
        sorterPha->SetInvTimesNonSorted(readerPha->GetInvTimes());
        sorterPha->SetInput(readerPha->GetOutput());
        sorterPha->Update();

        if (sorterMag->GetInvTimesSorted() == sorterPha->GetInvTimesSorted()){
            vnl_vector<InputPixelType > temp = sorterMag->GetInvTimesSorted();
            _nSamples = temp.size();
            _invTimes = new InputPixelType[_nSamples];
            KWUtil::copyArrayToArray(_nSamples, _invTimes, temp.data_block());
        } else {
            throw std::runtime_error("Mag and Pha inv times are not equal");
        }

        _dictionaryInput = readerMag->GetDicomIO()->GetMetaDataDictionary();
        _imageMag = sorterMag->GetOutput();
        _imagePha = sorterPha->GetOutput();

        return 0; // EXIT_SUCCESS
    }

    template< typename MeasureType >
    int
    Tomato<MeasureType>
    ::calculate() {

        // alloc and init
        CalculatorT1<InputPixelType> *calculatorT1 = FactoryOfCalculators<InputPixelType>::newByFactory(_opts);
        FunctionsT1<InputPixelType> *functionsT1 = FactoryOfFunctions<InputPixelType>::newByFactory(_opts);
        Fitter<InputPixelType> *fitter = FactoryOfFitters<InputPixelType>::newByFactory(_opts);
        SignCalculator<InputPixelType> *signCalculator = FactoryOfSignCalculators<InputPixelType>::newByFactory(_opts);
        StartPointCalculator<InputPixelType> *startPointCalculator = FactoryOfStartPointCalculators<InputPixelType>::newByFactory(_opts);

        // configure calculator
        calculatorT1->setFunctionsT1(functionsT1);
        calculatorT1->setFitter(fitter);
        calculatorT1->setSignCalculator(signCalculator);
        calculatorT1->setStartPointCalculator(startPointCalculator);
        calculatorT1->setInvTimes(_invTimes);
        calculatorT1->setNSamples(_nSamples);

        // configure calculator itk filter
        //CalculatorT1ImageFilterType::Pointer _imageCalculatorItk = CalculatorT1ImageFilterType::New();
        //_imageCalculatorItk = CalculatorT1ImageFilterType::New();
        _imageCalculatorItk->SetInputMagImage(_imageMag);
        _imageCalculatorItk->SetInputPhaImage(_imagePha);
        if (_opts->number_of_threads > 0)
            _imageCalculatorItk->SetNumberOfThreads(_opts->number_of_threads);
        _imageCalculatorItk->SetCalculator(calculatorT1);

        // calculations
        itk::TimeProbe clock;
        clock.Start();
        try {
            _imageCalculatorItk->Update();
        } catch( itk::ExceptionObject & err ) {
            std::cerr << "ExceptionObject caught !" << std::endl;
            std::cerr << err << std::endl;
        }
        clock.Stop();
        printf("Calculation time: %.4fs.\n", clock.GetTotal());

        delete functionsT1;
        delete fitter;
        delete signCalculator;
        delete startPointCalculator;
        delete calculatorT1;

        return 0; // EXIT_SUCCESS
    }

    template< typename MeasureType >
    int
    Tomato<MeasureType>
    ::visualise(){

#ifdef USE_VTK

        // visual presentation of the results
        if (_opts->visualise) {

            // OxColorbarImageFilter
            typedef itk::Colorbar2DImageFilter< ImageType2D > ColorbarImageFilterType;
            typename ColorbarImageFilterType::Pointer ColorbarFilter = ColorbarImageFilterType::New();
            ColorbarFilter->SetInput(_imageCalculatorItk->GetT1Image());

            QuickView viewer;
            viewer.AddImage(_imageCalculatorItk->GetT1Image(), true, "T1");
            viewer.AddImage(ColorbarFilter->GetOutput(), true, "T1 with colorbar");
            viewer.AddImage(_imageCalculatorItk->GetR2Image(), true, "R2");
            viewer.AddImage(_imageCalculatorItk->GetAImage(), true, "A");
            viewer.AddImage(_imageCalculatorItk->GetBImage(), true, "B");
            viewer.AddImage(_imageCalculatorItk->GetT1starImage(), true, "T1*");
            viewer.AddImage(_imageCalculatorItk->GetChiSqrtImage(), true, "ChiSqrt");
            viewer.AddImage(_imageCalculatorItk->GetSNRImage(), true, "SNR");
            viewer.AddImage(_imageCalculatorItk->GetNShmolliSamplesUsedImage(), true, "Number of Samples used in reconstruction");
            viewer.AddImage(_imageCalculatorItk->GetSD_AImage(), true, "SD A");
            viewer.AddImage(_imageCalculatorItk->GetSD_BImage(), true, "SD B");
            viewer.AddImage(_imageCalculatorItk->GetSD_T1Image(), true, "SD T1");
            //viewer.SetViewPortSize(500);
            viewer.Visualize();
        }

#else // USE_VTK
        printf("Visualisation not possible: the project was configured not to use VTK. Install VTK and reconfigure the project in CMake.");
        //throw itk::ExceptionObject(__FILE__, __LINE__, "Visualisation not possible: the project was configured not to use VTK. Install VTK and reconfigure the project in CMake.");
#endif // USE_VTK

        return 0; // EXIT_SUCCESS
    }

} // namespace Ox

#endif

#endif //Tomato_Tomato_H

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API