From ca6a1bf1319c88ce8717ad804c76c69cd6fcb87f Mon Sep 17 00:00:00 2001 From: delmon Date: Fri, 15 Apr 2011 11:15:46 +0000 Subject: [PATCH] Mathieu Malaterre gdcm2 migration: + vv open Dicom still a segfault when reading spacing --- vv/vvMeshReader.cxx | 34 ++++++++++++++++++++++++++++++++-- vv/vvQDicomSeriesSelector.cxx | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/vv/vvMeshReader.cxx b/vv/vvMeshReader.cxx index fc420d4..142609a 100644 --- a/vv/vvMeshReader.cxx +++ b/vv/vvMeshReader.cxx @@ -21,9 +21,12 @@ #include #if GDCM_MAJOR_VERSION == 2 + #include + #include + #include #else -#include -#include + #include + #include #endif #include @@ -86,6 +89,33 @@ std::vector > vvMeshReader::GetROINames() assert(filename!=""); std::vector > roi_names; #if GDCM_MAJOR_VERSION == 2 + // duplicate code from clitk::DicomRT_StructureSet::Read + gdcm::Reader reader; + reader.SetFileName( filename.c_str() ); + reader.Read(); + + const gdcm::DataSet &ds = reader.GetFile().GetDataSet(); + + gdcm::Tag tssroisq(0x3006,0x0020); + const gdcm::DataElement &ssroisq = ds.GetDataElement( tssroisq ); + gdcm::SmartPointer roi_seq = ssroisq.GetValueAsSQ(); + assert(roi_seq); // TODO error message + for(unsigned int ridx = 0; ridx < roi_seq->GetNumberOfItems(); ++ridx) + { + gdcm::Item & item = roi_seq->GetItem( ridx + 1); // Item starts at 1 + const gdcm::DataSet& nestedds = item.GetNestedDataSet(); + if( nestedds.FindDataElement( gdcm::Tag(0x3006,0x22) ) ) + { + gdcm::Attribute<0x3006,0x26> roiname; + roiname.SetFromDataSet( nestedds ); + std::string name = roiname.GetValue(); // 0x3006,0x0026 = [ROI Name] + gdcm::Attribute<0x3006,0x0022> roinumber; + roinumber.SetFromDataSet( nestedds ); + int nb = roinumber.GetValue(); // 0x3006,0x0022 = [ROI Number] + + roi_names.push_back(make_pair(nb,name)); + } + } #else gdcm::File reader; reader.SetFileName(filename.c_str()); diff --git a/vv/vvQDicomSeriesSelector.cxx b/vv/vvQDicomSeriesSelector.cxx index 2740767..34c8e21 100644 --- a/vv/vvQDicomSeriesSelector.cxx +++ b/vv/vvQDicomSeriesSelector.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #else #include #endif @@ -203,6 +204,7 @@ void vvDicomSeriesSelector::itemSelectionChanged() if (mDicomInfo[mCurrentSerie] == "") { // QString m; // m = QString("Patient : %1
").arg(mDicomHeader[s]->GetEntryValue(0x0010,0x0010).c_str()); // Patient's name + DD(mCurrentSerie) mDicomInfo[mCurrentSerie] = MakeDicomInfo(mCurrentSerie, mDicomHeader[mCurrentSerie]); } ui.mDicomInfoPanel->setText(mDicomInfo[mCurrentSerie]); @@ -278,7 +280,36 @@ QString vvDicomSeriesSelector::MakeDicomInfo(std::string & s, gdcm::File *header { QString n = QString("%1").arg(mListOfSeriesFilenames[s]->size()); #if GDCM_MAJOR_VERSION == 2 - QString ss; + const gdcm::File &f = *header; + std::vector thespacing = gdcm::ImageHelper::GetSpacingValue(f); + std::vector theorigin = gdcm::ImageHelper::GetOriginValue(f); + + QString size = QString("%1x%2x%3") + .arg(0) + .arg(0) + .arg(0); + QString spacing = QString("%1x%2x%3") + .arg(thespacing[0]) + .arg(thespacing[1]) + .arg(thespacing[2]); + QString origin = QString("%1x%2x%3") + .arg(theorigin[0]) + .arg(theorigin[1]) + .arg(theorigin[2]); + + QString ss = + //AddInfo( "Serie ID : ", s)+ + AddInfo(header, "Patient : ", 0x0010,0x0010)+ + AddInfo( "Folder : ", QFileInfo((*mFilenames)[0].c_str()).canonicalPath().toStdString())+ + AddInfo(header, "Series Description : ", 0x0008,0x103e)+ + AddInfo(header, "Modality : ", 0x0008,0x0060)+ + AddInfo(header, "# images : ", 0x0020,0x0013)+ + AddInfo( "# files : ", n.toStdString())+ + AddInfo( "Size : ", size.toStdString())+ + AddInfo( "Spacing : ", spacing.toStdString())+ + AddInfo( "Origin : ", origin.toStdString())+ + AddInfo(header, "Pixel size : ", 0x0028,0x0100)+ + AddInfo( "Pixel type : ", 0); #else QString size = QString("%1x%2x%3") .arg(header->GetXSize()) -- 2.47.1