36 #include <vtkOBJReader.h>
37 #include <vtkPolyData.h>
38 #include <vtkPolyDataNormals.h>
39 #include <vtkSTLReader.h>
41 #include <vtkDataReader.h>
42 #include <vtkPolyDataReader.h>
43 #include <vtkStructuredPointsReader.h>
45 #include <vtkLookupTable.h>
46 #include <vtkPointData.h>
47 #include <vtkStructuredPoints.h>
48 #include <vtkXMLImageDataReader.h>
52 #include <itkGDCMImageIO.h>
54 #include <itkImageFileReader.h>
55 #include <itkImageIOFactory.h>
56 #include <itkImageIORegion.h>
57 #include <itkImageSeriesReader.h>
58 #include <itkImageSeriesReader.h>
59 #include <itksys/Directory.hxx>
60 #include <itksys/SystemTools.hxx>
67 #include <itkGDCMSeriesFileNames.h>
76 #include <itkCommand.h>
77 #include <itkNumericSeriesFileNames.h>
127 std::ifstream exists(m_FileName.c_str());
130 std::string testfilename = m_FileName +
".gz";
132 std::ifstream exists(testfilename.c_str());
139 testfilename = m_FileName +
".GZ";
140 std::ifstream exists(testfilename.c_str());
147 std::string message(
"File does not exist, or cannot be read. Filename = ");
148 message += m_FileName;
150 itkExceptionMacro(<< message.str());
162 this->ReadFileSeriesTypeDCM();
166 bool usedNewDTNF =
false;
169 std::vector<mitk::BaseData::Pointer> baseDataVector =
172 if (!baseDataVector.empty())
173 this->ResizeOutputs((
unsigned int)baseDataVector.size());
175 for (
int i = 0; i < (int)baseDataVector.size(); i++)
179 if (baseData.IsNotNull())
183 node->SetData(baseData);
184 this->SetDefaultCommonProperties(node);
186 this->SetOutput(this->MakeNameFromOutputIndex(i), node);
189 if (!usedNewDTNF && (m_FileName !=
"") && !(m_Serie ==
false))
190 ReadFileSeriesTypeITKImageSeriesReader();
196 unsigned int prevNum = this->GetNumberOfOutputs();
197 this->SetNumberOfIndexedOutputs(num);
198 for (
unsigned int i = prevNum; i < num; ++i)
200 this->SetNthOutput(i, this->MakeOutput(i).GetPointer());
206 if (m_FileName.size() < name.size())
209 return m_FileName.substr(m_FileName.size() - name.size()) == name;
214 return m_FilePattern.find(name) != std::string::npos;
219 return itksys::SystemTools::GetFilenameName(m_FileName);
224 return itksys::SystemTools::GetFilenameName(m_FilePrefix);
229 if (!m_FileName.empty())
230 return itksys::SystemTools::GetFilenamePath(m_FileName);
231 if (!m_FilePrefix.empty())
232 return itksys::SystemTools::GetFilenamePath(m_FilePrefix);
234 return std::string();
240 std::locale previousCppLocale(std::cin.getloc());
246 MITK_INFO <<
"it is a Philips3D US Dicom file" << std::endl;
247 this->ResizeOutputs(1);
250 stringvec.push_back(this->GetFileName());
253 node->SetName(this->GetBaseFileName());
255 std::cin.imbue(previousCppLocale);
260 this->GetDirectory(),
true, this->m_SeriesRestrictions);
261 const unsigned int size = imageBlocks.size();
263 this->ResizeOutputs(size);
267 unsigned int outputIndex = 0u;
268 const DicomSeriesReader::FileNamesGrouping::const_iterator n_end = imageBlocks.end();
270 for (DicomSeriesReader::FileNamesGrouping::const_iterator n_it = imageBlocks.begin(); n_it != n_end; ++n_it)
272 const std::string &uid = n_it->first;
277 MITK_INFO <<
"--------------------------------------------------------------------------------";
278 MITK_INFO <<
"DataNodeFactory: Loading DICOM series " << outputIndex <<
": Series UID "
289 MITK_INFO <<
"--------------------------------------------------------------------------------";
293 std::string nodeName(uid);
294 std::string studyDescription;
297 0x0008, 0x1030,
"dicom.study.StudyDescription", node->GetPropertyList(), studyDescription))
299 nodeName = studyDescription;
300 std::string seriesDescription;
303 0x0008, 0x103e,
"dicom.study.SeriesDescription", node->GetPropertyList(), seriesDescription))
305 nodeName +=
"/" + seriesDescription;
309 node->SetName(nodeName);
315 MITK_ERROR <<
"DataNodeFactory: Skipping series " << outputIndex <<
" due to some unspecified error..."
322 std::cin.imbue(previousCppLocale);
328 typedef itk::ImageSeriesReader<ImageType> ReaderType;
330 if (!this->GenerateFileList())
332 itkWarningMacro(
"Sorry, file list could not be generated!");
335 if (m_MatchedFileNames.size() == 0)
337 itkWarningMacro(
"Sorry, no files matched the given filename (" << m_FileName <<
")!");
345 reader->SetFileNames(m_MatchedFileNames);
349 ResizeOutputs(reader->GetNumberOfOutputs());
350 for (
unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i)
354 image->InitializeByItk(reader->GetOutput(i));
355 image->SetVolume(reader->GetOutput(i)->GetBufferPointer());
359 node->SetData(image);
362 node->SetProperty(
"name", nameProp);
365 catch (
const std::exception &e)
367 itkWarningMacro(<< e.what());
374 static bool initialized =
false;
375 static std::map<std::string, std::string> s_ColorMap;
381 s_ColorMap.insert(std::make_pair(
"ankle",
"0xe38686"));
382 s_ColorMap.insert(std::make_pair(
"appendix",
"0xe38686"));
383 s_ColorMap.insert(std::make_pair(
"blood vessels",
"0xff3131"));
384 s_ColorMap.insert(std::make_pair(
"bronchial tree",
"0x3168ff"));
385 s_ColorMap.insert(std::make_pair(
"bone",
"0xd5d5d5"));
386 s_ColorMap.insert(std::make_pair(
"brain",
"0xff9cca"));
387 s_ColorMap.insert(std::make_pair(
"coccyx",
"0xe38686"));
388 s_ColorMap.insert(std::make_pair(
"colon",
"0xe38686"));
389 s_ColorMap.insert(std::make_pair(
"cyst",
"0xe38686"));
390 s_ColorMap.insert(std::make_pair(
"elbow",
"0xe38686"));
391 s_ColorMap.insert(std::make_pair(
"eye",
"0xe38686"));
392 s_ColorMap.insert(std::make_pair(
"fallopian tube",
"0xe38686"));
393 s_ColorMap.insert(std::make_pair(
"fat",
"0xff2bee"));
394 s_ColorMap.insert(std::make_pair(
"hand",
"0xe38686"));
395 s_ColorMap.insert(std::make_pair(
"gall bladder",
"0x567f18"));
396 s_ColorMap.insert(std::make_pair(
"heart",
"0xeb1d32"));
397 s_ColorMap.insert(std::make_pair(
"hip",
"0xe38686"));
398 s_ColorMap.insert(std::make_pair(
"kidney",
"0xd33f00"));
399 s_ColorMap.insert(std::make_pair(
"knee",
"0xe38686"));
400 s_ColorMap.insert(std::make_pair(
"larynx",
"0xe38686"));
401 s_ColorMap.insert(std::make_pair(
"liver",
"0xffcc3d"));
402 s_ColorMap.insert(std::make_pair(
"lung",
"0x6bdcff"));
403 s_ColorMap.insert(std::make_pair(
"lymph node",
"0xff0000"));
404 s_ColorMap.insert(std::make_pair(
"muscle",
"0xff456a"));
405 s_ColorMap.insert(std::make_pair(
"nerve",
"0xffea4f"));
406 s_ColorMap.insert(std::make_pair(
"nose",
"0xe38686"));
407 s_ColorMap.insert(std::make_pair(
"oesophagus",
"0xe38686"));
408 s_ColorMap.insert(std::make_pair(
"ovaries",
"0xe38686"));
409 s_ColorMap.insert(std::make_pair(
"pancreas",
"0xf9ab3d"));
410 s_ColorMap.insert(std::make_pair(
"pelvis",
"0xe38686"));
411 s_ColorMap.insert(std::make_pair(
"penis",
"0xe38686"));
412 s_ColorMap.insert(std::make_pair(
"pharynx",
"0xe38686"));
413 s_ColorMap.insert(std::make_pair(
"prostate",
"0xe38686"));
414 s_ColorMap.insert(std::make_pair(
"rectum",
"0xe38686"));
415 s_ColorMap.insert(std::make_pair(
"sacrum",
"0xe38686"));
416 s_ColorMap.insert(std::make_pair(
"seminal vesicle",
"0xe38686"));
417 s_ColorMap.insert(std::make_pair(
"shoulder",
"0xe38686"));
418 s_ColorMap.insert(std::make_pair(
"spinal cord",
"0xf5f93d"));
419 s_ColorMap.insert(std::make_pair(
"spleen",
"0xf96c3d"));
420 s_ColorMap.insert(std::make_pair(
"stomach",
"0xf96c3d"));
421 s_ColorMap.insert(std::make_pair(
"teeth",
"0xfffcd8"));
422 s_ColorMap.insert(std::make_pair(
"testicles",
"0xe38686"));
423 s_ColorMap.insert(std::make_pair(
"thyroid",
"0xfff694"));
424 s_ColorMap.insert(std::make_pair(
"tongue",
"0xe38686"));
425 s_ColorMap.insert(std::make_pair(
"tumor",
"0x937011"));
426 s_ColorMap.insert(std::make_pair(
"urethra",
"0xf8ff32"));
427 s_ColorMap.insert(std::make_pair(
"urinary bladder",
"0xf8ff32"));
428 s_ColorMap.insert(std::make_pair(
"uterus",
"0xe38686"));
429 s_ColorMap.insert(std::make_pair(
"vagina",
"0xe38686"));
430 s_ColorMap.insert(std::make_pair(
"vertebra",
"0xe38686"));
431 s_ColorMap.insert(std::make_pair(
"wrist",
"0xe38686"));
435 std::string lowercaseOrgan(organ);
436 for (
unsigned int i = 0; i < organ.length(); i++)
438 lowercaseOrgan[i] = tolower(lowercaseOrgan[i]);
441 std::map<std::string, std::string>::iterator iter = s_ColorMap.find(lowercaseOrgan);
442 if (iter != s_ColorMap.end())
444 std::string hexColor = iter->second;
445 std::string hexRed = std::string(
"0x") + hexColor.substr(2, 2);
446 std::string hexGreen = std::string(
"0x") + hexColor.substr(4, 2);
447 std::string hexBlue = std::string(
"0x") + hexColor.substr(6, 2);
449 long int red = strtol(hexRed.c_str(), NULL, 16);
450 long int green = strtol(hexGreen.c_str(), NULL, 16);
451 long int blue = strtol(hexBlue.c_str(), NULL, 16);
453 return ColorProperty::New((
float)red / 255.0, (
float)green / 255.0, (
float)blue / 255.0);
470 if (nameProp.IsNull() || (strcmp(nameProp->GetValue(),
"No Name!") == 0))
475 if (baseDataNameProp.IsNull() || (strcmp(baseDataNameProp->GetValue(),
"No Name!") == 0))
478 if (FileNameEndsWith(
".gz"))
479 m_FileName = m_FileName.substr(0, m_FileName.length() - 3);
483 node->SetProperty(
"name", nameProp);
489 node->SetProperty(
"name", nameProp);
494 if (!node->GetProperty(
"visible"))
495 node->SetVisibility(
true);
virtual std::string GetBaseFilePrefix()
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
static ColorProperty::Pointer DefaultColorForOrgan(const std::string &)
itk::SmartPointer< Self > Pointer
StringContainer GetFilenames() const
List of files in this group.
Return type of GetSeries, describes a logical group of files.
bool HasGantryTiltCorrected() const
Whether or not the block contains a gantry tilt which will be "corrected" during loading.
virtual void GenerateData() override
virtual bool FileNameEndsWith(const std::string &name)
virtual std::string GetBaseFileName()
static Pointer GetInstance()
std::vector< std::string > StringContainer
Lists of filenames.
static DataNode::Pointer LoadDicomSeries(const StringContainer &filenames, bool sort=true, bool load4D=true, bool correctGantryTilt=true, UpdateCallBackMethod callback=nullptr, itk::SmartPointer< Image > preLoadedImageBlock=nullptr)
std::string GetModality() const
Series Modality (CT, MR, etc.)
static bool m_TextureInterpolationActive
static std::string ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue)
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
std::string GetSOPClassUIDAsString() const
SOP Class UID as readable string (Computed Tomography Image Storage, Secondary Capture Image Storage...
static std::string PixelSpacingInterpretationToString(const PixelSpacingInterpretation &enumValue)
map::core::discrete::Elements< 3 >::InternalImageType ImageType
void SetImageSerie(bool serie)
Convenience class to temporarily change the current locale.
static FileNamesGrouping GetSeries(const std::string &dir, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
see other GetSeries().
virtual void ReadFileSeriesTypeITKImageSeriesReader()
bool HasMultipleTimePoints() const
3D+t or not
std::string GetSeriesInstanceUID() const
The Series Instance UID.
void SetDefaultCommonProperties(mitk::DataNode::Pointer &node)
virtual void ResizeOutputs(const unsigned int &num)
static bool IsPhilips3DDicom(const std::string &filename)
Checks if a specific file is a Philips3D ultrasound DICOM file.
static bool IsDicom(const std::string &filename)
Checks if a specific file contains DICOM data.
bool IsMultiFrameImage() const
Multi-frame image(s) or not.
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
virtual ~DataNodeFactory()
static std::vector< mitk::BaseData::Pointer > LoadBaseDataFromFile(const std::string path, const std::string filePrefix, const std::string filePattern, bool series)
ReaderImplementationLevel GetReaderImplementationLevel() const
Confidence of the reader that this block can be read successfully.
virtual bool FilePatternEndsWith(const std::string &name)
virtual std::string GetDirectory()
std::map< std::string, ImageBlockDescriptor > FileNamesGrouping
PixelSpacingInterpretation GetPixelSpacingType() const
How the mitk::Image spacing can meaningfully be interpreted.
bool MITKCORE_EXPORT GetBackwardsCompatibleDICOMProperty(unsigned int group, unsigned int element, std::string const &backwardsCompatiblePropertyName, PropertyList const *propertyList, std::string &propertyValue)
virtual void ReadFileSeriesTypeDCM()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.