Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp @ 1677:51bab5188a13
start multiple preset windowings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 23 Nov 2020 19:24:18 +0100 |
parents | 4e14735e98f8 |
children | 5b8b88e5bfd6 |
comparison
equal
deleted
inserted
replaced
1676:5e76d5e8167a | 1677:51bab5188a13 |
---|---|
178 { | 178 { |
179 LOG(ERROR) << "Tag DoseGridScaling (0x3004, 0x000e) is missing in " << sopInstanceUid_ << " doseGridScaling_ will be set to 1.0"; | 179 LOG(ERROR) << "Tag DoseGridScaling (0x3004, 0x000e) is missing in " << sopInstanceUid_ << " doseGridScaling_ will be set to 1.0"; |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 Vector c, w; | 183 bool ok = false; |
184 if (LinearAlgebra::ParseVector(c, dicom, Orthanc::DICOM_TAG_WINDOW_CENTER) && | 184 |
185 LinearAlgebra::ParseVector(w, dicom, Orthanc::DICOM_TAG_WINDOW_WIDTH) && | 185 if (LinearAlgebra::ParseVector(presetWindowingCenters_, dicom, Orthanc::DICOM_TAG_WINDOW_CENTER) && |
186 c.size() > 0 && | 186 LinearAlgebra::ParseVector(presetWindowingWidths_, dicom, Orthanc::DICOM_TAG_WINDOW_WIDTH)) |
187 w.size() > 0) | 187 { |
188 { | 188 if (presetWindowingCenters_.size() == presetWindowingWidths_.size()) |
189 hasDefaultWindowing_ = true; | 189 { |
190 defaultWindowingCenter_ = static_cast<float>(c[0]); | 190 ok = true; |
191 defaultWindowingWidth_ = static_cast<float>(w[0]); | 191 } |
192 } | 192 else |
193 else | 193 { |
194 { | 194 LOG(ERROR) << "Mismatch in the number of preset windowing widths/centers, ignoring this"; |
195 hasDefaultWindowing_ = false; | 195 ok = false; |
196 defaultWindowingCenter_ = 0; | 196 } |
197 defaultWindowingWidth_ = 0; | 197 } |
198 } | 198 |
199 if (!ok) | |
200 { | |
201 // Don't use "Vector::clear()", as it has not the same meaning as "std::vector::clear()" | |
202 presetWindowingCenters_.resize(0); | |
203 presetWindowingWidths_.resize(0); | |
204 } | |
199 | 205 |
200 // This computes the "IndexInSeries" metadata from Orthanc (check | 206 // This computes the "IndexInSeries" metadata from Orthanc (check |
201 // out "Orthanc::ServerIndex::Store()") | 207 // out "Orthanc::ServerIndex::Store()") |
202 hasIndexInSeries_ = ( | 208 hasIndexInSeries_ = ( |
203 dicom.ParseUnsignedInteger32(indexInSeries_, Orthanc::DICOM_TAG_INSTANCE_NUMBER) || | 209 dicom.ParseUnsignedInteger32(indexInSeries_, Orthanc::DICOM_TAG_INSTANCE_NUMBER) || |
389 return Orthanc::PixelFormat_Grayscale16; // Rough guess | 395 return Orthanc::PixelFormat_Grayscale16; // Rough guess |
390 } | 396 } |
391 } | 397 } |
392 | 398 |
393 | 399 |
394 float DicomInstanceParameters::GetDefaultWindowingCenter() const | 400 size_t DicomInstanceParameters::GetPresetWindowingsCount() const |
395 { | 401 { |
396 if (data_.hasDefaultWindowing_) | 402 assert(data_.presetWindowingCenters_.size() == data_.presetWindowingWidths_.size()); |
397 { | 403 return data_.presetWindowingCenters_.size(); |
398 return data_.defaultWindowingCenter_; | 404 } |
399 } | 405 |
400 else | 406 |
401 { | 407 float DicomInstanceParameters::GetPresetWindowingCenter(size_t i) const |
402 LOG(ERROR) << "DicomInstanceParameters::GetDefaultWindowingCenter(): no default windowing"; | 408 { |
403 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 409 if (i < GetPresetWindowingsCount()) |
404 } | 410 { |
405 } | 411 return static_cast<float>(data_.presetWindowingCenters_[i]); |
406 | 412 } |
407 | 413 else |
408 float DicomInstanceParameters::GetDefaultWindowingWidth() const | 414 { |
409 { | 415 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
410 if (data_.hasDefaultWindowing_) | 416 } |
411 { | 417 } |
412 return data_.defaultWindowingWidth_; | 418 |
413 } | 419 |
414 else | 420 float DicomInstanceParameters::GetPresetWindowingWidth(size_t i) const |
415 { | 421 { |
416 LOG(ERROR) << "DicomInstanceParameters::GetDefaultWindowingWidth(): no default windowing"; | 422 if (i < GetPresetWindowingsCount()) |
417 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 423 { |
418 } | 424 return static_cast<float>(data_.presetWindowingWidths_[i]); |
419 } | 425 } |
420 | 426 else |
421 | 427 { |
428 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
429 } | |
430 } | |
431 | |
432 | |
422 Orthanc::ImageAccessor* DicomInstanceParameters::ConvertToFloat(const Orthanc::ImageAccessor& pixelData) const | 433 Orthanc::ImageAccessor* DicomInstanceParameters::ConvertToFloat(const Orthanc::ImageAccessor& pixelData) const |
423 { | 434 { |
424 std::unique_ptr<Orthanc::Image> converted(new Orthanc::Image(Orthanc::PixelFormat_Float32, | 435 std::unique_ptr<Orthanc::Image> converted(new Orthanc::Image(Orthanc::PixelFormat_Float32, |
425 pixelData.GetWidth(), | 436 pixelData.GetWidth(), |
426 pixelData.GetHeight(), | 437 pixelData.GetHeight(), |
481 { | 492 { |
482 std::unique_ptr<Orthanc::ImageAccessor> converted(ConvertToFloat(pixelData)); | 493 std::unique_ptr<Orthanc::ImageAccessor> converted(ConvertToFloat(pixelData)); |
483 texture.reset(new FloatTextureSceneLayer(*converted)); | 494 texture.reset(new FloatTextureSceneLayer(*converted)); |
484 } | 495 } |
485 | 496 |
486 if (data_.hasDefaultWindowing_) | 497 if (GetPresetWindowingsCount() > 0) |
487 { | 498 { |
488 texture->SetCustomWindowing(data_.defaultWindowingCenter_, | 499 texture->SetCustomWindowing(GetPresetWindowingCenter(0), GetPresetWindowingWidth(0)); |
489 data_.defaultWindowingWidth_); | |
490 } | 500 } |
491 | 501 |
492 switch (GetImageInformation().GetPhotometricInterpretation()) | 502 switch (GetImageInformation().GetPhotometricInterpretation()) |
493 { | 503 { |
494 case Orthanc::PhotometricInterpretation_Monochrome1: | 504 case Orthanc::PhotometricInterpretation_Monochrome1: |