23 #include <itkImageFileWriter.h>
24 #include <itkNrrdImageIO.h>
26 #include <itksys/SystemTools.hxx>
27 #include <itksys/Directory.hxx>
49 itksys::Directory input;
50 input.Load( input_directory.c_str() );
54 for(
unsigned long idx=0; idx<input.GetNumberOfFiles(); idx++)
56 if( ! itksys::SystemTools::FileIsDirectory( input.GetFile(idx)) )
58 std::string fullpath = input_directory +
"/" + std::string( input.GetFile(idx) );
60 inputlist.push_back( fullpath.c_str() );
62 MITK_INFO(
"dicom.loader.inputdir.addfile") << input.GetFile(idx);
73 MITK_INFO(
"dicom.loader.setinputfiles.end") <<
"[]";
117 gdcmReader->SetInputFiles( input_files );
121 gdcmReader->AnalyzeInputFiles();
123 catch(
const itk::ExceptionObject &e)
125 MITK_ERROR <<
"Failed to analyze data. " << e.what();
127 catch(
const std::exception &se)
133 gdcmReader->LoadImages();
150 void SearchForInputInSubdirs( std::string root_directory, std::string subdir_prefix , std::vector<DiffusionImageType::Pointer>& output_container)
153 itksys::Directory rootdir;
154 rootdir.Load( root_directory.c_str() );
156 MITK_INFO(
"dicom.loader.setinputdirs.start") <<
"Prefix = " << subdir_prefix;
158 for(
unsigned int idx=0; idx<rootdir.GetNumberOfFiles(); idx++)
160 std::string current_path = rootdir.GetFile(idx);
162 std::string directory_path = std::string(rootdir.GetPath()) + current_path;
164 MITK_INFO(
"dicom.loader.inputrootdir.test") <<
"ProbePath: " << current_path <<
"\n"
165 <<
"escaped to " << itksys::SystemTools::ConvertToOutputPath( directory_path.c_str() );
167 MITK_INFO(
"dicom.loader.inputrootdir.test") <<
" IsDirectory: " << itksys::SystemTools::FileIsDirectory( directory_path.c_str() )
168 <<
" StartsWith: " << itksys::SystemTools::StringStartsWith( current_path.c_str(), subdir_prefix.c_str() );
171 if( itksys::SystemTools::FileIsDirectory( directory_path.c_str() )
172 && itksys::SystemTools::StringStartsWith( current_path.c_str(), subdir_prefix.c_str() )
176 MITK_INFO(
"dicom.loader.inputrootdir.searchin") << directory_path;
179 MITK_INFO(
"dicom.loader.inputrootdir.preload") <<
"[]" ;
182 output_container.push_back( dwi );
188 MITK_INFO(
"dicom.loader.setinputdirs.end") <<
"[]";
193 using namespace mitk;
198 int main(
int argc,
char* argv[])
203 parser.
setTitle(
"Diffusion Dicom Loader");
213 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
214 if (parsedArgs.size()==0)
219 std::string inputDirectory =
us::any_cast<std::string>( parsedArgs[
"inputdir"] );
220 MITK_INFO <<
"Loading data from directory: " << inputDirectory;
223 bool search_for_subdirs =
false;
224 std::string subdir_prefix;
225 if( parsedArgs.count(
"dwprefix"))
227 subdir_prefix =
us::any_cast<std::string>( parsedArgs[
"dwprefix"] );
228 if (subdir_prefix !=
"")
230 MITK_INFO <<
"Prefix specified, will search for subdirs in the input directory!";
231 search_for_subdirs =
true;
236 std::string outputFile =
us::any_cast< std::string >( parsedArgs[
"output"] );
239 if( !search_for_subdirs )
250 catch(
const itk::ExceptionObject& e)
252 MITK_ERROR <<
"Failed to write out the output file. \n\t Reason : ITK Exception " << e.what();
259 std::vector<mitk::Image::Pointer> output_container;
265 if( output_container.size() > 1 )
269 std::vector< double > bValueContainer;
271 for ( std::vector< mitk::Image::Pointer >::iterator dwi = output_container.begin();
272 dwi != output_container.end(); ++dwi )
277 imageContainer.push_back(itkVectorImagePointer);
284 filter->SetImageVolumes(imageContainer);
285 filter->SetGradientLists(gradientListContainer);
286 filter->SetBValues(bValueContainer);
289 vnl_matrix_fixed< double, 3, 3 > mf; mf.set_identity();
301 image = output_container.at(0);
304 MITK_INFO(
"dicom.import.writeout") <<
" [OutputFile] " << outputFile.c_str();
310 catch(
const itk::ExceptionObject& e)
312 MITK_ERROR <<
"Failed to write out the output file. \n\t Reason : ITK Exception " << e.what();
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
static const std::string REFERENCEBVALUEPROPERTYNAME
itk::SmartPointer< Self > Pointer
std::vector< DwiImageType::Pointer > DwiImageContainerType
void setContributor(std::string contributor)
Helper class for mitk::Images containing diffusion weighted data.
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
static const std::string MEASUREMENTFRAMEPROPERTYNAME
mitk::Image DiffusionImageType
static mitk::StringList & GetInputFilenames()
GradientDirectionsProperty::GradientDirectionsContainerType GradientDirectionsContainerType
void InitializeImage()
Make certain the owned image is up to date with all necessary properties.
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)
mitk::Image::Pointer ReadInDICOMFiles(mitk::StringList &input_files, std::string output_file)
Image class for storing images.
DwiImageType::PixelType DwiPixelType
itk::VectorImage< DiffusionPixelType, 3 > DwiImageType
mitk::DiffusionPropertyHelper::GradientDirectionsContainerType GradientContainerType
void setCategory(std::string category)
std::vector< std::string > StringList
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void SetInputFileNames(std::string input_directory)
float GetReferenceBValue() const
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
std::vector< GradientContainerType::Pointer > GradientListContainerType
void SearchForInputInSubdirs(std::string root_directory, std::string subdir_prefix, std::vector< DiffusionImageType::Pointer > &output_container)
GradientDirectionsContainerType::Pointer GetGradientContainer() const
Merges diffusion weighted images, e.g. to generate one multishell volume from several single shell vo...
static const std::string GRADIENTCONTAINERPROPERTYNAME
void setTitle(std::string title)
DwiImageType::RegionType DwiRegionType
void setDescription(std::string description)
int main(int argc, char *argv[])
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.