[Insight-users] DICOM Tags From One Slice

Luis Ibanez luis.ibanez at kitware.com
Mon Aug 28 12:09:45 EDT 2006



Hi 肖 潇

If you are reusing an iterator for a second loop,
you *must* reinitialize the iterator to be at the
"begin()" of the container.


Your code should look like:


  // First loop
  DictionaryType::ConstIterator itr = dictionary.Begin();
  DictionaryType::ConstIterator end = dictionary.End();

  while( itr != end )
   {
   // do stuff with "itr"
   ++itr;
   }


  itr = dictionary.Begin(); // THIS IS WHAT YOU ARE MISSING


  // Second loop
  while( itr != end )
   {
   // do stuff with "itr"
   ++itr;
   }



  Regards,



     Luis


====================
肖 潇 wrote:
> Hi,
> 
> I have a problem while editing my code with VC6.0 in WindowsXP.
> 
> I was following the example which is in ItkSoftwareGuide-2.6.0.pdf, 
> Chapter 7.12.5 Printing DICOM Tags From One Slice.(Page 305)
> 
> When it run into the while loop for the first time, everything was 
> perfect. However,after ++itr; run into the while for the second loop, 
> the cursor run to this line: /MetaDataStringType::Pointer entryvalue 
> =dynamic_cast<MetaDataStringType *>( entry.GetPointer() ) ; /
> 
> then it was caught by the
> 
> /catch (...) {
>         CHKExceptionProcess::GetHKExc()->Execute 
> ("CHKReader_Dicom::ReadFile() Error ! ");
>         return -1;
>  }/
> 
> in order to find out what was wrong, I changed the code as follows,
> 
> /....../
> 
> /itr++;/
> 
> ///while( itr != end )//{
> itk::MetaDataObjectBase::Pointer entry = itr->second;
> MetaDataStringType::Pointer entryvalue =
> dynamic_cast<MetaDataStringType *>( entry.GetPointer() ) ;/
> 
> /....../
> 
> ///++itr;/
> 
> ///}/
> 
> Again, when it run to dynamic_cast, the exception  came out as the same.
> 
> I wonder to know how to fix in this case. Is it the smart point or the 
> const_iterator which I am in wrong use? or the operator++, or the 
> dynamic_cast cause this problem?
> 
> I have included the needed headfiles, perhaps is not this reason.
> 
> Longing for some kind people to reply.
> 
> 
> 
> ------------------------------------------------------------------------
> 免费下载 MSN Explorer <http://g.msn.com/8HMACNCN/2740??PS=47575>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users




More information about the Insight-users mailing list