From 63dd4ddae0f177cf03dcd2e29a05ebd7fc8bcbff Mon Sep 17 00:00:00 2001 From: Adrian Schneider Date: Sun, 5 Nov 2023 17:52:31 +0100 Subject: [PATCH] use std filesystem --- lib/inc/dicomRoutines.h | 4 ++-- lib/src/dicomRoutines.cpp | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/inc/dicomRoutines.h b/lib/inc/dicomRoutines.h index 83178e9..c7e8adc 100644 --- a/lib/inc/dicomRoutines.h +++ b/lib/inc/dicomRoutines.h @@ -81,10 +81,10 @@ class VTKDicomRoutines */ void cropDicom( vtkSmartPointer imageData ); - private: - bool fileExists(const std::string& filePath); + bool checkDataLoaded( vtkSmartPointer imageData ); + protected: diff --git a/lib/src/dicomRoutines.cpp b/lib/src/dicomRoutines.cpp index ccb4b59..008ae18 100644 --- a/lib/src/dicomRoutines.cpp +++ b/lib/src/dicomRoutines.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace std; @@ -64,8 +65,7 @@ vtkSmartPointer 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; @@ -150,23 +150,17 @@ void VTKDicomRoutines::cropDicom( vtkSmartPointer imageData ) } } -bool VTKDicomRoutines::fileExists(const std::string& filePath) -{ - ifstream f(filePath.c_str()); - return f.good(); -} - vtkSmartPointer VTKDicomRoutines::loadPngImages( const std::vector& pngPaths, double x_spacing, double y_spacing, double slice_spacing ) { vtkSmartPointer files = vtkSmartPointer::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; @@ -185,8 +179,7 @@ vtkSmartPointer 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; @@ -196,3 +189,9 @@ vtkSmartPointer VTKDicomRoutines::loadPngImages( const std::vector return rawVolumeData; } + +bool VTKDicomRoutines::checkDataLoaded( vtkSmartPointer imageData ) +{ + int* dims = imageData->GetDimensions(); + return dims[0] > 0 && dims[1] > 0 && dims[2] > 0; +}