From: Niels D. - a. u. 2. <nie...@xs...> - 2011-07-25 13:52:27
|
cldl at gmx... wrote: > i have a question about converting attribute values to an string. > > I know two ways to get the string from the attribute value. > > 1) std::cout << dataElement.GetValue() << std::endl; > > 2) using StringFilter class > > If i use the first way i have to convert some Binary VR by hand. > This works so far, but if the attribute contains umlauts (...) > the string gets "Loaded:XX". > > If i use the StringFilter class to get the string everything looks > fine. > But if i'm not go wrong it is not possible to use the StringFilter > in SQ's datasets. ?! I encountered a similar problem in the past, but I managed to get the raw bytes out of the GDCM Value, at least if it is a ByteValue. As follows: const gdcm::Value& value = dataElement.GetValue(); const gdcm::ByteValue* const byteValue = dynamic_cast<const gdcm::ByteValue*>(&value); if ( byteValue == NULL ) { std::ostringstream outputStringStream; value.Print(outputStringStream); std::string str = outputStringStream.str(); } else { // It's a Byte Value, so get the bytes! const std::vector<char>& bytes = *byteValue; std::string str(bytes.begin(), bytes.end()); } The resulting std::string may not always be a proper ASCII string, depending on the Value Representation (VR). However, any umlaut or trema is likely to be preserved. Is that of any help to you? > (sorry Mathieu for the two invalid posts, i had > problems with the mail client...) LOL I was just about to send Mathieu a spam report about you :-D Kind regards, Niels -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center |