164 lines
6.2 KiB
C++
164 lines
6.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include <limits>
|
|
|
|
#include "Function1D.h"
|
|
#include "MatlabReader.h"
|
|
#include "Matrix.h"
|
|
#include "transmissionReconstruction/reconstruction/buildMatrix/DGradient.h"
|
|
#include "transmissionReconstruction/reconstruction/buildMatrix/FMM.h"
|
|
#include "transmissionReconstruction/reconstruction/buildMatrix/buildMatrix.h"
|
|
#include "transmissionReconstruction/reconstruction/reconstruction.h"
|
|
|
|
|
|
|
|
|
|
inline double fourDecimalRound(double src){
|
|
return round(src*10000.0)/10000.0;
|
|
}
|
|
|
|
#define EXPECT_DOUBLE_AE(valueA,valueB)\
|
|
EXPECT_DOUBLE_EQ(fourDecimalRound(valueA),fourDecimalRound(valueB))
|
|
|
|
class Reconstruction_Test : public ::testing::Test {
|
|
protected:
|
|
static void SetUpReconstructionTester() {
|
|
|
|
}
|
|
|
|
static void TearDownTestCase() {
|
|
}
|
|
|
|
void SetUp() {
|
|
}
|
|
|
|
void TearDown() {
|
|
}
|
|
};
|
|
|
|
TEST_F(Reconstruction_Test, calculateMinimalMaximalTransducerPositions) {
|
|
auto senderList = Aurora::Matrix::fromRawData(new double[6]{1, 2, 3, 1, 2, 4}, 3, 2);
|
|
auto receiverList = Aurora::Matrix::fromRawData(new double[6]{1, 8, 3, 1, 2, 1}, 3, 2);
|
|
auto result = Recon::calculateMinimalMaximalTransducerPositions(senderList,receiverList);
|
|
EXPECT_DOUBLE_EQ(1.0,result.getData()[0]);
|
|
EXPECT_DOUBLE_EQ(2,result.getData()[1]);
|
|
EXPECT_DOUBLE_EQ(1.0,result.getData()[2]);
|
|
EXPECT_DOUBLE_EQ(1.0,result.getData()[3]);
|
|
EXPECT_DOUBLE_EQ(8,result.getData()[4]);
|
|
EXPECT_DOUBLE_EQ(4,result.getData()[5]);
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test, calculateResolution) {
|
|
auto ddims = Aurora::Matrix::fromRawData(new double[6]{-0.1296,-0.1296,0.0185,0.1296,0.1295,0.1682}, 1, 6);
|
|
auto dims = Aurora::Matrix::fromRawData(new double[3]{128,128,74}, 1, 3);
|
|
auto result = Recon::calculateResolution(ddims, dims);
|
|
EXPECT_DOUBLE_AE(0.0020,result[0]);
|
|
EXPECT_DOUBLE_AE(0.0020,result[1]);
|
|
EXPECT_DOUBLE_AE(0.0021,result[2]);
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test, getDimensions) {
|
|
auto ddims = Aurora::Matrix::fromRawData(new double[6]{-0.1296,-0.1296,0.0185,0.1296,0.1295,0.1682}, 1, 6);
|
|
double numPixelXY = 128;
|
|
auto result = Recon::getDimensions(numPixelXY,ddims);
|
|
EXPECT_DOUBLE_AE(128,result[0]);
|
|
EXPECT_DOUBLE_AE(128,result[1]);
|
|
EXPECT_DOUBLE_AE(74,result[2]);
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test, discretizePositions) {
|
|
auto senderList = Aurora::Matrix::fromRawData(new double[6]{1, 2, 3, 1, 2, 4}, 3, 2);
|
|
auto receiverList = Aurora::Matrix::fromRawData(new double[6]{1, 8, 3, 1, 2, 1}, 3, 2);
|
|
double numPixelXY = 128;
|
|
auto result = Recon::discretizePositions(senderList,receiverList,numPixelXY);
|
|
EXPECT_DOUBLE_AE(128,result.receiverCoordList[1]);
|
|
EXPECT_DOUBLE_AE(1,result.senderCoordList[1]);
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test, DGradient) {
|
|
MatlabReader m("/home/krad/TestData/DGradient.mat");
|
|
|
|
auto x = m.read("x");
|
|
auto y = m.read("y");
|
|
// x.forceReshape(x.getDataSize(), 1, 1);
|
|
auto result = Recon::DGradient(x,1,2);
|
|
for (size_t i = 0; i < result.getDataSize(); i++)
|
|
{
|
|
EXPECT_DOUBLE_AE(result.getData()[i],y.getData()[i])<<"index:"<<i;
|
|
}
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test, correctPath) {
|
|
auto path = Aurora::Matrix::fromRawData(new double[6]{1,1,10,9,1,1},2,3);
|
|
auto startPt = Aurora::Matrix::fromRawData(new double[3]{1, .5, 1}, 1, 3);
|
|
auto endPt = Aurora::Matrix::fromRawData(new double[3]{1, 10, 1}, 1, 3);
|
|
|
|
Recon::correctPath(path,startPt,endPt);
|
|
for (size_t i = 0; i < 10; i++)
|
|
{
|
|
EXPECT_DOUBLE_EQ(path[i],1.0);
|
|
EXPECT_DOUBLE_EQ(path[i+10],1.0+i);
|
|
EXPECT_DOUBLE_EQ(path[i+20],1.0);
|
|
}
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test,getPixelLengthApproximation){
|
|
auto startPt = Aurora::Matrix::fromRawData(new double[3]{1, 1, 1}, 1, 3);
|
|
auto endPt = Aurora::Matrix::fromRawData(new double[3]{4, 5, 6}, 1, 3);
|
|
auto res = Aurora::Matrix::fromRawData(new double[3]{.1, .1, .1}, 1, 3);
|
|
auto weight = Recon::getPixelLengthApproximation(startPt, endPt, res, 10);
|
|
EXPECT_DOUBLE_AE(weight[0],.0707);
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test,traceLine3D){
|
|
auto p1 = Aurora::Matrix::fromRawData(new double[3]{1, 10, 12}, 1, 3);
|
|
auto p2 = Aurora::Matrix::fromRawData(new double[3]{20, 2, 13}, 1, 3);
|
|
auto discretization = Aurora::Matrix::fromRawData(new double[3]{1, 1, 1}, 1, 3);
|
|
auto result = Recon::traceLine3D(p1, p2, discretization);
|
|
MatlabReader m("/home/krad/TestData/traceLine3D.mat");
|
|
|
|
auto path = m.read("path");
|
|
auto ds = m.read("ds");
|
|
for (size_t i = 0; i < result.path.getDataSize(); i++)
|
|
{
|
|
EXPECT_DOUBLE_AE(result.path.getData()[i],path[i])<<"index:"<<i;
|
|
}
|
|
for (size_t i = 0; i < result.ds.getDataSize(); i++)
|
|
{
|
|
EXPECT_DOUBLE_AE(result.ds.getData()[i],ds[i])<<"index:"<<i;
|
|
}
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test,traceStraightRay){
|
|
auto p1 = Aurora::Matrix::fromRawData(new double[3]{1, 1, 1}, 1, 3);
|
|
auto p2 = Aurora::Matrix::fromRawData(new double[3]{5, 6, 7}, 1, 3);
|
|
auto res = Aurora::Matrix::fromRawData(new double[3]{.1, .1, .1}, 1, 3);
|
|
auto dmis = Aurora::Matrix::fromRawData(new double[3]{5, 10, 20}, 1, 3);
|
|
auto result = Recon::traceStraightRay(p1, p2, res, dmis);
|
|
EXPECT_EQ(13, result.weighting.getDataSize());
|
|
EXPECT_DOUBLE_AE(result.weighting[0],0);
|
|
EXPECT_DOUBLE_AE(result.weighting[1],0.1462);
|
|
EXPECT_DOUBLE_AE(result.weighting[11],0.0292);
|
|
EXPECT_DOUBLE_AE(result.weighting[3],0.0439);
|
|
EXPECT_EQ(13, result.path.getDimSize(0));
|
|
EXPECT_EQ(3, result.path.getDimSize(1));
|
|
EXPECT_DOUBLE_AE(result.path[0],1);
|
|
EXPECT_DOUBLE_AE(result.path[15],2);
|
|
EXPECT_DOUBLE_AE(result.path[30],3);
|
|
EXPECT_EQ(13, result.pathLen);
|
|
}
|
|
|
|
TEST_F(Reconstruction_Test,traceStraightRayBresenham){
|
|
auto p1 = Aurora::Matrix::fromRawData(new double[3]{1, 1, 1}, 1, 3);
|
|
auto p2 = Aurora::Matrix::fromRawData(new double[3]{5, 6, 7}, 1, 3);
|
|
auto res = Aurora::Matrix::fromRawData(new double[3]{.1, .1, .1}, 1, 3);
|
|
auto result = Recon::traceStraightRayBresenham(p1, p2, res);
|
|
EXPECT_EQ(1, result.weighting.getDataSize());
|
|
EXPECT_DOUBLE_AE(result.weighting[0],0.1462);
|
|
EXPECT_EQ(6, result.path.getDimSize(0));
|
|
EXPECT_EQ(3, result.path.getDimSize(1));
|
|
EXPECT_DOUBLE_AE(result.path[0],1);
|
|
EXPECT_DOUBLE_AE(result.path[15],4);
|
|
EXPECT_DOUBLE_AE(result.path[7],2);
|
|
EXPECT_EQ(6, result.pathLen);
|
|
}
|