Skip to content

Commit

Permalink
Add volume tests, import tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eidelen committed Aug 6, 2023
1 parent f5f11a6 commit 79aea08
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 16 deletions.
14 changes: 7 additions & 7 deletions dicom2mesh/src/dicom2mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
**
*****************************************************************************/

#include <vtkAlgorithm.h>
#include <iostream>
#include <memory>
#include <fstream>
#include <chrono>
#include <regex>

#include "dicom2mesh.h"
#include "meshRoutines.h"
#include "meshData.h"
Expand All @@ -29,13 +36,6 @@
#include "meshVisualizer.h"
#include "volumeVisualizer.h"

#include <vtkAlgorithm.h>
#include <iostream>
#include <memory>
#include <fstream>
#include <chrono>
#include <regex>

// 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.
Expand Down
36 changes: 36 additions & 0 deletions dicom2mesh/test/t_d2m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ TEST(D2M, MakeSimpleMesh)
}
}

TEST(D2M, ImportSimpleMesh)
{
std::vector<std::string> 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<std::string> fnames{"testObj.obj", "testPly.ply", "testStl.stl"};
Expand Down
16 changes: 7 additions & 9 deletions lib/inc/volumeVisualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/src/volumeVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
#include <vtkColorTransferFunction.h>
#include <vtkFixedPointVolumeRayCastMapper.h>

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
Expand Down
26 changes: 26 additions & 0 deletions lib/test/t_volume.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <gtest/gtest.h>
#include <cstdio>
#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;
}

0 comments on commit 79aea08

Please sign in to comment.