Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPASimulationBatchGenerator.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include <mitkIOUtil.h>
15 
16 #include <iomanip>
17 
18 #ifdef _WIN32
19 #include <direct.h>
20 #else
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #endif
24 
26 {
27 }
28 
30 {
31 }
32 
34  SimulationBatchGeneratorParameters::Pointer parameters)
35 {
36  std::string volumeNumber = std::to_string(parameters->GetVolumeIndex());
37  volumeNumber = std::string((3 - volumeNumber.length()), '0') + volumeNumber;
38  return volumeNumber;
39 }
40 
42  SimulationBatchGeneratorParameters::Pointer parameters)
43 {
44  return (parameters->GetTissueName() + GetVolumeNumber(parameters));
45 }
46 
48  SimulationBatchGeneratorParameters::Pointer parameters)
49 {
50  std::string outputFolderName = GetOutputFolderName(parameters);
51  std::string savePath = outputFolderName + ".nrrd";
52  std::stringstream batchstring;
53  for (double d = parameters->GetYOffsetLowerThresholdInCentimeters();
54  d <= parameters->GetYOffsetUpperThresholdInCentimeters() + 1e-5;
55  d += parameters->GetYOffsetStepInCentimeters())
56  {
57  batchstring << parameters->GetBinaryPath() << " -p PROBE_DESIGN.xml -i " << savePath << " -o " << outputFolderName << "/"
58  << parameters->GetTissueName() << GetVolumeNumber(parameters) << "_yo" << round(d * 100) / 100 << ".nrrd" << " -yo " << round(d * 100) / 100 << " -n "
59  << parameters->GetNumberOfPhotons() << "\n";
60  }
61  return batchstring.str();
62 }
63 
65  SimulationBatchGeneratorParameters::Pointer parameters,
66  mitk::Image::Pointer tissueVolume)
67 {
68  std::string outputFolderName = parameters->GetNrrdFilePath() + GetOutputFolderName(parameters);
69  std::string savePath = outputFolderName + ".nrrd";
70  mitk::IOUtil::Save(tissueVolume, savePath);
71 
72  std::string filenameAllSimulation = "simulate_all";
73 #ifdef _WIN32
74  mkdir(outputFolderName.c_str());
75  filenameAllSimulation += ".bat";
76 #else
77  mkdir(outputFolderName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
78  filenameAllSimulation += ".sh";
79 #endif
80 
81  std::ofstream fileAllSimulation(parameters->GetNrrdFilePath() + "/" + filenameAllSimulation, std::ios_base::app);
82  if (fileAllSimulation.is_open())
83  {
84  fileAllSimulation << CreateBatchSimulationString(parameters);
85  fileAllSimulation.close();
86  }
87 }
static void WriteBatchFileAndSaveTissueVolume(SimulationBatchGeneratorParameters::Pointer parameters, mitk::Image::Pointer tissueVolume)
static std::string CreateBatchSimulationString(SimulationBatchGeneratorParameters::Pointer parameter)
static std::string GetOutputFolderName(SimulationBatchGeneratorParameters::Pointer parameter)
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774
static std::string GetVolumeNumber(SimulationBatchGeneratorParameters::Pointer parameters)