21 #define BOOST_DATE_TIME_NO_LIB
24 #if defined(BOOST_ALL_DYN_LINK)
25 #undef BOOST_ALL_DYN_LINK
28 #include <boost/date_time/posix_time/posix_time_types.hpp>
36 #define switch3DCase( IOType, T ) \
38 return LoadDICOMByITK<T>( filenames, correctTilt, tiltInfo, io );
44 return tester->CanReadFile( filename.c_str() );
51 if ( filenames.empty() )
54 <<
"Calling LoadDicomSeries with empty filename string container. Probably invalid application logic.";
58 typedef itk::GDCMImageIO DcmIoType;
63 if ( io->CanReadFile( filenames.front().c_str() ) )
65 io->SetFileName( filenames.front().c_str() );
66 io->ReadImageInformation();
68 if ( io->GetPixelType() == itk::ImageIOBase::SCALAR )
70 switch ( io->GetComponentType() )
73 DcmIoType::USHORT,
unsigned short)
switch3DCase(DcmIoType::SHORT,
short)
75 DcmIoType::ULONG,
long unsigned int)
switch3DCase(DcmIoType::LONG,
long int)
78 <<
"Found unsupported DICOM scalar pixel type: (enum value) "
79 << io->GetComponentType();
82 else if ( io->GetPixelType() == itk::ImageIOBase::RGB )
84 switch ( io->GetComponentType() )
87 DcmIoType::CHAR, itk::RGBPixel<char>)
switch3DCase(DcmIoType::USHORT,
88 itk::RGBPixel<unsigned short>)
90 DcmIoType::UINT, itk::RGBPixel<unsigned int>)
switch3DCase(DcmIoType::INT, itk::RGBPixel<int>)
91 switch3DCase(DcmIoType::ULONG, itk::RGBPixel<long unsigned int>)
93 DcmIoType::FLOAT, itk::RGBPixel<float>)
switch3DCase(DcmIoType::DOUBLE,
94 itk::RGBPixel<double>)
default
96 <<
"Found unsupported DICOM scalar pixel type: (enum value) "
97 << io->GetComponentType();
105 catch (
const itk::MemoryAllocationError& e )
107 MITK_ERROR <<
"Out of memory. Cannot load DICOM series: " << e.what();
109 catch (
const std::exception& e )
111 MITK_ERROR <<
"Error encountered when loading DICOM series:" << e.what();
115 MITK_ERROR <<
"Unspecified error encountered when loading DICOM series.";
121 #define switch3DnTCase( IOType, T ) \
123 return LoadDICOMByITK3DnT<T>( filenamesLists, correctTilt, tiltInfo, io );
129 if ( filenamesLists.empty() || filenamesLists.front().empty() )
132 <<
"Calling LoadDicomSeries with empty filename string container. Probably invalid application logic.";
136 typedef itk::GDCMImageIO DcmIoType;
141 if ( io->CanReadFile( filenamesLists.front().front().c_str() ) )
143 io->SetFileName( filenamesLists.front().front().c_str() );
144 io->ReadImageInformation();
146 if ( io->GetPixelType() == itk::ImageIOBase::SCALAR )
148 switch ( io->GetComponentType() )
157 <<
"Found unsupported DICOM scalar pixel type: (enum value) "
158 << io->GetComponentType();
161 else if ( io->GetPixelType() == itk::ImageIOBase::RGB )
163 switch ( io->GetComponentType() )
167 DcmIoType::USHORT, itk::RGBPixel<unsigned short>)
switch3DnTCase(DcmIoType::SHORT,
168 itk::RGBPixel<short>)
170 DcmIoType::INT, itk::RGBPixel<int>)
switch3DnTCase(DcmIoType::ULONG,
171 itk::RGBPixel<long unsigned int>)
173 DcmIoType::FLOAT, itk::RGBPixel<float>)
switch3DnTCase(DcmIoType::DOUBLE,
174 itk::RGBPixel<double>)
default
176 <<
"Found unsupported DICOM scalar pixel type: (enum value) "
177 << io->GetComponentType();
185 catch (
const itk::MemoryAllocationError& e )
187 MITK_ERROR <<
"Out of memory. Cannot load DICOM series: " << e.what();
189 catch (
const std::exception& e )
191 MITK_ERROR <<
"Error encountered when loading DICOM series:" << e.what();
195 MITK_ERROR <<
"Unspecified error encountered when loading DICOM series.";
202 const std::string& timeString,
205 OFString content( timeString.c_str() );
207 if ( !dateString.empty() )
209 content = OFString( dateString.c_str() ).append( content );
212 const OFCondition result = DcmDateTime::getOFDateTimeFromString( content, time );
214 return result.good();
219 const boost::gregorian::date boostDate(
220 time.getDate().getYear(), time.getDate().getMonth(), time.getDate().getDay() );
222 const boost::posix_time::time_duration boostTime =
223 boost::posix_time::hours( time.getTime().getHour() )
224 + boost::posix_time::minutes( time.getTime().getMinute() )
225 + boost::posix_time::seconds( time.getTime().getSecond() )
226 + boost::posix_time::milliseconds( time.getTime().getMilliSecond() );
228 boost::posix_time::ptime result( boostDate, boostTime );
235 OFDateTime result = time1;
237 if ( ( time2.getDate() < time1.getDate() )
238 || ( ( time2.getDate() == time1.getDate() ) && ( time2.getTime() < time1.getTime() ) ) )
248 OFDateTime result = time1;
250 if ( ( time2.getDate() > time1.getDate() )
251 || ( ( time2.getDate() == time1.getDate() ) && ( time2.getTime() > time1.getTime() ) ) )
264 ::boost::posix_time::time_duration duration = stopTime - startTime;
266 double result = duration.total_milliseconds();
271 bool mitk::ITKDICOMSeriesReaderHelper::ExtractTimeBoundsOfTimeStep(
272 const StringContainer& filenamesOfTimeStep, DateTimeBounds& bounds )
274 const DICOMTag acquisitionDateTag( 0x0008, 0x0022 );
275 const DICOMTag acquisitionTimeTag( 0x0008, 0x0032 );
278 filescanner->SetInputFiles( filenamesOfTimeStep );
279 filescanner->AddTag( acquisitionDateTag );
280 filescanner->AddTag( acquisitionTimeTag );
288 for (DICOMDatasetAccessingImageFrameList::const_iterator pos = frameList.cbegin(); pos != frameList.cend(); ++pos)
290 const std::string dateStr = ( *pos )->GetTagValueAsString( acquisitionDateTag ).value;
291 const std::string timeStr = ( *pos )->GetTagValueAsString( acquisitionTimeTag ).value;
316 mitk::ITKDICOMSeriesReaderHelper::TimeBoundsList
317 mitk::ITKDICOMSeriesReaderHelper::ExtractTimeBoundsOfTimeSteps(
318 const StringContainerList& filenamesOfTimeSteps )
320 TimeBoundsList result;
323 bool baseLineSet =
false;
325 for ( StringContainerList::const_iterator pos = filenamesOfTimeSteps.cbegin();
326 pos != filenamesOfTimeSteps.cend();
330 DateTimeBounds dateTimeBounds;
332 if ( ExtractTimeBoundsOfTimeStep( *pos, dateTimeBounds ) )
337 baseLine = dateTimeBounds[0];
344 result.push_back( bounds );
351 mitk::ITKDICOMSeriesReaderHelper::GenerateTimeGeometry(
const BaseGeometry* templateGeometry,
352 const TimeBoundsList& boundsList )
357 const auto boundListSize = boundsList.size();
358 for (
auto pos = 0; pos < boundListSize; ++pos )
360 check += boundsList[pos][0];
361 check += boundsList[pos][1];
368 newTimeGeometry->Initialize( templateGeometry, boundListSize );
369 timeGeometry = newTimeGeometry.GetPointer();
374 newTimeGeometry->ClearAllGeometries();
375 newTimeGeometry->ReserveSpaceForGeometries( boundListSize );
377 for (
auto pos = 0; pos < boundListSize; ++pos )
380 if ( pos + 1 < boundListSize )
382 bounds[1] = boundsList[pos + 1][0];
385 newTimeGeometry->AppendTimeStepClone( templateGeometry, bounds[1], bounds[0] );
387 timeGeometry = newTimeGeometry.GetPointer();
itk::SmartPointer< Self > Pointer
OFDateTime GetUpperDateTime(const OFDateTime &time1, const OFDateTime &time2)
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
static bool CanHandleFile(const std::string &filename)
Image::Pointer Load(const StringContainer &filenames, bool correctTilt, const GantryTiltInformation &tiltInfo)
itk::SmartPointer< Self > Pointer
OFDateTime GetLowerDateTime(const OFDateTime &time1, const OFDateTime &time2)
Image::Pointer Load3DnT(const StringContainerList &filenamesLists, bool correctTilt, const GantryTiltInformation &tiltInfo)
#define switch3DnTCase(IOType, T)
static const std::string filename
bool ConvertDICOMDateTimeString(const std::string &dateString, const std::string &timeString, OFDateTime &time)
std::list< StringContainer > StringContainerList
itk::SmartPointer< Self > Pointer
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
itk::SmartPointer< Self > Pointer
boost::posix_time::ptime ConvertOFDateTimeToPTime(const OFDateTime &time)
MITKCORE_EXPORT const ScalarType eps
double ComputeMiliSecDuration(const OFDateTime &start, const OFDateTime &stop)
std::vector< std::string > StringContainer
#define switch3DCase(IOType, T)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.