comparison OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp @ 1635:1a714e21ea7c

start refactoring DicomInstanceParameters
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Nov 2020 16:08:44 +0100
parents a4418a489e86
children d1e0b08b809d
comparison
equal deleted inserted replaced
1634:a4418a489e86 1635:1a714e21ea7c
43 std::string increment; 43 std::string increment;
44 44
45 if (dicom.LookupStringValue(increment, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER, false)) 45 if (dicom.LookupStringValue(increment, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER, false))
46 { 46 {
47 Orthanc::Toolbox::ToUpperCase(increment); 47 Orthanc::Toolbox::ToUpperCase(increment);
48 if (increment != "3004,000C") // This is the "Grid Frame Offset Vector" tag (DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) 48
49 // This is the "Grid Frame Offset Vector" tag (DICOM_TAG_GRID_FRAME_OFFSET_VECTOR)
50 if (increment != "3004,000C")
49 { 51 {
50 LOG(WARNING) << "Bad value for the FrameIncrementPointer tags in a multiframe image"; 52 LOG(WARNING) << "Bad value for the FrameIncrementPointer tags in a multiframe image";
53 frameOffsets_.resize(0);
51 return; 54 return;
52 } 55 }
53 } 56 }
54 57
55 if (!LinearAlgebra::ParseVector(frameOffsets_, dicom, Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) || 58 if (!LinearAlgebra::ParseVector(frameOffsets_, dicom, Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) ||
56 frameOffsets_.size() != imageInformation_.GetNumberOfFrames()) 59 frameOffsets_.size() != numberOfFrames_)
57 { 60 {
58 LOG(INFO) << "The frame offset information is missing in a multiframe image"; 61 LOG(INFO) << "The frame offset information is missing in a multiframe image";
59 frameOffsets_.clear(); 62
63 // DO NOT use ".clear()" here, as the "Vector" class doesn't behave like std::vector!
64 frameOffsets_.resize(0);
60 } 65 }
61 } 66 }
62 67
63 68
64 DicomInstanceParameters::Data::Data(const Orthanc::DicomMap& dicom) : 69 DicomInstanceParameters::Data::Data(const Orthanc::DicomMap& dicom) :
65 imageInformation_(dicom) 70 imageInformation_(dicom)
66 { 71 {
67 if (imageInformation_.GetNumberOfFrames() == 0)
68 {
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
70 }
71
72 if (!dicom.LookupStringValue(studyInstanceUid_, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) || 72 if (!dicom.LookupStringValue(studyInstanceUid_, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) ||
73 !dicom.LookupStringValue(seriesInstanceUid_, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) || 73 !dicom.LookupStringValue(seriesInstanceUid_, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) ||
74 !dicom.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) 74 !dicom.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
75 { 75 {
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
77 } 77 }
78 78
79 std::string s; 79 std::string s;
80 if (!dicom.LookupStringValue(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false)) 80 if (dicom.LookupStringValue(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false))
81 {
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
83 }
84 else
85 { 81 {
86 sopClassUid_ = StringToSopClassUid(s); 82 sopClassUid_ = StringToSopClassUid(s);
87 } 83 }
84 else
85 {
86 sopClassUid_ = SopClassUid_Other;
87 }
88
89 uint32_t n;
90 if (dicom.ParseUnsignedInteger32(n, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES))
91 {
92 numberOfFrames_ = n;
93 }
94 else
95 {
96 numberOfFrames_ = 1;
97 }
98
99 if (!dicom.HasTag(Orthanc::DICOM_TAG_COLUMNS) ||
100 !dicom.GetValue(Orthanc::DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(width_))
101 {
102 width_ = 0;
103 }
104
105 if (!dicom.HasTag(Orthanc::DICOM_TAG_ROWS) ||
106 !dicom.GetValue(Orthanc::DICOM_TAG_ROWS).ParseFirstUnsignedInteger(height_))
107 {
108 height_ = 0;
109 }
88 110
89 if (!dicom.ParseDouble(sliceThickness_, Orthanc::DICOM_TAG_SLICE_THICKNESS)) 111 if (!dicom.ParseDouble(sliceThickness_, Orthanc::DICOM_TAG_SLICE_THICKNESS))
90 { 112 {
91 sliceThickness_ = 100.0 * std::numeric_limits<double>::epsilon(); 113 sliceThickness_ = 100.0 * std::numeric_limits<double>::epsilon();
92 } 114 }
98 dicom.LookupStringValue(orientation, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false)) 120 dicom.LookupStringValue(orientation, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false))
99 { 121 {
100 geometry_ = CoordinateSystem3D(position, orientation); 122 geometry_ = CoordinateSystem3D(position, orientation);
101 } 123 }
102 124
125 // Must be AFTER setting "numberOfFrames_"
103 ExtractFrameOffsets(dicom); 126 ExtractFrameOffsets(dicom);
104 127
105 if (sopClassUid_ == SopClassUid_RTDose) 128 if (sopClassUid_ == SopClassUid_RTDose)
106 { 129 {
107 static const Orthanc::DicomTag DICOM_TAG_DOSE_UNITS(0x3004, 0x0002); 130 static const Orthanc::DicomTag DICOM_TAG_DOSE_UNITS(0x3004, 0x0002);
204 } 227 }
205 228
206 229
207 CoordinateSystem3D DicomInstanceParameters::Data::GetFrameGeometry(unsigned int frame) const 230 CoordinateSystem3D DicomInstanceParameters::Data::GetFrameGeometry(unsigned int frame) const
208 { 231 {
209 if (frame == 0) 232 if (frame >= numberOfFrames_)
233 {
234 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
235 }
236 else if (frameOffsets_.empty())
210 { 237 {
211 return geometry_; 238 return geometry_;
212 } 239 }
213 else if (frame >= imageInformation_.GetNumberOfFrames()) 240 else
214 { 241 {
215 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 242 assert(frameOffsets_.size() == numberOfFrames_);
216 }
217 else if (frameOffsets_.empty())
218 {
219 return geometry_;
220 }
221 else
222 {
223 assert(frameOffsets_.size() == imageInformation_.GetNumberOfFrames());
224 243
225 return CoordinateSystem3D( 244 return CoordinateSystem3D(
226 geometry_.GetOrigin() + frameOffsets_[frame] * geometry_.GetNormal(), 245 geometry_.GetOrigin() + frameOffsets_[frame] * geometry_.GetNormal(),
227 geometry_.GetAxisX(), 246 geometry_.GetAxisX(),
228 geometry_.GetAxisY()); 247 geometry_.GetAxisY());
231 250
232 251
233 bool DicomInstanceParameters::Data::IsPlaneWithinSlice(unsigned int frame, 252 bool DicomInstanceParameters::Data::IsPlaneWithinSlice(unsigned int frame,
234 const CoordinateSystem3D& plane) const 253 const CoordinateSystem3D& plane) const
235 { 254 {
236 if (frame >= imageInformation_.GetNumberOfFrames()) 255 if (frame >= numberOfFrames_)
237 { 256 {
238 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 257 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
239 } 258 }
240 259
241 CoordinateSystem3D tmp = geometry_; 260 CoordinateSystem3D tmp = geometry_;