Skip to content

Commit

Permalink
use filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
eidelen committed Nov 5, 2023
1 parent 63dd4dd commit db76160
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
9 changes: 3 additions & 6 deletions dicom2mesh/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
**
*****************************************************************************/

#include <memory>
#include "dicom2mesh.h"

int main(int argc, char *argv[])
Expand All @@ -29,10 +30,6 @@ int main(int argc, char *argv[])
if( !Dicom2Mesh::parseCmdLineParameters(argc, (const char**)( argv ), settings) )
return -1;

Dicom2Mesh* d2m = new Dicom2Mesh(settings);
int retCode = d2m->doMesh();

delete d2m;

return retCode;
auto d2m = std::shared_ptr<Dicom2Mesh>(new Dicom2Mesh(settings));
return d2m->doMesh();
}
22 changes: 8 additions & 14 deletions dicom2mesh/test/t_d2m.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#include <gtest/gtest.h>
#include "dicom2mesh.h"

#include <fstream>
#include <filesystem>
#include <cstdio>
#include <limits>

bool fexists(const std::string& filePath)
{
std::ifstream f(filePath.c_str());
return f.good();
}

std::ifstream::pos_type filesize(const std::string& filePath)
{
std::ifstream in(filePath, std::ifstream::ate | std::ifstream::binary);
Expand Down Expand Up @@ -38,7 +32,7 @@ TEST(D2M, InvalidMesh)
delete d2m;

ASSERT_NE(retCode, 0);
ASSERT_FALSE(fexists(fname));
ASSERT_FALSE(std::filesystem::exists(std::filesystem::path(fname)));
}

TEST(D2M, MakeSimpleMesh)
Expand All @@ -57,7 +51,7 @@ TEST(D2M, MakeSimpleMesh)

ASSERT_EQ(retCode, 0);
ASSERT_GT(filesize(fn), 0);
ASSERT_TRUE(fexists(fn));
ASSERT_TRUE(std::filesystem::exists(std::filesystem::path(fn)));
remove(fn.c_str());
}
}
Expand All @@ -78,7 +72,7 @@ TEST(D2M, ImportSimpleMesh)

ASSERT_EQ(retCode, 0);
ASSERT_GT(filesize(fn), 0);
ASSERT_TRUE(fexists(fn));
ASSERT_TRUE(std::filesystem::exists(std::filesystem::path(fn)));

// now import it again and safe as, whatever, obj
std::string exportFilePath = "importtest.obj";
Expand All @@ -90,7 +84,7 @@ TEST(D2M, ImportSimpleMesh)
delete d2mImport;
ASSERT_EQ(retCode, 0);
ASSERT_GT(filesize(exportFilePath), 0);
ASSERT_TRUE(fexists(exportFilePath));
ASSERT_TRUE(std::filesystem::exists(std::filesystem::path(exportFilePath)));


remove(fn.c_str());
Expand All @@ -115,7 +109,7 @@ TEST(D2M, MakeCenterMesh)

ASSERT_EQ(retCode, 0);
ASSERT_GT(filesize(fn), 0);
ASSERT_TRUE(fexists(fn));
ASSERT_TRUE(std::filesystem::exists(std::filesystem::path(fn)));
remove(fn.c_str());
}
}
Expand All @@ -137,7 +131,7 @@ TEST(D2M, MakeSmoothedMesh)

ASSERT_EQ(retCode, 0);
ASSERT_GT(filesize(fn), 0);
ASSERT_TRUE(fexists(fn));
ASSERT_TRUE(std::filesystem::exists(std::filesystem::path(fn)));
remove(fn.c_str());
}
}
Expand All @@ -161,7 +155,7 @@ TEST(D2M, TestReduce)
delete d2m;

ASSERT_EQ(retCode, 0);
ASSERT_TRUE(fexists(fname));
ASSERT_TRUE(std::filesystem::exists(std::filesystem::path(fname)));

// check that file size decreases
size_t fs = filesize(fname);
Expand Down

0 comments on commit db76160

Please sign in to comment.