[Insight-users] How to load sequence items

Subrahmanyam Gorthi subrahmanyam.gorthi at gmail.com
Mon Nov 24 05:01:11 EST 2008


Hi Brano,

Sorry for the delay in my response.
I have not yet submitted that article. I still have to fix some things in my
code.

I was previously writing the sequence data into a DICOM file, but not
reading.
Thanks to the suggestions of Mathieu for writing DICOM sequences.

I will mention here how I was writing the DICOM sequences. Similar approach
may be helpful for loading as well.


// Each sequence is encapsulated inside a dictionary, and this dictionary is
// further encapsulated inside the final dictionary which is passed to the
writer.

// Each Sequence can contain multiple items.
// So, for separating the items within a sequence, they are also
encapsulated
// inside dictionary.
// But for distinguishing the dictionary of sequence from a dictionary of
Item,
// a special string is used for items.
//
//
// For instance, the following special string is used for distinguishing the
// encapsulation of an Item of DICOM sequence from the encapsulation of the
// DICOM sequence itself.
//
const std::string ITEM_ENCAPSULATE_STRING("DICOM_ITEM_ENCAPSULATE");


// Here is an Example:
// The following is the sequence to be written along with it's associated
tags:

//  Structure Set ROI Sequence:           (3006|0020)
//    > ROI Number                        (3006|0022)
//    > Referenced Frame of ref. UID      (3006|0024)
//    > ROI Name                          (3006|0026)
//    > ROI Generation Algorithm          (3006|0036)
//



  // Declaration of strings
  string roiNumber = "1";
  string roiName = "External Contour";
  string frameOfReferenceUID =
"1.2.840.113619.2.55.3.464283444.427.1208496883.210.11425.1";
  string roiGenAlgorithm = "ITK-GDCM based algorithm";

  // string for distinguishing items inside sequence:
  string tempString = ITEM_ENCAPSULATE_STRING + "01";

  typedef itk::RTSTRUCTIO               STRUCTOutType;
  typedef itk::MetaDataDictionary       DictionaryType;

   // Final Dictionary that will be passed to RTSTRUCTIO
  STRUCTOutType::Pointer gdcmIO2 = STRUCTOutType::New();
  DictionaryType& dictWriter = gdcmIO2->GetMetaDataDictionary();

  // Dictionary for encapsulating the sequences.
  STRUCTOutType::Pointer gdcmIOStructureSetRoi = STRUCTOutType::New();
  DictionaryType &structureSetRoiSeq =
gdcmIOStructureSetRoi->GetMetaDataDictionary();

  // Dictionary for encapsulating the items within sequences
  STRUCTOutType::Pointer gdcmIOItem = STRUCTOutType::New();
  DictionaryType &itemDict = gdcmIOItem->GetMetaDataDictionary();

  itk::EncapsulateMetaData<string>(itemDict, "3006|0022", roiNumber);
  itk::EncapsulateMetaData<string>(itemDict, "3006|0024",
frameOfReferenceUID);
  itk::EncapsulateMetaData<string>(itemDict, "3006|0026", roiName);
  itk::EncapsulateMetaData<string>(itemDict, "3006|0036", roiGenAlgorithm);

  itk::EncapsulateMetaData<DictionaryType>(structureSetRoiSeq, tempString,
itemDict);


  itk::EncapsulateMetaData<DictionaryType>(dictWriter, "3006|0020",
structureSetRoiSeq);


// The above dictWriter is passed in the RTSTRUCTIO class.
// While parsing, if the type of object inside dictWriter is another
dictionary,
// it is passed to the following function:
//

bool RTSTRUCTIO::InsertDICOMSequence(MetaDataDictionary &sub_dict,
                                     const unsigned int itemDepthLevel,
                                     gdcm::SeqEntry     *seqEntry)

{
  gdcm::SQItem *sqItem = NULL;

  itk::MetaDataDictionary::ConstIterator itr = sub_dict.Begin();
  itk::MetaDataDictionary::ConstIterator end = sub_dict.End();

  while(itr != end)
  {
    // Get the key
    const std::string &inside_key = itr->first;

    // To separate the items from each other, each item is
    // encapsulated inside a dictionary and to distinguish them against
sub-sequences,
    // special-predefined-strings are associated with those dictionaries.
    //
    // In such cases, inside sub-dictionary associated with those
    // special-predefined-strings is passed to this self-calling function.

    if (ITEM_ENCAPSULATE_STRING == inside_key.substr(0,
ITEM_ENCAPSULATE_STRING.length()))
    {
      // Get the dictionary associted with that string...
      itk::MetaDataDictionary actual_sub_dict;
      ExposeMetaData<itk::MetaDataDictionary>(sub_dict, inside_key,
actual_sub_dict);

      // Call this function on that sub-dictionary
      InsertDICOMSequence(actual_sub_dict, itemDepthLevel, seqEntry);
    } else
    {
      if ( itr == sub_dict.Begin() )
      {
        sqItem = new gdcm::SQItem(itemDepthLevel);
      }

      assert( sqItem != NULL );

      // if the value associated with this key is again a dictionary,
      // recursively call this function to insert a sub-sequence:
      if( typeid(sub_dict).name() ==
(sub_dict[inside_key].GetPointer())->GetMetaDataObjectTypeName() )
      {
        itk::MetaDataDictionary inside_sub_dict;
        ExposeMetaData<itk::MetaDataDictionary>(sub_dict, inside_key,
inside_sub_dict);

        // if the attached sub-dictinary is a sequence, then.......
        gdcm::SeqEntry *sub_seqEntry = new gdcm::SeqEntry(

gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(inside_key));
        InsertDICOMSequence(inside_sub_dict, itemDepthLevel+1,
sub_seqEntry);

        sqItem->AddEntry(sub_seqEntry);

      } else // if the value associated with the key is a string, directly
add it to the sequence
      {
        std::string inside_value;
        ExposeMetaData<std::string>(sub_dict, inside_key, inside_value);

        gdcm::ValEntry *inside_valEntry = new gdcm::ValEntry(

gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(inside_key) );
        inside_valEntry->SetValue(inside_value);

        sqItem->AddEntry(inside_valEntry);
      }
    }
    ++itr;
  }
  if (sqItem != NULL)
  {
    // 2nd argument: ordinal number of the seq-item
    // seqEntry->AddSQItem(sqItem, seqEntry->GetNumberOfSQItems()+1);
    seqEntry->AddSQItem(sqItem, seqEntry->GetNumberOfSQItems());
  }
  return true;
}


Thank you.

Warm Regards,
Subrahmanyam Gorthi.




On Sat, Nov 22, 2008 at 3:11 PM, Dan Mueller <dan.muel at gmail.com> wrote:

> Hi Brano,
>
> I guess you'll need check with the author...I don't recall seeing the
> IJ article yet.
>
> Cheers, Dan
>
> 2008/11/22 Branislav Goga <brano.goga at centrum.sk>:
> >
> > Thanks for that link, very interesting, but is there some link to
> > implementation, I didn`t found any in IJ, do I miss something? Are there
> > some plans to integrate it into future ITK builds? I think for a lot of
> > people this could be very interesting and will simplify usage of ITK for
> > several research tasks.
> >
> > regards
> > Brano
> >
> >
> > Dan Mueller-2 wrote:
> >>
> >> Hi Siqi,
> >>
> >> AFAIK, ITK does not provide support for reading/writing "ROI Contour
> >> Sequences".
> >>
> >> By the way, do you actually mean RTSTRUCT sets? If so, then you may be
> >> interested in the following discussion thread regarding the addition
> >> of a writer for RTSTRUCT sets to ITK. Though I don't think the reader
> >> has been implemented yet...
> >>
> >> http://www.cmake.org/pipermail/insight-users/2008-September/027272.html
> >>
> >> Hope this helps.
> >>
> >> Regards, Dan
> >>
> >> 2008/11/21 chensiqi <pidanchen at hotmail.com>:
> >>>
> >>> Hi, ITKers,
> >>>
> >>> Does anybody know how to load sequence items using ITK? Such as "ROI
> >>> Contour
> >>> Sequence".
> >>> Or if you know how to do it in GDCM, and integrate into ITK, that will
> >>> also
> >>> be very helpful.
> >>>
> >>> Thanks
> >>> Siqi
> >>>
> >>>
> >>> ________________________________
> >>> 更多热辣资讯尽在新版MSN首页! 立刻访问!
> >>> _______________________________________________
> >>> Insight-users mailing list
> >>> Insight-users at itk.org
> >>> http://www.itk.org/mailman/listinfo/insight-users
> >>>
> >>>
> >> _______________________________________________
> >> Insight-users mailing list
> >> Insight-users at itk.org
> >> http://www.itk.org/mailman/listinfo/insight-users
> >>
> >>
> >
> > --
> > View this message in context:
> http://www.nabble.com/How-to-load-sequence-items-tp20622657p20635416.html
> > Sent from the ITK - Users mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081124/582be75f/attachment-0001.htm>


More information about the Insight-users mailing list