Skip to content

Commit

Permalink
use std filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
eidelen committed Nov 5, 2023
1 parent 21b7955 commit 63dd4dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/inc/dicomRoutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class VTKDicomRoutines
*/
void cropDicom( vtkSmartPointer<vtkImageData> imageData );


private:

bool fileExists(const std::string& filePath);
bool checkDataLoaded( vtkSmartPointer<vtkImageData> imageData );


protected:

Expand Down
23 changes: 11 additions & 12 deletions lib/src/dicomRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <vtkStringArray.h>
#include <iostream>
#include <vector>
#include <filesystem>

using namespace std;

Expand Down Expand Up @@ -64,8 +65,7 @@ vtkSmartPointer<vtkImageData> VTKDicomRoutines::loadDicomImage( const std::strin
rawVolumeData->DeepCopy(reader->GetOutput());

// check if load was successful
int* dims = rawVolumeData->GetDimensions();
if( dims[0] < 1 || dims[1] < 1 || dims[2] < 1 )
if( checkDataLoaded(rawVolumeData) )
{
cerr << "No DICOM data in directory" << endl;
return NULL;
Expand Down Expand Up @@ -150,23 +150,17 @@ void VTKDicomRoutines::cropDicom( vtkSmartPointer<vtkImageData> imageData )
}
}

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

vtkSmartPointer<vtkImageData> VTKDicomRoutines::loadPngImages( const std::vector<std::string>& pngPaths,
double x_spacing, double y_spacing, double slice_spacing )
{
vtkSmartPointer<vtkStringArray> files = vtkSmartPointer<vtkStringArray>::New();
files->SetNumberOfValues(pngPaths.size());

// copy paths and check if files exist
// copy existing file paths
for( size_t i = 0; i < pngPaths.size(); i++ )
{
const std::string& path = pngPaths.at(i);
if( !fileExists(path) )
if( !std::filesystem::exists(std::filesystem::path(path)) )
{
cerr << "PNG file does not exist: " << path << endl;
return NULL;
Expand All @@ -185,8 +179,7 @@ vtkSmartPointer<vtkImageData> VTKDicomRoutines::loadPngImages( const std::vector
rawVolumeData->DeepCopy(pngReader->GetOutput());

// check if load was successful
int* dims = rawVolumeData->GetDimensions();
if( dims[0] < 1 || dims[1] < 1 || dims[2] < 1 )
if( !checkDataLoaded(rawVolumeData) )
{
cerr << "No PNG data in directory" << endl;
return NULL;
Expand All @@ -196,3 +189,9 @@ vtkSmartPointer<vtkImageData> VTKDicomRoutines::loadPngImages( const std::vector

return rawVolumeData;
}

bool VTKDicomRoutines::checkDataLoaded( vtkSmartPointer<vtkImageData> imageData )
{
int* dims = imageData->GetDimensions();
return dims[0] > 0 && dims[1] > 0 && dims[2] > 0;
}

0 comments on commit 63dd4dd

Please sign in to comment.