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

  • f09b485
  • /
  • tests
  • /
  • OxTestImage.hxx
Raw File Download
Permalinks

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
content badge Iframe embedding
swh:1:cnt:fef8f7dbdf1f7c6e7d0316f755556c71cdce4404
directory badge Iframe embedding
swh:1:dir:ef7d3738cbd07b4664a3ef264e4187e7ba4e4bba
Citations

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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
OxTestImage.hxx
/*!
 * \file OxTestImage.hxx
 * \author Konrad Werys
 * \date 2018/08/07
 */

#ifndef Tomato_OXTESTImage_HXX
#define Tomato_OXTESTImage_HXX


namespace Ox {

    template< typename MeasureType >
    TestImage<MeasureType>
    ::TestImage(int nRows, int nCols, std::vector <std::string> filesPaths, std::vector<int> invTimesOrder){
        init(nRows, nCols, filesPaths,  invTimesOrder);
    }

    template< typename MeasureType >
    TestImage<MeasureType>
    ::TestImage(int nRows, int nCols, std::vector <std::string> filesPaths){
        std::vector<int> invTimesOrder;
        init(nRows, nCols, filesPaths,  invTimesOrder);
    }

    template< typename MeasureType >
    int
    TestImage<MeasureType>
    ::init(int nRows, int nCols, std::vector <std::string> filesPaths, std::vector<int> invTimesOrder) {
        _nCols = nCols;
        _nRows = nRows;
        int nTissues = filesPaths.size();
        std::vector< TestData <MeasureType> > TestDataVector; // vector with TestData objects

        // I do want to have less 'tissues' (TestData objects) than Columns, just for the sake of simplicity
        if (nTissues > _nCols){
            throw std::runtime_error("Give me more nCols or less tissues");
        }

        // populate TestDataVector
        for (int i = 0; i < nTissues; ++i){
            TestDataVector.push_back(TestData<MeasureType>((char*)filesPaths.at(i).c_str()));
        }

        // check if invTimes are equal
        for (int i = 1; i < nTissues; ++i){
            if(!(TestDataVector.at(i).getInvTimes() == TestDataVector.at(i-1).getInvTimes())){
                throw std::runtime_error("InvTimes are different");
            }
        }
        std::vector<MeasureType> invTimesWithoutOrder = TestDataVector.at(0).getInvTimes();
        _nSamples = invTimesWithoutOrder.size();

        if (invTimesOrder.empty()){
            // _invTimes = 1,2,3, ... , nSamples
            invTimesOrder = std::vector<int>(_nSamples);
            for (int i = 0; i < _nSamples; ++i){
                invTimesOrder.at(i) = i;
            }
        }

        if (invTimesOrder.size() != _nSamples){
            throw std::runtime_error("invTimesOrder size is different than the input files nSamples");
        }

        _invTimes = std::vector <MeasureType>(_nSamples);
        for (int i = 0; i < _nSamples; ++i){
            _invTimes.at(i) = invTimesWithoutOrder.at(invTimesOrder.at(i));
        }

        _invTimesOrder = invTimesOrder;

        // allocate memory
        _imageMag = new MeasureType[_nCols*_nRows*_nSamples];
        _imagePha = new MeasureType[_nCols*_nRows*_nSamples];
        _imageResultsMolli = new MeasureType[_nRows*_nCols*3];
        _imageResultsShmolli = new MeasureType[_nRows*_nCols*3];

        // how to divide the memory?
        std::vector<int> ranges = KWUtil::bounds<int>(nTissues, _nCols);

//        std::cout << std::endl;
//        std::cout << std::endl;
//        for (int i = 0; i < ranges.size(); ++i ){
//            std::cout << ranges[i] << std::endl;
//        }

        // fill memory
        for (int iSample = 0; iSample < _nSamples; ++iSample){
            //for (int iCol = 0; iCol < _nCols; ++iCol) {
            for (int iRow = 0; iRow < _nRows; ++iRow) {
                for (int iTissue = 0; iTissue < ranges.size()-1; ++iTissue) {
                    //for (int iRow = ranges[iTissue]; iRow < ranges[iTissue+1]; ++iRow) {
                    for (int iCol = ranges[iTissue]; iCol < ranges[iTissue+1]; ++iCol) {
                        int invTimesIdx = _invTimesOrder.at(iSample);
                        //int index = iSample * (nRows * nCols) + iCol * nRows + iRow;
                        int index = iSample * (nRows * nCols) + iRow * nCols + iCol;
                        _imageMag[index] = TestDataVector.at(iTissue).getSignalMagPtr()[invTimesIdx];
                        _imagePha[index] = TestDataVector.at(iTissue).getSignalPhaPtr()[invTimesIdx];
                    }
                }
            }
        }

        for (int iDim = 0; iDim < 3; ++iDim){
            //for (int iCol = 0; iCol < _nCols; ++iCol) {
            for (int iRow = 0; iRow < _nRows; ++iRow) {
                for (int iTissue = 0; iTissue < ranges.size()-1; ++iTissue) {
                    //for (int iRow = ranges[iTissue]; iRow < ranges[iTissue+1]; ++iRow) {
                    for (int iCol = ranges[iTissue]; iCol < ranges[iTissue+1]; ++iCol) {
                        //int index = iDim * (nRows * nCols) + iCol * nRows + iRow;
                        int index = iDim * (nRows * nCols) + iRow * nCols + iCol;
                        _imageResultsMolli[index] = TestDataVector.at(iTissue).getResultsMolliPtr()[iDim];
                        _imageResultsShmolli[index] = TestDataVector.at(iTissue).getResultsShmolliPtr()[iDim];
                    }
                }
            }
        }
        return 0; // EXIT_SUCCESS
    }

    template< typename MeasureType >
    TestImage<MeasureType>
    ::~TestImage(){
        delete [] _imageMag;
        delete [] _imagePha;
        delete [] _imageResultsMolli;
        delete [] _imageResultsShmolli;

    }
    template< typename MeasureType >
    std::vector<MeasureType>
    TestImage<MeasureType>
    ::getInvTimes() const {
        return _invTimes;
    }

    template< typename MeasureType >
    MeasureType *
    TestImage<MeasureType>
    ::getInvTimesPtr()  {
        return &_invTimes.at(0);
    }


    template< typename MeasureType >
    MeasureType *
    TestImage<MeasureType>
    ::getImageMagPtr() const {
        return _imageMag;
    }

    template< typename MeasureType >
    MeasureType *
    TestImage<MeasureType>
    ::getImagePhaPtr() const {
        return _imagePha;
    }

    template< typename MeasureType >
    MeasureType *
    TestImage<MeasureType>
    ::getImageResultsMolliPtr() const {
        return _imageResultsMolli;
    }

    template< typename MeasureType >
    MeasureType *
    TestImage<MeasureType>
    ::getImageResultsShmolliPtr() const {
        return _imageResultsShmolli;
    }

} // namespace Ox



#endif //Tomato_OXTESTImage_HXX

Software Heritage — Copyright (C) 2015–2025, 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— Contact— JavaScript license information— Web API

back to top