Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyScene.cpp @ 1200:54cbffabdc45 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 Nov 2019 11:03:41 +0100 |
parents | bdc6837d5917 922d2e61aa5d |
children | b519c1c878f1 |
comparison
equal
deleted
inserted
replaced
1198:4cc997207d8a | 1200:54cbffabdc45 |
---|---|
132 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 132 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
133 } | 133 } |
134 | 134 |
135 std::auto_ptr<RadiographyLayer> raii(layer); | 135 std::auto_ptr<RadiographyLayer> raii(layer); |
136 | 136 |
137 // LOG(INFO) << "Registering layer: " << countLayers_; | 137 size_t index = nextLayerIndex_++; |
138 | |
139 size_t index = countLayers_++; | |
140 raii->SetIndex(index); | 138 raii->SetIndex(index); |
141 layers_[index] = raii.release(); | 139 layers_[index] = raii.release(); |
142 | 140 |
143 BroadcastMessage(GeometryChangedMessage(*this, *layer)); | 141 BroadcastMessage(GeometryChangedMessage(*this, *layer)); |
144 BroadcastMessage(ContentChangedMessage(*this, *layer)); | 142 BroadcastMessage(ContentChangedMessage(*this, *layer)); |
160 void RadiographyScene::OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message) | 158 void RadiographyScene::OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message) |
161 { | 159 { |
162 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, message.GetOrigin())); | 160 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, message.GetOrigin())); |
163 } | 161 } |
164 | 162 |
163 | |
165 RadiographyScene::RadiographyScene() : | 164 RadiographyScene::RadiographyScene() : |
166 countLayers_(0), | 165 nextLayerIndex_(0), |
167 hasWindowing_(false), | 166 hasWindowing_(false), |
168 windowingCenter_(0), // Dummy initialization | 167 windowingCenter_(0), // Dummy initialization |
169 windowingWidth_(0) // Dummy initialization | 168 windowingWidth_(0) // Dummy initialization |
170 { | 169 { |
171 } | 170 } |
217 { | 216 { |
218 assert(found->second != NULL); | 217 assert(found->second != NULL); |
219 delete found->second; | 218 delete found->second; |
220 | 219 |
221 layers_.erase(found); | 220 layers_.erase(found); |
222 countLayers_--; | |
223 | 221 |
224 LOG(INFO) << "Removing layer, there are now : " << countLayers_ << " layers"; | 222 LOG(INFO) << "Removing layer, there are now : " << layers_.size() << " layers"; |
225 | 223 |
226 BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex)); | 224 BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex)); |
227 } | 225 } |
228 } | 226 } |
229 | 227 |
279 BroadcastMessage(RadiographyScene::WindowingChangedMessage(*this)); | 277 BroadcastMessage(RadiographyScene::WindowingChangedMessage(*this)); |
280 } | 278 } |
281 | 279 |
282 | 280 |
283 RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, | 281 RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8, |
284 size_t fontSize, | 282 unsigned int fontSize, |
285 uint8_t foreground, | 283 uint8_t foreground, |
286 RadiographyLayer::Geometry* geometry) | 284 RadiographyLayer::Geometry* geometry) |
287 { | 285 { |
288 std::auto_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(*this)); | 286 std::auto_ptr<RadiographyTextLayer> alpha(new RadiographyTextLayer(*this)); |
289 alpha->LoadText(utf8, fontSize, foreground); | 287 alpha->LoadText(utf8, fontSize, foreground); |
290 if (geometry != NULL) | 288 if (geometry != NULL) |
291 { | 289 { |
292 alpha->SetGeometry(*geometry); | 290 alpha->SetGeometry(*geometry); |
293 } | 291 } |
294 | 292 |
295 return RegisterLayer(alpha.release()); | 293 RadiographyLayer& registeredLayer = RegisterLayer(alpha.release()); |
294 | |
295 BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, registeredLayer)); | |
296 return registeredLayer; | |
296 } | 297 } |
297 | 298 |
298 | 299 |
299 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width, | 300 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width, |
300 unsigned int height, | 301 unsigned int height, |
505 } | 506 } |
506 | 507 |
507 | 508 |
508 void RadiographyScene::Render(Orthanc::ImageAccessor& buffer, | 509 void RadiographyScene::Render(Orthanc::ImageAccessor& buffer, |
509 const AffineTransform2D& viewTransform, | 510 const AffineTransform2D& viewTransform, |
510 ImageInterpolation interpolation) const | 511 ImageInterpolation interpolation, |
512 bool applyWindowing) const | |
511 { | 513 { |
512 // Render layers in the background-to-foreground order | 514 // Render layers in the background-to-foreground order |
513 for (size_t index = 0; index < countLayers_; index++) | 515 for (size_t index = 0; index < nextLayerIndex_; index++) |
514 { | 516 { |
515 Layers::const_iterator it = layers_.find(index); | 517 Layers::const_iterator it = layers_.find(index); |
516 if (it != layers_.end()) | 518 if (it != layers_.end()) |
517 { | 519 { |
518 assert(it->second != NULL); | 520 assert(it->second != NULL); |
519 it->second->Render(buffer, viewTransform, interpolation); | 521 it->second->Render(buffer, viewTransform, interpolation, windowingCenter_, windowingWidth_, applyWindowing); |
520 } | 522 } |
521 } | 523 } |
522 } | 524 } |
523 | 525 |
524 | 526 |
525 bool RadiographyScene::LookupLayer(size_t& index /* out */, | 527 bool RadiographyScene::LookupLayer(size_t& index /* out */, |
526 double x, | 528 double x, |
527 double y) const | 529 double y) const |
528 { | 530 { |
529 // Render layers in the foreground-to-background order | 531 // Render layers in the foreground-to-background order |
530 for (size_t i = countLayers_; i > 0; i--) | 532 for (size_t i = nextLayerIndex_; i > 0; i--) |
531 { | 533 { |
532 index = i - 1; | 534 index = i - 1; |
533 Layers::const_iterator it = layers_.find(index); | 535 Layers::const_iterator it = layers_.find(index); |
534 if (it != layers_.end()) | 536 if (it != layers_.end()) |
535 { | 537 { |
595 | 597 |
596 Orthanc::Image* RadiographyScene::ExportToImage(double pixelSpacingX, | 598 Orthanc::Image* RadiographyScene::ExportToImage(double pixelSpacingX, |
597 double pixelSpacingY, | 599 double pixelSpacingY, |
598 ImageInterpolation interpolation, | 600 ImageInterpolation interpolation, |
599 bool invert, | 601 bool invert, |
600 int64_t maxValue /* for inversion */) | 602 int64_t maxValue /* for inversion */, |
603 bool applyWindowing) | |
601 { | 604 { |
602 if (pixelSpacingX <= 0 || | 605 if (pixelSpacingX <= 0 || |
603 pixelSpacingY <= 0) | 606 pixelSpacingY <= 0) |
604 { | 607 { |
605 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 608 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
624 AffineTransform2D::CreateOffset(-extent.GetX1(), -extent.GetY1())); | 627 AffineTransform2D::CreateOffset(-extent.GetX1(), -extent.GetY1())); |
625 | 628 |
626 // wipe background before rendering | 629 // wipe background before rendering |
627 Orthanc::ImageProcessing::Set(layers, 0); | 630 Orthanc::ImageProcessing::Set(layers, 0); |
628 | 631 |
629 Render(layers, view, interpolation); | 632 Render(layers, view, interpolation, applyWindowing); |
630 | 633 |
631 std::auto_ptr<Orthanc::Image> rendered(new Orthanc::Image(Orthanc::PixelFormat_Grayscale16, | 634 std::auto_ptr<Orthanc::Image> rendered(new Orthanc::Image(Orthanc::PixelFormat_Grayscale16, |
632 layers.GetWidth(), layers.GetHeight(), false)); | 635 layers.GetWidth(), layers.GetHeight(), false)); |
633 | 636 |
634 Orthanc::ImageProcessing::Convert(*rendered, layers); | 637 Orthanc::ImageProcessing::Convert(*rendered, layers); |
647 bool invert, | 650 bool invert, |
648 ImageInterpolation interpolation) | 651 ImageInterpolation interpolation) |
649 { | 652 { |
650 LOG(INFO) << "Exporting RadiographyScene to DICOM"; | 653 LOG(INFO) << "Exporting RadiographyScene to DICOM"; |
651 | 654 |
652 std::auto_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags | 655 std::auto_ptr<Orthanc::Image> rendered(ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, false)); // note: we don't invert the image in the pixels data because we'll set the PhotometricDisplayMode correctly in the DICOM tags |
653 | 656 |
654 createDicomRequestContent["Tags"] = dicomTags; | 657 createDicomRequestContent["Tags"] = dicomTags; |
655 | 658 |
656 RadiographyPhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); | 659 RadiographyPhotometricDisplayMode photometricMode = GetPreferredPhotomotricDisplayMode(); |
657 if ((invert && photometricMode != RadiographyPhotometricDisplayMode_Monochrome2) || | 660 if ((invert && photometricMode != RadiographyPhotometricDisplayMode_Monochrome2) || |