27 #include <itkDirectory.h> 28 #include <itksys/SystemTools.hxx> 30 static std::vector<int>
splitString(
const std::string &s,
const char* delim) {
31 std::vector<int> elems;
32 std::stringstream ss(s);
34 while (std::getline(ss, item, *delim))
37 std::stringstream(item) >> numb;
38 elems.push_back(numb);
44 if (fullString.length() == 0 || ending.length() == 0 || fullString.length() < ending.length())
47 return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
50 mitk::pa::IOUtil::IOUtil() {}
52 mitk::pa::IOUtil::~IOUtil() {}
56 if (filename.empty() || filename ==
"")
61 if (inputImage.IsNull())
71 std::map<mitk::pa::IOUtil::Position, mitk::pa::Volume::Pointer>
74 std::map<IOUtil::Position, Volume::Pointer> resultMap;
76 itk::Directory::Pointer directoryHandler = itk::Directory::New();
77 directoryHandler->Load(foldername.c_str());
78 for (
unsigned int fileIndex = 0, numFiles = directoryHandler->GetNumberOfFiles(); fileIndex < numFiles; ++fileIndex)
80 std::string filename = std::string(directoryHandler->GetFile(fileIndex));
81 if (itksys::SystemTools::FileIsDirectory(filename))
87 size_t s = filename.find(
"_p");
88 size_t e = filename.find(
"Fluence", s);
89 std::string sub = filename.substr(s + 2, e - s - 2);
92 if (coords.size() != 3)
94 MITK_ERROR <<
"Some of the data to read was corrupted or did not match the " <<
95 "naming pattern *_pN,N,NFluence*.nrrd";
96 mitkThrow() <<
"Some of the data to read was corrupted or did not match the" <<
97 " naming pattern *_pN,N,NFluence*.nrrd";
101 MITK_DEBUG <<
"Extracted coords: " << coords[0] <<
"|" << coords[1] <<
"|" << coords[2] <<
" from string " << sub;
102 Volume::Pointer nrrdFile =
LoadNrrd(foldername + filename, blur);
105 resultMap[
Position{ coords[0], coords[2] }] = nrrdFile;
106 *progress = *progress + 1;
120 std::vector<std::string> filenames;
121 itk::Directory::Pointer directoryHandler = itk::Directory::New();
122 directoryHandler->Load(directory.c_str());
123 for (
unsigned int fileIndex = 0, numFiles = directoryHandler->GetNumberOfFiles(); fileIndex < numFiles; ++fileIndex)
125 std::string filename = std::string(directoryHandler->GetFile(fileIndex));
126 if (itksys::SystemTools::FileIsDirectory(filename))
134 filenames.push_back(filename);
138 filenames.push_back(filename.substr(0, filename.size() - 5));
147 std::vector<std::string> returnVector;
149 itksys::Directory directoryHandler;
150 directoryHandler.Load(folderPath.c_str());
151 for (
unsigned int fileIndex = 0, numFiles = directoryHandler.GetNumberOfFiles(); fileIndex < numFiles; ++fileIndex)
153 std::string foldername = std::string(directoryHandler.GetFile(fileIndex));
154 std::string filename = folderPath +
"/" + foldername;
155 if (itksys::SystemTools::FileIsDirectory(filename))
157 if (foldername != std::string(
".") && foldername != std::string(
".."))
160 returnVector.push_back(filename);
168 returnVector.clear();
169 returnVector.push_back(folderPath);
179 MITK_INFO <<
"Initializing ComposedVolume by nrrd...";
180 auto inputImage = mitk::IOUtil::Load<mitk::Image>(nrrdFile);
184 unsigned int xDim = inputImage->GetDimensions()[1];
185 unsigned int yDim = inputImage->GetDimensions()[0];
186 unsigned int zDim = inputImage->GetDimensions()[2];
187 tissueParameters->SetXDim(xDim);
188 tissueParameters->SetYDim(yDim);
189 tissueParameters->SetZDim(zDim);
191 double xSpacing = inputImage->GetGeometry(0)->GetSpacing()[1];
192 double ySpacing = inputImage->GetGeometry(0)->GetSpacing()[0];
193 double zSpacing = inputImage->GetGeometry(0)->GetSpacing()[2];
200 tissueParameters->SetVoxelSpacingInCentimeters(xSpacing);
205 auto* m_AbsorptionArray =
new double[xDim*yDim*zDim];
206 memcpy(m_AbsorptionArray, readAccess0.GetData(), xDim*yDim*zDim *
sizeof(double));
207 auto absorptionVolume =
Volume::New(m_AbsorptionArray, xDim, yDim, zDim, xSpacing);
210 auto* m_ScatteringArray =
new double[xDim*yDim*zDim];
211 memcpy(m_ScatteringArray, readAccess1.GetData(), xDim*yDim*zDim *
sizeof(double));
212 auto scatteringVolume =
Volume::New(m_ScatteringArray, xDim, yDim, zDim, xSpacing);
215 auto* m_AnisotropyArray =
new double[xDim*yDim*zDim];
216 memcpy(m_AnisotropyArray, readAccess2.GetData(), xDim*yDim*zDim *
sizeof(double));
217 auto anisotropyVolume =
Volume::New(m_AnisotropyArray, xDim, yDim, zDim, xSpacing);
219 Volume::Pointer segmentationVolume;
221 if (inputImage->GetDimension() == 4)
224 auto* m_SegmentationArray =
new double[xDim*yDim*zDim];
225 memcpy(m_SegmentationArray, readAccess3.GetData(), xDim*yDim*zDim *
sizeof(double));
226 segmentationVolume =
Volume::New(m_SegmentationArray, xDim, yDim, zDim, xSpacing);
230 anisotropyVolume, segmentationVolume, tissueParameters, propertyList);
239 auto yOffsetProperty = inputImage->GetProperty(
"y-offset");
241 if (yOffsetProperty.IsNull())
242 mitkThrow() <<
"No \"y-offset\" property found in fluence file!";
244 std::string yOff = yOffsetProperty->GetValueAsString();
245 MITK_INFO <<
"Reading y Offset: " << yOff;
249 double yOffset = std::stod(yOff);
251 return FluenceYOffsetPair::New(
Volume::New(inputImage), yOffset);
static std::vector< std::string > GetListOfAllNrrdFilesInDirectory(std::string directory, bool keepFileFormat=false)
returns a list of all .nrrd files in a given directory
static int GetNumberOfNrrdFilesInDirectory(std::string directory)
returns the number of .nrrd files in a given directory
static std::map< Position, Volume::Pointer > LoadFluenceContributionMaps(std::string foldername, double blur, int *progress, bool log10=false)
LoadFluenceContributionMaps loads multiple nrrd files from a given folder and sorts them into a posit...
static InSilicoTissueVolume::Pointer New(mitk::pa::Volume::Pointer absorptionVolume, Volume::Pointer scatteringVolume, Volume::Pointer anisotropyVolume, Volume::Pointer segmentationVolume, TissueGeneratorParameters::Pointer tissueParameters, mitk::PropertyList::Pointer propertyList)
static Volume::Pointer LoadNrrd(std::string filename, double sigma=0)
loads a nrrd file from a given filename.
static FluenceYOffsetPair::Pointer LoadFluenceSimulation(std::string fluenceSimulation)
LoadFluenceSimulation Adds a MC Simulation nrrd file to this composed volume. The given file needs to...
static void Log10Image(Volume::Pointer image)
static bool DoesFileHaveEnding(std::string const &fullString, std::string const &ending)
convenience method to check wether a given strings ends on a given substring.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
static std::vector< std::string > GetAllChildfoldersFromFolder(std::string folderPath)
returns all child folders from a folder if there is no .nrrd file in the folder If there IS a ...
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
MITKCORE_EXPORT const ScalarType eps
static void GaussianBlur3D(Volume::Pointer paVolume, double sigma)
applies a Gaussian blur to an image
static InSilicoTissueVolume::Pointer LoadInSilicoTissueVolumeFromNrrdFile(std::string filePath)
loads an in silico tissue volume from a saved nrrd file.
ImageReadAccessor class to get locked read access for a particular image part.
static Volume::Pointer New(double *data, unsigned int xDim, unsigned int yDim, unsigned int zDim, double spacing)
returns smartpointer reference to a new instance of this objects. The given data array will be freed ...
static std::vector< int > splitString(const std::string &s, const char *delim)