From fe84729646a3197584853bfd6f7fd4400ab26962 Mon Sep 17 00:00:00 2001 From: sunwen Date: Thu, 8 Jun 2023 15:26:13 +0800 Subject: [PATCH] Add meshgrid and unitTest. --- src/common/meshgrid.cpp | 27 +++++++++++++++++++++++++++ src/common/meshgrid.h | 18 ++++++++++++++++++ test/Common_Test.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/common/meshgrid.cpp create mode 100644 src/common/meshgrid.h diff --git a/src/common/meshgrid.cpp b/src/common/meshgrid.cpp new file mode 100644 index 0000000..1097891 --- /dev/null +++ b/src/common/meshgrid.cpp @@ -0,0 +1,27 @@ +#include "meshgrid.h" +#include "Function1D.h" +#include "Matrix.h" + +using namespace Aurora; +using namespace Recon; + +MeshgridResult Recon::meshgrid(const Aurora::Matrix& aX, const Aurora::Matrix& aY, const Aurora::Matrix& aZ) +{ + MeshgridResult result; + if(aX.isNull() || aY.isNull() || aZ.isNull()) + { + return result; + } + + size_t nx = aX.getDataSize(); + size_t ny = aY.getDataSize(); + size_t nz = aZ.getDataSize(); + Matrix xx = reshape(aX, 1, nx, 1); + Matrix yy = reshape(aY, ny, 1, 1); + Matrix zz = reshape(aZ, 1, 1, nz); + result.xx = repmat(xx, ny, 1, nz); + result.yy = repmat(yy, 1, nx, nz); + result.zz = repmat3d(zz, ny, nx, 1); + + return result; +} \ No newline at end of file diff --git a/src/common/meshgrid.h b/src/common/meshgrid.h new file mode 100644 index 0000000..d04f24d --- /dev/null +++ b/src/common/meshgrid.h @@ -0,0 +1,18 @@ +#ifndef MESHGRID_H +#define MESHGRID_H + +#include "Matrix.h" + +namespace Recon +{ + struct MeshgridResult + { + Aurora::Matrix xx; + Aurora::Matrix yy; + Aurora::Matrix zz; + }; + + MeshgridResult meshgrid(const Aurora::Matrix& aX, const Aurora::Matrix& aY, const Aurora::Matrix& aZ); +} + +#endif \ No newline at end of file diff --git a/test/Common_Test.cpp b/test/Common_Test.cpp index ae57731..b7a712d 100644 --- a/test/Common_Test.cpp +++ b/test/Common_Test.cpp @@ -9,6 +9,7 @@ #include "common/dataBlockCreation/getAscanBlock.h" #include "common/dataBlockCreation/blockingGeometryInfo.h" #include "common/dataBlockCreation/removeDataFromArrays.h" +#include "common/meshgrid.h" #include "Parser.h" #include "MatlabReader.h" @@ -340,3 +341,32 @@ TEST_F(Common_Test, removeDataFromArrays) { EXPECT_DOUBLE_EQ(result[2], 5); EXPECT_DOUBLE_EQ(result[3], 6); } + +TEST_F(Common_Test, meshgrid) { + MatlabReader m("/home/sun/testData/meshgrid.mat"); + auto x = m.read("x"); + auto y = m.read("y"); + auto z = m.read("z"); + auto result = Recon::meshgrid(x, y, z); + auto xx = m.read("xx"); + auto yy = m.read("yy"); + auto zz = m.read("zz"); + + EXPECT_DOUBLE_AE(xx.getDataSize(), result.xx.getDataSize()); + for(int i=0; i