From 79aea085ce01062754db9c965feea4b5e78540f5 Mon Sep 17 00:00:00 2001 From: Adrian Schneider Date: Sun, 6 Aug 2023 20:23:23 +0200 Subject: [PATCH] Add volume tests, import tests --- dicom2mesh/src/dicom2mesh.cpp | 14 +++++++------- dicom2mesh/test/t_d2m.cpp | 36 +++++++++++++++++++++++++++++++++++ lib/inc/volumeVisualizer.h | 16 +++++++--------- lib/src/volumeVisualizer.cpp | 10 ++++++++++ lib/test/t_volume.cpp | 26 +++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 lib/test/t_volume.cpp diff --git a/dicom2mesh/src/dicom2mesh.cpp b/dicom2mesh/src/dicom2mesh.cpp index a2fbde1..796989a 100644 --- a/dicom2mesh/src/dicom2mesh.cpp +++ b/dicom2mesh/src/dicom2mesh.cpp @@ -21,6 +21,13 @@ ** *****************************************************************************/ +#include +#include +#include +#include +#include +#include + #include "dicom2mesh.h" #include "meshRoutines.h" #include "meshData.h" @@ -29,13 +36,6 @@ #include "meshVisualizer.h" #include "volumeVisualizer.h" -#include -#include -#include -#include -#include -#include - // Note: In order to safe memory, smart-pointers were not used for certain // objects. This has the advantage that memory blocks can be released // within the function body. diff --git a/dicom2mesh/test/t_d2m.cpp b/dicom2mesh/test/t_d2m.cpp index ef54f8f..92b90b6 100644 --- a/dicom2mesh/test/t_d2m.cpp +++ b/dicom2mesh/test/t_d2m.cpp @@ -62,6 +62,42 @@ TEST(D2M, MakeSimpleMesh) } } +TEST(D2M, ImportSimpleMesh) +{ + std::vector fnames{"testObj.obj", "testPly.ply", "testStl.stl"}; + + for( auto fn: fnames ) + { + // create file fn + Dicom2Mesh::Dicom2MeshParameters settings = getPresetImageSettings(); + settings.outputFilePath = fn; + settings.isoValue = 100; + Dicom2Mesh* d2m = new Dicom2Mesh(settings); + int retCode = d2m->doMesh(); + delete d2m; + + ASSERT_EQ(retCode, 0); + ASSERT_GT(filesize(fn), 0); + ASSERT_TRUE(fexists(fn)); + + // now import it again and safe as, whatever, obj + std::string exportFilePath = "importtest.obj"; + Dicom2Mesh::Dicom2MeshParameters importSettings; + importSettings.pathToInputData = fn; + importSettings.outputFilePath = exportFilePath; + Dicom2Mesh* d2mImport = new Dicom2Mesh(importSettings); + retCode = d2mImport->doMesh(); + delete d2mImport; + ASSERT_EQ(retCode, 0); + ASSERT_GT(filesize(exportFilePath), 0); + ASSERT_TRUE(fexists(exportFilePath)); + + + remove(fn.c_str()); + remove(exportFilePath.c_str()); + } +} + TEST(D2M, MakeCenterMesh) { std::vector fnames{"testObj.obj", "testPly.ply", "testStl.stl"}; diff --git a/lib/inc/volumeVisualizer.h b/lib/inc/volumeVisualizer.h index 82a8bb5..eb657cd 100644 --- a/lib/inc/volumeVisualizer.h +++ b/lib/inc/volumeVisualizer.h @@ -32,23 +32,21 @@ class VolumeRenderingColoringEntry { public: - VolumeRenderingColoringEntry(){} - VolumeRenderingColoringEntry(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha, int voxelValue) : - m_red(red), m_green(green), m_blue(blue), m_alpha(alpha), m_voxelValue(voxelValue) - {} + VolumeRenderingColoringEntry(); + VolumeRenderingColoringEntry(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha, int voxelValue); /* * The color and transparency */ - unsigned char m_red = 255u; - unsigned char m_green = 255u; - unsigned char m_blue = 255u; - unsigned char m_alpha = 128u; + unsigned char m_red; + unsigned char m_green; + unsigned char m_blue; + unsigned char m_alpha; /* * The voxel value, to which the color is applied */ - int m_voxelValue = 0; + int m_voxelValue; }; class VTKVolumeVisualizer diff --git a/lib/src/volumeVisualizer.cpp b/lib/src/volumeVisualizer.cpp index 7b66dba..84d52a9 100644 --- a/lib/src/volumeVisualizer.cpp +++ b/lib/src/volumeVisualizer.cpp @@ -32,6 +32,16 @@ #include #include +VolumeRenderingColoringEntry::VolumeRenderingColoringEntry() : VolumeRenderingColoringEntry(255u, 255u, 255u, 128u, 0) +{ +} + +VolumeRenderingColoringEntry::VolumeRenderingColoringEntry(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha, int voxelValue) : +m_red(red), m_green(green), m_blue(blue), m_alpha(alpha), m_voxelValue(voxelValue) +{ +} + + // Code based on examples from: // https://www.vtk.org/Wiki/VTK/Examples/Cxx/VolumeRendering/SmartVolumeMapper // https://www.vtk.org/Wiki/VTK/Examples/Cxx/Medical/MedicalDemo4 diff --git a/lib/test/t_volume.cpp b/lib/test/t_volume.cpp new file mode 100644 index 0000000..e9d4047 --- /dev/null +++ b/lib/test/t_volume.cpp @@ -0,0 +1,26 @@ +#include +#include +#include "volumeVisualizer.h" + +TEST(VolumeEntry, DefaultCtor) +{ + VolumeRenderingColoringEntry* defaultEntry = new VolumeRenderingColoringEntry(); + ASSERT_EQ(defaultEntry->m_red, 255u); + ASSERT_EQ(defaultEntry->m_green, 255u); + ASSERT_EQ(defaultEntry->m_blue, 255u); + ASSERT_EQ(defaultEntry->m_alpha, 128u); + ASSERT_EQ(defaultEntry->m_voxelValue, 0); + delete defaultEntry; +} + +TEST(VolumeEntry, Ctor) +{ + VolumeRenderingColoringEntry* defaultEntry = new VolumeRenderingColoringEntry(1u, 2u, 3u, 4u, 5); + ASSERT_EQ(defaultEntry->m_red, 1u); + ASSERT_EQ(defaultEntry->m_green, 2u); + ASSERT_EQ(defaultEntry->m_blue, 3u); + ASSERT_EQ(defaultEntry->m_alpha, 4u); + ASSERT_EQ(defaultEntry->m_voxelValue, 5); + delete defaultEntry; +} +