Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
PAPhantomGenerator.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 
13 #include <mitkCommon.h>
14 #include <chrono>
16 #include <mitkPATissueGenerator.h>
18 #include <mitkIOUtil.h>
19 #include <mitkCommandLineParser.h>
20 #include <mitkUIDGenerator.h>
21 #include <mitkException.h>
22 
23 #include <itksys/SystemTools.hxx>
24 
25 using namespace mitk::pa;
26 
27 TissueGeneratorParameters::Pointer CreatePhantom_04_04_18_Parameters()
28 {
29  auto returnParameters = TissueGeneratorParameters::New();
30  returnParameters->SetAirThicknessInMillimeters(12);
31  returnParameters->SetMinBackgroundAbsorption(0.1);
32  returnParameters->SetMaxBackgroundAbsorption(0.1);
33  returnParameters->SetBackgroundAnisotropy(0.9);
34  returnParameters->SetBackgroundScattering(15);
35  returnParameters->SetCalculateNewVesselPositionCallback(&VesselMeanderStrategy::CalculateNewDirectionVectorInStraightLine);
36  returnParameters->SetDoPartialVolume(true);
37  returnParameters->SetMinNumberOfVessels(1);
38  returnParameters->SetMaxNumberOfVessels(8);
39  returnParameters->SetMinVesselAbsorption(1);
40  returnParameters->SetMaxVesselAbsorption(10);
41  returnParameters->SetMinVesselAnisotropy(0.9);
42  returnParameters->SetMaxVesselAnisotropy(0.9);
43  returnParameters->SetMinVesselBending(0.1);
44  returnParameters->SetMaxVesselBending(0.3);
45  returnParameters->SetMinVesselRadiusInMillimeters(0.25);
46  returnParameters->SetMaxVesselRadiusInMillimeters(4);
47  returnParameters->SetMinVesselScattering(15);
48  returnParameters->SetMaxVesselScattering(15);
49  returnParameters->SetMinVesselZOrigin(1.6);
50  returnParameters->SetMaxVesselZOrigin(4);
51  returnParameters->SetVesselBifurcationFrequency(5000);
52  returnParameters->SetRandomizePhysicalProperties(false);
53  returnParameters->SetSkinThicknessInMillimeters(0);
54  returnParameters->SetUseRngSeed(false);
55  returnParameters->SetVoxelSpacingInCentimeters(0.03);
56  returnParameters->SetXDim(140);
57  returnParameters->SetYDim(100);
58  returnParameters->SetZDim(180);
59  //returnParameters->SetVoxelSpacingInCentimeters(0.015);
60  //returnParameters->SetXDim(280);
61  //returnParameters->SetYDim(200);
62  //returnParameters->SetZDim(360);
63  returnParameters->SetForceVesselsMoveAlongYDirection(true);
64  //returnParameters->SetVoxelSpacingInCentimeters(0.0075);
65  //returnParameters->SetXDim(560);
66  //returnParameters->SetYDim(400);
67  //returnParameters->SetZDim(720);
68  return returnParameters;
69 }
70 
71 struct InputParameters
72 {
73  std::string saveFolderPath;
74  std::string identifyer;
75  std::string exePath;
76  std::string probePath;
77  bool empty;
78  bool verbose;
79 };
80 
81 InputParameters parseInput(int argc, char* argv[])
82 {
83  MITK_INFO << "Parsing arguments...";
84  mitkCommandLineParser parser;
85 
86  parser.setCategory("MITK-Photoacoustics");
87  parser.setTitle("Mitk Tissue Batch Generator");
88  parser.setDescription("Creates in silico tissue in batch processing and automatically calculates fluence values for the central slice of the volume.");
89  parser.setContributor("Computer Assisted Medical Interventions, DKFZ");
90 
91  parser.setArgumentPrefix("--", "-");
92 
93  parser.beginGroup("Required parameters");
94  parser.addArgument(
95  "savePath", "s", mitkCommandLineParser::Directory,
96  "Input save folder (directory)", "input save folder",
97  us::Any(), false, false, false, mitkCommandLineParser::Input);
98  parser.addArgument(
99  "mitkMcxyz", "m", mitkCommandLineParser::File,
100  "MitkMcxyz binary (file)", "path to the MitkMcxyz binary",
101  us::Any(), false, false, false, mitkCommandLineParser::Output);
102  parser.endGroup();
103 
104  parser.beginGroup("Optional parameters");
105  parser.addArgument(
106  "probe", "p", mitkCommandLineParser::File,
107  "xml probe file (file)", "file to the definition of the used probe (*.xml)",
108  us::Any(), true, false, false, mitkCommandLineParser::Output);
109  parser.addArgument(
110  "verbose", "v", mitkCommandLineParser::Bool,
111  "Verbose Output", "Whether to produce verbose, or rather debug output");
112  parser.addArgument(
113  "identifyer", "i", mitkCommandLineParser::String,
114  "Generator identifyer (string)", "A unique identifyer for the calculation instance");
115  parser.addArgument(
116  "empty-volume", "e", mitkCommandLineParser::Bool,
117  "omit vessel structures (boolean flag)", "Whether to create an empty volume with no structures inside.");
118  parser.endGroup();
119 
120  InputParameters input;
121 
122  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
123  if (parsedArgs.size() == 0)
124  exit(-1);
125 
126  if (parsedArgs.count("empty-volume"))
127  {
128  input.empty = us::any_cast<bool>(parsedArgs["empty-volume"]);
129  }
130  else
131  {
132  input.empty = false;
133  }
134 
135  if (parsedArgs.count("verbose"))
136  {
137  input.verbose = us::any_cast<bool>(parsedArgs["verbose"]);
138  }
139  else
140  {
141  input.verbose = false;
142  }
143 
144  if (parsedArgs.count("savePath"))
145  {
146  input.saveFolderPath = us::any_cast<std::string>(parsedArgs["savePath"]);
147  }
148 
149  if (parsedArgs.count("mitkMcxyz"))
150  {
151  input.exePath = us::any_cast<std::string>(parsedArgs["mitkMcxyz"]);
152  }
153 
154  if (parsedArgs.count("probe"))
155  {
156  input.probePath = us::any_cast<std::string>(parsedArgs["probe"]);
157  }
158 
159  if (parsedArgs.count("identifyer"))
160  {
161  input.identifyer = us::any_cast<std::string>(parsedArgs["identifyer"]);
162  }
163  else
164  {
165  auto uid = mitk::UIDGenerator("", 8);
166  input.identifyer = uid.GetUID();
167  }
168  MITK_INFO << "Parsing arguments...[Done]";
169  return input;
170 }
171 
172 int main(int argc, char * argv[])
173 {
174  auto input = parseInput(argc, argv);
175  auto parameters = CreatePhantom_04_04_18_Parameters();
176  if (input.empty)
177  {
178  parameters->SetMaxNumberOfVessels(0);
179  parameters->SetMinNumberOfVessels(0);
180  }
181  MITK_INFO(input.verbose) << "Generating tissue..";
182  auto resultTissue = InSilicoTissueGenerator::GenerateInSilicoData(parameters);
183  MITK_INFO(input.verbose) << "Generating tissue..[Done]";
184 
185  auto inputfolder = std::string(input.saveFolderPath + "input/");
186  auto outputfolder = std::string(input.saveFolderPath + "output/");
187  if (!itksys::SystemTools::FileIsDirectory(inputfolder))
188  {
189  itksys::SystemTools::MakeDirectory(inputfolder);
190  }
191  if (!itksys::SystemTools::FileIsDirectory(outputfolder))
192  {
193  itksys::SystemTools::MakeDirectory(outputfolder);
194  }
195 
196  std::string savePath = input.saveFolderPath + "input/Phantom_" + input.identifyer +
197  ".nrrd";
198  mitk::IOUtil::Save(resultTissue->ConvertToMitkImage(), savePath);
199  std::string outputPath = input.saveFolderPath + "output/Phantom_" + input.identifyer +
200  "/";
201 
202  resultTissue = nullptr;
203 
204  if (!itksys::SystemTools::FileIsDirectory(outputPath))
205  {
206  itksys::SystemTools::MakeDirectory(outputPath);
207  }
208 
209  outputPath = outputPath + "Fluence_Phantom_" + input.identifyer;
210 
211  MITK_INFO(input.verbose) << "Simulating fluence..";
212 
213  int result = -4;
214 
215  std::string cmdString = std::string(input.exePath + " -i " + savePath + " -o " +
216  (outputPath + ".nrrd") +
217  " -yo " + "0" + " -p " + input.probePath +
218  " -n 10000000");
219 
220  MITK_INFO << "Executing: " << cmdString;
221 
222  result = std::system(cmdString.c_str());
223 
224  MITK_INFO << result;
225  MITK_INFO(input.verbose) << "Simulating fluence..[Done]";
226 }
int main(int argc, char *argv[])
Generated unique IDs.
#define MITK_INFO
Definition: mitkLogMacros.h:18
void setContributor(std::string contributor)
InputParameters parseInput(int argc, char *argv[])
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
TissueGeneratorParameters::Pointer CreatePhantom_04_04_18_Parameters()
static InSilicoTissueVolume::Pointer GenerateInSilicoData(TissueGeneratorParameters::Pointer parameters)
GenerateInSilicoData This method will return a InSilicoTissueVolume created in terms of the given par...
bool verbose(false)
Definition: usAny.h:163
void CalculateNewDirectionVectorInStraightLine(Vector::Pointer direction, double bendingFactor, std::mt19937 *rng)
CalculateNewPositionInStraightLine calculates the new position by just following the direction vector...
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774
void setTitle(std::string title)
void setDescription(std::string description)
void beginGroup(const std::string &description)