Add convertToLinearIndices to common
This commit is contained in:
@@ -52,4 +52,32 @@ namespace Recon
|
|||||||
// Data2 = ifft(Data2, [], 1);
|
// Data2 = ifft(Data2, [], 1);
|
||||||
return Aurora::Matrix();
|
return Aurora::Matrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Aurora::Matrix convertToLinearIndices(Aurora::Matrix aVMatrixSize, Aurora::Matrix aMCoordinates)
|
||||||
|
{
|
||||||
|
if (aVMatrixSize.getDataSize() != aMCoordinates.getDimSize(1)){
|
||||||
|
std::cerr<<"convertToLinearIndices fail, Dimension of coordinates and matrix do not fit."<<std::endl;
|
||||||
|
return Aurora::Matrix();
|
||||||
|
}
|
||||||
|
size_t columns = aMCoordinates.getDimSize(1);
|
||||||
|
auto coord_col1= aMCoordinates(Aurora::$,0).toMatrix();
|
||||||
|
auto coord_col2Sub1= aMCoordinates(Aurora::$,1).toMatrix()-1;
|
||||||
|
auto matrixSize_1 = aVMatrixSize.getData()[0];
|
||||||
|
switch (columns) {
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
auto matrixSize_2 = aVMatrixSize.getData()[1];
|
||||||
|
auto coord_col3Sub1= aMCoordinates(Aurora::$,2).toMatrix()-1;
|
||||||
|
return coord_col1 + coord_col2Sub1 * matrixSize_1 + coord_col3Sub1 * matrixSize_1 * matrixSize_2;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
return coord_col1 + coord_col2Sub1 * matrixSize_1;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
std::cerr<<"convertToLinearIndices fail,NotImplemented, Converting into linear indices only implemented for 2D and 3D matrices."<<std::endl;
|
||||||
|
return Aurora::Matrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ namespace Recon {
|
|||||||
*/
|
*/
|
||||||
Aurora::Matrix reconstructBandpasssubsampling(Aurora::Matrix aMatrix, double aAScanReconstructionFreq, double SampleRate);
|
Aurora::Matrix reconstructBandpasssubsampling(Aurora::Matrix aMatrix, double aAScanReconstructionFreq, double SampleRate);
|
||||||
|
|
||||||
|
Aurora::Matrix convertToLinearIndices(Aurora::Matrix aVMatrixSize, Aurora::Matrix aMCoordinates);
|
||||||
}
|
}
|
||||||
#endif //RECON_COMMON_H
|
#endif //RECON_COMMON_H
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "common/ceMatchedFilterHandling.h"
|
#include "common/ceMatchedFilterHandling.h"
|
||||||
|
#include "common/common.h"
|
||||||
#include "common/convertfp16tofloat.h"
|
#include "common/convertfp16tofloat.h"
|
||||||
#include "MatlabReader.h"
|
#include "MatlabReader.h"
|
||||||
|
|
||||||
@@ -56,3 +57,29 @@ TEST_F(Common_Test, convertfp16tofloat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(Common_Test, convertToLinearIndices) {
|
||||||
|
//2D
|
||||||
|
{
|
||||||
|
double *dataA = new double[6]{1, 9, 4, 0, .01, 1.9};
|
||||||
|
auto A = Aurora::Matrix::fromRawData(dataA, 3, 2);
|
||||||
|
double *dataB = new double[2]{3, 2};
|
||||||
|
auto B = Aurora::Matrix::fromRawData(dataB, 2, 1);
|
||||||
|
auto output =Recon::convertToLinearIndices(B,A);
|
||||||
|
EXPECT_DOUBLE_AE(-2,output.getData()[0]);
|
||||||
|
EXPECT_DOUBLE_AE(6.03,output.getData()[1]);
|
||||||
|
EXPECT_DOUBLE_AE(6.7,output.getData()[2]);
|
||||||
|
}
|
||||||
|
//3D
|
||||||
|
{
|
||||||
|
double *dataA = new double[12]{1, 9, 4, 0, .01, 1.9, 1, 9, 4, 0, .01, 1.9};
|
||||||
|
auto A = Aurora::Matrix::fromRawData(dataA, 2, 3, 2);
|
||||||
|
double *dataB = new double[3]{3, 2, 2};
|
||||||
|
auto B = Aurora::Matrix::fromRawData(dataB, 3, 1);
|
||||||
|
auto output =Recon::convertToLinearIndices(B,A);
|
||||||
|
EXPECT_DOUBLE_AE(4.06,output.getData()[0]);
|
||||||
|
EXPECT_DOUBLE_AE(11.4,output.getData()[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user