Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp @ 4076:eab8010c05fc framework
avoid relying on boost::bad_lexical_cast in DicomImageInformation
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Jun 2020 18:45:16 +0200 |
parents | d25f4c0fa160 |
children | bf7b9edf6b81 |
comparison
equal
deleted
inserted
replaced
4075:ea95eecead6f | 4076:eab8010c05fc |
---|---|
50 | 50 |
51 namespace Orthanc | 51 namespace Orthanc |
52 { | 52 { |
53 DicomImageInformation::DicomImageInformation(const DicomMap& values) | 53 DicomImageInformation::DicomImageInformation(const DicomMap& values) |
54 { | 54 { |
55 unsigned int pixelRepresentation; | 55 uint32_t pixelRepresentation = 0; |
56 unsigned int planarConfiguration = 0; | 56 uint32_t planarConfiguration = 0; |
57 | 57 |
58 try | 58 try |
59 { | 59 { |
60 std::string p = values.GetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION).GetContent(); | 60 std::string p = values.GetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION).GetContent(); |
61 Toolbox::ToUpperCase(p); | 61 Toolbox::ToUpperCase(p); |
118 } | 118 } |
119 | 119 |
120 values.GetValue(DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(width_); // in some US images, we've seen tag values of "800\0"; that's why we parse the 'first' value | 120 values.GetValue(DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(width_); // in some US images, we've seen tag values of "800\0"; that's why we parse the 'first' value |
121 values.GetValue(DICOM_TAG_ROWS).ParseFirstUnsignedInteger(height_); | 121 values.GetValue(DICOM_TAG_ROWS).ParseFirstUnsignedInteger(height_); |
122 | 122 |
123 bitsAllocated_ = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_BITS_ALLOCATED).GetContent()); | 123 if (!values.ParseUnsignedInteger32(bitsAllocated_, DICOM_TAG_BITS_ALLOCATED)) |
124 | 124 { |
125 try | 125 throw OrthancException(ErrorCode_BadFileFormat); |
126 { | 126 } |
127 samplesPerPixel_ = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_SAMPLES_PER_PIXEL).GetContent()); | 127 |
128 } | 128 if (!values.ParseUnsignedInteger32(samplesPerPixel_, DICOM_TAG_SAMPLES_PER_PIXEL)) |
129 catch (OrthancException&) | |
130 { | 129 { |
131 samplesPerPixel_ = 1; // Assume 1 color channel | 130 samplesPerPixel_ = 1; // Assume 1 color channel |
132 } | 131 } |
133 | 132 |
134 try | 133 if (!values.ParseUnsignedInteger32(bitsStored_, DICOM_TAG_BITS_STORED)) |
135 { | |
136 bitsStored_ = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_BITS_STORED).GetContent()); | |
137 } | |
138 catch (OrthancException&) | |
139 { | 134 { |
140 bitsStored_ = bitsAllocated_; | 135 bitsStored_ = bitsAllocated_; |
141 } | 136 } |
142 | 137 |
143 try | 138 if (!values.ParseUnsignedInteger32(highBit_, DICOM_TAG_HIGH_BIT)) |
144 { | |
145 highBit_ = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_HIGH_BIT).GetContent()); | |
146 } | |
147 catch (OrthancException&) | |
148 { | 139 { |
149 highBit_ = bitsStored_ - 1; | 140 highBit_ = bitsStored_ - 1; |
150 } | 141 } |
151 | 142 |
152 try | 143 if (!values.ParseUnsignedInteger32(pixelRepresentation, DICOM_TAG_PIXEL_REPRESENTATION)) |
153 { | |
154 pixelRepresentation = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_PIXEL_REPRESENTATION).GetContent()); | |
155 } | |
156 catch (OrthancException&) | |
157 { | 144 { |
158 pixelRepresentation = 0; // Assume unsigned pixels | 145 pixelRepresentation = 0; // Assume unsigned pixels |
159 } | 146 } |
160 | 147 |
161 if (samplesPerPixel_ > 1) | 148 if (samplesPerPixel_ > 1) |
162 { | 149 { |
163 // The "Planar Configuration" is only set when "Samples per Pixels" is greater than 1 | 150 // The "Planar Configuration" is only set when "Samples per Pixels" is greater than 1 |
164 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.3.1.3 | 151 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.3.1.3 |
165 try | 152 |
166 { | 153 if (!values.ParseUnsignedInteger32(planarConfiguration, DICOM_TAG_PLANAR_CONFIGURATION)) |
167 planarConfiguration = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_PLANAR_CONFIGURATION).GetContent()); | |
168 } | |
169 catch (OrthancException&) | |
170 { | 154 { |
171 planarConfiguration = 0; // Assume interleaved color channels | 155 planarConfiguration = 0; // Assume interleaved color channels |
172 } | 156 } |
173 } | 157 } |
174 } | 158 } |
179 catch (OrthancException&) | 163 catch (OrthancException&) |
180 { | 164 { |
181 throw OrthancException(ErrorCode_NotImplemented); | 165 throw OrthancException(ErrorCode_NotImplemented); |
182 } | 166 } |
183 | 167 |
168 | |
184 if (values.HasTag(DICOM_TAG_NUMBER_OF_FRAMES)) | 169 if (values.HasTag(DICOM_TAG_NUMBER_OF_FRAMES)) |
185 { | 170 { |
186 try | 171 if (!values.ParseUnsignedInteger32(numberOfFrames_, DICOM_TAG_NUMBER_OF_FRAMES)) |
187 { | |
188 numberOfFrames_ = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).GetContent()); | |
189 } | |
190 catch (boost::bad_lexical_cast&) | |
191 { | 172 { |
192 throw OrthancException(ErrorCode_NotImplemented); | 173 throw OrthancException(ErrorCode_NotImplemented); |
193 } | 174 } |
194 } | 175 } |
195 else | 176 else |