Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F648
Philips3D_DCM_Patch.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
graser
Dec 29 2010, 4:13 PM
2010-12-29 16:13:46 (UTC+1)
Size
15 KB
Referenced Files
None
Subscribers
None
Philips3D_DCM_Patch.patch
View Options
Index: mitkDicomSeriesReader.txx
===================================================================
--- mitkDicomSeriesReader.txx (revision 28567)
+++ mitkDicomSeriesReader.txx (working copy)
@@ -21,102 +21,274 @@
#include <mitkDicomSeriesReader.h>
#include <itkImageSeriesReader.h>
-
+//#define GDCM_MAJOR_VERSION 3
#if GDCM_MAJOR_VERSION >= 2
- #include <gdcmSorter.h>
- #include <gdcmScanner.h>
+#include <gdcmSorter.h>
+#include <gdcmScanner.h>
+#include <gdcmPixmapReader.h>
+#include <gdcmStringFilter.h>
+#include <gdcmRAWCodec.h>
#endif
namespace mitk
{
-template <typename PixelType>
-void DicomSeriesReader::LoadDicom(const StringContainer &filenames, DataNode &node, UpdateCallBackMethod callback)
-{
- const char* previousCLocale = setlocale(LC_NUMERIC, NULL);
- setlocale(LC_NUMERIC, "C");
- std::locale previousCppLocale( std::cin.getloc() );
- std::locale l( "C" );
- std::cin.imbue(l);
-
- try
+ template <typename PixelType>
+ void DicomSeriesReader::LoadDicom(const StringContainer &filenames, DataNode &node, UpdateCallBackMethod callback)
{
- mitk::Image::Pointer image = mitk::Image::New();
- CallbackCommand *command = callback ? new CallbackCommand(callback) : 0;
+ const char* previousCLocale = setlocale(LC_NUMERIC, NULL);
+ setlocale(LC_NUMERIC, "C");
+ std::locale previousCppLocale( std::cin.getloc() );
+ std::locale l( "C" );
+ std::cin.imbue(l);
+ try
+ {
+ mitk::Image::Pointer image = mitk::Image::New();
+ CallbackCommand *command = callback ? new CallbackCommand(callback) : 0;
+
#if GDCM_MAJOR_VERSION >= 2
- /******** Workaround for 4D data ***************/
- gdcm::Sorter sorter;
+ /******** Workaround for Philips 3D+t images ********/
- sorter.SetSortFunction(DicomSeriesReader::GdcmSortFunction);
- sorter.Sort(filenames);
+ //Look at 3001,0010 if it is Philips3D
+ gdcm::PixmapReader reader;
+ reader.SetFileName(filenames.front().c_str());
+ reader.Read();
+ gdcm::DataSet &data_set = reader.GetFile().GetDataSet();
+ gdcm::StringFilter sf;
+ sf.SetFile(reader.GetFile());
- gdcm::Tag tag(0x0020,0x1041); //Slice location
- gdcm::Scanner scanner;
+ if (data_set.FindDataElement(gdcm::Tag(0x3001, 0x0010)) &&
+ (sf.ToString(gdcm::Tag(0x3001, 0x0010)) == "Philips3D "))
+ {
+ // It is Philips3D!
+ // Now get PhilipsSpecific Tags
+ gdcm::Attribute<0x0028,0x0011> dimTagX; // coloumns || sagittal
+ gdcm::Attribute<0x3001,0x1001, gdcm::VR::UL, gdcm::VM::VM1> dimTagZ; //I have no idea what is VM1. // (Philips specific) // transversal
+ gdcm::Attribute<0x0028,0x0010> dimTagY; // rows || coronal
+ gdcm::Attribute<0x0028,0x0008> dimTagT;
+ gdcm::Attribute<0x0018,0x602c> spaceTagX;
+ gdcm::Attribute<0x0018,0x602e> spaceTagY;
+ gdcm::Attribute<0x3001,0x1003, gdcm::VR::FD, gdcm::VM::VM1> spaceTagZ; // (Philips specific)
+ gdcm::Attribute<0x0018,0x6024> physicalTagX;
+ gdcm::Attribute<0x0018,0x6026> physicalTagY;
+ gdcm::Attribute<0x3001,0x1002, gdcm::VR::US, gdcm::VM::VM1> physicalTagZ; // (Philips specific)
- scanner.AddTag(tag);
- scanner.Scan(sorter.GetFilenames());
+ dimTagX.Set(data_set);
+ dimTagY.Set(data_set);
+ dimTagZ.Set(data_set);
+ dimTagT.Set(data_set);
+ spaceTagX.Set(data_set);
+ spaceTagY.Set(data_set);
+ spaceTagZ.Set(data_set);
+ physicalTagX.Set(data_set);
+ physicalTagY.Set(data_set);
+ physicalTagZ.Set(data_set);
- std::list<StringContainer> decomposed_filenames;
- const StringContainer::const_iterator f_end = sorter.GetFilenames().end();
- const char *act_value = scanner.GetValue(sorter.GetFilenames().front().c_str(), tag);
- unsigned int volume_count = 1u;
+ unsigned int
+ dimX = dimTagX.GetValue(),
+ dimY = dimTagY.GetValue(),
+ dimZ = dimTagZ.GetValue(),
+ dimT = dimTagT.GetValue(),
+ physicalX = physicalTagX.GetValue(),
+ physicalY = physicalTagY.GetValue(),
+ physicalZ = physicalTagZ.GetValue();
- decomposed_filenames.push_back(StringContainer());
- decomposed_filenames.back().push_back(sorter.GetFilenames().front());
+ float
+ spaceX = spaceTagX.GetValue(),
+ spaceY = spaceTagY.GetValue(),
+ spaceZ = spaceTagZ.GetValue();
- for (StringContainer::const_iterator f_it = ++sorter.GetFilenames().begin(); f_it != f_end; ++f_it)
- {
- const char *value = scanner.GetValue(f_it->c_str(), tag);
+ // Ok, got all necessary Tags!
+ // Now read Pixeldata (7fe0,0010) X x Y x Z x T Elements
- if (!strcmp(act_value, value))
+ const gdcm::Pixmap &pixels = reader.GetPixmap();
+ gdcm::RAWCodec codec;
+
+ codec.SetPhotometricInterpretation(gdcm::PhotometricInterpretation::MONOCHROME2);
+ codec.SetPixelFormat(pixels.GetPixelFormat());
+ codec.SetPlanarConfiguration(0);
+
+ gdcm::DataElement out;
+ codec.Decode(data_set.GetDataElement(gdcm::Tag(0x7fe0, 0x0010)), out);
+
+ const gdcm::ByteValue *bv = out.GetByteValue();
+ const char *new_pixels = bv->GetPointer();
+
+ // Create MITK Image + Geometry
+ typedef itk::Image<PixelType, 4> ImageType;
+ typename ImageType::RegionType myRegion;
+ typename ImageType::SizeType mySize;
+ typename ImageType::IndexType myIndex;
+ typename ImageType::SpacingType mySpacing;
+ ImageType::Pointer imageItk = ImageType::New();
+
+ mySpacing[0] = spaceX;
+ mySpacing[1] = spaceY;
+ mySpacing[2] = spaceZ;
+ myIndex[0] = physicalX;
+ myIndex[1] = physicalY;
+ myIndex[2] = physicalZ;
+ mySize[0] = dimX;
+ mySize[1] = dimY;
+ mySize[2] = dimZ;
+ mySize[3] = dimT;
+ myRegion.SetSize( mySize);
+ myRegion.SetIndex( myIndex );
+ imageItk->SetSpacing(mySpacing);
+ imageItk->SetRegions( myRegion);
+ imageItk->Allocate();
+ imageItk->FillBuffer(0);
+
+ typename itk::ImageRegionIterator<ImageType> iterator(imageItk, imageItk->GetLargestPossibleRegion());
+ iterator.GoToBegin();
+ unsigned long pixCount = 0;
+ unsigned long planeSize = dimX*dimY;
+ unsigned long planeCount = 0;
+ unsigned long timeCount = 0;
+ unsigned long numberOfSlices = dimZ;
+
+
+ while (!iterator.IsAtEnd())
+ {
+ unsigned long adressedPixel =
+ pixCount
+ + (numberOfSlices-1-planeCount)*planeSize // add offset to adress the first pixel of current plane
+ + timeCount*numberOfSlices*planeSize; // add time offset
+
+ iterator.Set( new_pixels[ adressedPixel ] );
+ pixCount++;
+ iterator++;
+
+ if (pixCount == planeSize)
+ {
+ pixCount = 0;
+ planeCount++;
+ }
+ if (planeCount == numberOfSlices)
+ {
+ planeCount = 0;
+ timeCount++;
+ }
+ if (timeCount == dimT)
+ {
+ break;
+ }
+ }
+ mitk::CastToMitkImage(imageItk, image);
+
+ /*
+ // this works as well, but then the picture is upside down.. transversal slice[max] should be transversal slice[0] and so on.
+ while (!iterator.IsAtEnd())
+ {
+ iterator.Set( new_pixels[pixCount] );
+ pixCount++;
+ iterator++;
+ }
+ mitk::CastToMitkImage(imageItk, image);
+ */
+
+ }
+ /******** END: Workaround for Phillips 3D+t images ********/
+ else
{
- act_value = value;
+ /******** Workaround for 4D data ***************/
+ gdcm::Sorter sorter;
+
+ sorter.SetSortFunction(DicomSeriesReader::GdcmSortFunction);
+ sorter.Sort(filenames);
+
+ gdcm::Tag tag(0x0020,0x1041); //Slice location
+ gdcm::Scanner scanner;
+
+ scanner.AddTag(tag);
+ scanner.Scan(sorter.GetFilenames());
+
+ std::list<StringContainer> decomposed_filenames;
+ const StringContainer::const_iterator f_end = sorter.GetFilenames().end();
+ const char *act_value = scanner.GetValue(sorter.GetFilenames().front().c_str(), tag);
+ unsigned int volume_count = 1u;
+
decomposed_filenames.push_back(StringContainer());
- ++volume_count;
- }
+ decomposed_filenames.back().push_back(sorter.GetFilenames().front());
- decomposed_filenames.back().push_back(*f_it);
- }
- /******** End: Workaround for 4D data **********/
+ for (StringContainer::const_iterator f_it = ++sorter.GetFilenames().begin(); f_it != f_end; ++f_it)
+ {
+ const char *value = scanner.GetValue(f_it->c_str(), tag);
- if (volume_count > 1)
- {
- typedef itk::Image<PixelType, 4> ImageType;
- typedef itk::ImageSeriesReader<ImageType> ReaderType;
+ if (!strcmp(act_value, value))
+ {
+ act_value = value;
+ decomposed_filenames.push_back(StringContainer());
+ ++volume_count;
+ }
- DcmIoType::Pointer io = DcmIoType::New();
- typename ReaderType::Pointer reader = ReaderType::New();
+ decomposed_filenames.back().push_back(*f_it);
+ }
+ /******** End: Workaround for 4D data **********/
- reader->SetImageIO(io);
- reader->ReverseOrderOff();
+ if (volume_count > 1)
+ {
+ typedef itk::Image<PixelType, 4> ImageType;
+ typedef itk::ImageSeriesReader<ImageType> ReaderType;
- if (command)
- {
- reader->AddObserver(itk::ProgressEvent(), command);
- }
+ DcmIoType::Pointer io = DcmIoType::New();
+ typename ReaderType::Pointer reader = ReaderType::New();
- const std::list<StringContainer>::const_iterator df_end = decomposed_filenames.end();
- unsigned int act_volume = 1u;
+ reader->SetImageIO(io);
+ reader->ReverseOrderOff();
- reader->SetFileNames(decomposed_filenames.front());
- reader->Update();
- image->InitializeByItk(reader->GetOutput(), 1, volume_count);
- image->SetImportVolume(reader->GetOutput()->GetBufferPointer(), 0u);
+ if (command)
+ {
+ reader->AddObserver(itk::ProgressEvent(), command);
+ }
- MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << ", " << image->GetDimension(3) << "]";
- MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";
+ const std::list<StringContainer>::const_iterator df_end = decomposed_filenames.end();
+ unsigned int act_volume = 1u;
- for (std::list<StringContainer>::iterator df_it = ++decomposed_filenames.begin(); df_it != df_end; ++df_it)
- {
- reader->SetFileNames(*df_it);
- reader->Update();
- image->SetImportVolume(reader->GetOutput()->GetBufferPointer(), act_volume++);
+ reader->SetFileNames(decomposed_filenames.front());
+ reader->Update();
+ image->InitializeByItk(reader->GetOutput(), 1, volume_count);
+ image->SetImportVolume(reader->GetOutput()->GetBufferPointer(), 0u);
+
+ MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << ", " << image->GetDimension(3) << "]";
+ MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";
+
+ for (std::list<StringContainer>::iterator df_it = ++decomposed_filenames.begin(); df_it != df_end; ++df_it)
+ {
+ reader->SetFileNames(*df_it);
+ reader->Update();
+ image->SetImportVolume(reader->GetOutput()->GetBufferPointer(), act_volume++);
+ }
+ }
+ else
+ {
+ typedef itk::Image<PixelType, 3> ImageType;
+ typedef itk::ImageSeriesReader<ImageType> ReaderType;
+
+ DcmIoType::Pointer io = DcmIoType::New();
+ typename ReaderType::Pointer reader = ReaderType::New();
+
+ reader->SetImageIO(io);
+ reader->ReverseOrderOff();
+
+ if (command)
+ {
+ reader->AddObserver(itk::ProgressEvent(), command);
+ }
+
+ reader->SetFileNames(filenames);
+ reader->Update();
+ image->InitializeByItk(reader->GetOutput());
+ image->SetImportVolume(reader->GetOutput()->GetBufferPointer());
+
+ MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << "]";
+ MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";
+ }
}
- }
- else
- {
+
+#else
typedef itk::Image<PixelType, 3> ImageType;
typedef itk::ImageSeriesReader<ImageType> ReaderType;
@@ -138,48 +310,24 @@
MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << "]";
MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";
- }
-#else
- typedef itk::Image<PixelType, 3> ImageType;
- typedef itk::ImageSeriesReader<ImageType> ReaderType;
+#endif
- DcmIoType::Pointer io = DcmIoType::New();
- typename ReaderType::Pointer reader = ReaderType::New();
+ node.SetData(image);
- reader->SetImageIO(io);
- reader->ReverseOrderOff();
+ setlocale(LC_NUMERIC, previousCLocale);
+ std::cin.imbue(previousCppLocale);
- if (command)
+ }
+ catch (std::exception& e)
{
- reader->AddObserver(itk::ProgressEvent(), command);
+ setlocale(LC_NUMERIC, previousCLocale);
+ std::cin.imbue(previousCppLocale);
+
+ throw e;
}
-
- reader->SetFileNames(filenames);
- reader->Update();
- image->InitializeByItk(reader->GetOutput());
- image->SetImportVolume(reader->GetOutput()->GetBufferPointer());
-
- MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << "]";
- MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";
-
-#endif
-
- node.SetData(image);
-
- setlocale(LC_NUMERIC, previousCLocale);
- std::cin.imbue(previousCppLocale);
-
}
- catch (std::exception& e)
- {
- setlocale(LC_NUMERIC, previousCLocale);
- std::cin.imbue(previousCppLocale);
- throw e;
- }
}
-}
-
#endif
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
623
Default Alt Text
Philips3D_DCM_Patch.patch (15 KB)
Attached To
Mode
T6397: Support für Philips Ultraschalldaten
Attached
Detach File
Event Timeline
graser
added a comment.
Dec 29 2010, 4:13 PM
2010-12-29 16:13:46 (UTC+1)
Comment Actions
To support Philips3D DCM files
Log In to Comment