[Insight-users] [GDCM] Can't read easily value of a DataElement

Chr. Rossmanith cr at neuro.ma.uni-heidelberg.de
Fri Mar 30 05:59:45 EDT 2012


You can access the value as unsigned short and convert it to a string:

unsigned short SamplesPerPixel = *((unsigned short *) 
p_Elem.GetByteValue()->GetPointer());
std::stringstream s_SamplesPerPixel;
s_SamplesPerPixel << SamplesPerPixel;
p_Str = s_SamplesPerPixel.str();

Christina

Am 23.03.2012 09:14, schrieb Daanen:
>
> Hi,
>
> I recently upgrade from itk 3.16 to itk 4.1.
>
> I thus have to update my code source to use the new gdcm core (2.0.x)
>
> Previously, I wrote a method (for internal use) which returns the 
> value of a given Tag as string.
>
> This method now uses a gdcm::DataElement as parameter.
>
> But I can't get the value of the DataElement as a string in all the case.
>
> My code is the following
>
> staticbool GetValue(std::string &p_Str, const gdcm::DataElement &p_Elem)
>
> {
>
>       p_Str.clear();
>
> if (p_Elem.GetByteValue() == NULL) return false;
>
>       p_Str = 
> std::string(p_Elem.GetByteValue()->GetBuffer(),p_Elem.GetByteValue()->GetLength());
>
> return !p_Str.empty();
>
> }
>
> But for a given tag (SamplesPerPixel, which VR = US and Value is 1), 
> p_Str is not "1" but " ". This seems to indicate that
>
> p_Str = 
> std::string(p_Elem.GetByteValue()->GetBuffer(),p_Elem.GetByteValue()->GetLength());
>
> is not the correct way to get the value of a US element in a string !
>
> Is there a way to do want I want in a safe manner (not dependent to VR) ?
>
> Thanks for help
>
> Vincent
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120330/e46b0255/attachment.htm>


More information about the Insight-users mailing list