Mercurial > hg > orthanc-wsi
comparison Framework/Inputs/DicomPyramidInstance.cpp @ 215:02cb86d07966
Allow images without "Per frame functional groups sequence" tag (0x5200,0x9230)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 Jan 2021 17:12:24 +0100 |
parents | 1e864138f0da |
children | c35a3a0627b9 |
comparison
equal
deleted
inserted
replaced
214:1e864138f0da | 215:02cb86d07966 |
---|---|
171 { | 171 { |
172 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 172 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
173 } | 173 } |
174 | 174 |
175 size_t countFrames; | 175 size_t countFrames; |
176 if (!reader.GetDataset().GetSequenceSize(countFrames, OrthancStone::DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE))) | 176 if (reader.GetDataset().GetSequenceSize(countFrames, OrthancStone::DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE))) |
177 { | 177 { |
178 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 178 if (countFrames != tmp) |
179 } | 179 { |
180 | 180 LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; |
181 if (countFrames != tmp) | |
182 { | |
183 LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; | |
184 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
185 } | |
186 | |
187 frames_.resize(countFrames); | |
188 | |
189 for (size_t i = 0; i < countFrames; i++) | |
190 { | |
191 DicomPath pathX(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, | |
192 DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, | |
193 DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); | |
194 | |
195 DicomPath pathY(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, | |
196 DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, | |
197 DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); | |
198 | |
199 int xx, yy; | |
200 if (!reader.GetIntegerValue(xx, pathX) || | |
201 !reader.GetIntegerValue(yy, pathY)) | |
202 { | |
203 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); | |
204 } | |
205 | |
206 // "-1", because coordinates are shifted by 1 in DICOM | |
207 xx -= 1; | |
208 yy -= 1; | |
209 | |
210 unsigned int x = static_cast<unsigned int>(xx); | |
211 unsigned int y = static_cast<unsigned int>(yy); | |
212 | |
213 if (xx < 0 || | |
214 yy < 0 || | |
215 x % tileWidth_ != 0 || | |
216 y % tileHeight_ != 0 || | |
217 x >= totalWidth_ || | |
218 y >= totalHeight_) | |
219 { | |
220 LOG(ERROR) << "Frame " << i << " with unexpected tile location (" | |
221 << x << "," << y << ") in instance: " << instanceId; | |
222 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 181 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
223 } | 182 } |
224 | 183 |
225 frames_[i].first = x / tileWidth_; | 184 frames_.resize(countFrames); |
226 frames_[i].second = y / tileHeight_; | 185 |
186 for (size_t i = 0; i < countFrames; i++) | |
187 { | |
188 DicomPath pathX(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, | |
189 DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, | |
190 DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); | |
191 | |
192 DicomPath pathY(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, | |
193 DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, | |
194 DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); | |
195 | |
196 int xx, yy; | |
197 if (!reader.GetIntegerValue(xx, pathX) || | |
198 !reader.GetIntegerValue(yy, pathY)) | |
199 { | |
200 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); | |
201 } | |
202 | |
203 // "-1", because coordinates are shifted by 1 in DICOM | |
204 xx -= 1; | |
205 yy -= 1; | |
206 | |
207 unsigned int x = static_cast<unsigned int>(xx); | |
208 unsigned int y = static_cast<unsigned int>(yy); | |
209 | |
210 if (xx < 0 || | |
211 yy < 0 || | |
212 x % tileWidth_ != 0 || | |
213 y % tileHeight_ != 0 || | |
214 x >= totalWidth_ || | |
215 y >= totalHeight_) | |
216 { | |
217 LOG(ERROR) << "Frame " << i << " with unexpected tile location (" | |
218 << x << "," << y << ") in instance: " << instanceId; | |
219 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
220 } | |
221 | |
222 frames_[i].first = x / tileWidth_; | |
223 frames_[i].second = y / tileHeight_; | |
224 } | |
225 } | |
226 else | |
227 { | |
228 // No "Per frame functional groups sequence" tag. Assume regular grid. | |
229 frames_.resize(tmp); | |
230 | |
231 // Compute "ceiling(totalWidth_ / tileWidth_) | |
232 unsigned int w = totalWidth_ / tileWidth_; | |
233 if (totalWidth_ % tileWidth_ != 0) | |
234 { | |
235 w += 1; | |
236 } | |
237 | |
238 unsigned int h = totalHeight_ / tileHeight_; | |
239 if (totalHeight_ % tileHeight_ != 0) | |
240 { | |
241 h += 1; | |
242 } | |
243 | |
244 if (w * h != tmp) | |
245 { | |
246 LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; | |
247 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
248 } | |
249 | |
250 for (size_t i = 0; i < frames_.size(); i++) | |
251 { | |
252 frames_[i].first = i % w; | |
253 frames_[i].second = i / w; | |
254 } | |
227 } | 255 } |
228 } | 256 } |
229 | 257 |
230 | 258 |
231 DicomPyramidInstance::DicomPyramidInstance(OrthancStone::IOrthancConnection& orthanc, | 259 DicomPyramidInstance::DicomPyramidInstance(OrthancStone::IOrthancConnection& orthanc, |