comparison RenderingPlugin/Sources/Plugin.cpp @ 1894:438071a29f77

xor polygon filler for holes in rt-struct
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Jan 2022 14:25:59 +0100
parents cdf91ad891a5
children 14c8f339d480
comparison
equal deleted inserted replaced
1893:90b5e116a5f9 1894:438071a29f77
657 657
658 static void RenderRtStruct(OrthancPluginRestOutput* output, 658 static void RenderRtStruct(OrthancPluginRestOutput* output,
659 const char* url, 659 const char* url,
660 const OrthancPluginHttpRequest* request) 660 const OrthancPluginHttpRequest* request)
661 { 661 {
662 class XorFiller : public Orthanc::ImageProcessing::IPolygonFiller
663 {
664 private:
665 Orthanc::Image image_;
666
667 public:
668 XorFiller(unsigned int width,
669 unsigned int height) :
670 image_(Orthanc::PixelFormat_Grayscale8, width, height, false)
671 {
672 Orthanc::ImageProcessing::Set(image_, 0);
673 }
674
675 const Orthanc::ImageAccessor& GetImage() const
676 {
677 return image_;
678 }
679
680 virtual void Fill(int y,
681 int x1,
682 int x2) ORTHANC_OVERRIDE
683 {
684 assert(x1 > 0 &&
685 x1 <= x2 &&
686 x2 < static_cast<int>(image_.GetWidth()) &&
687 y > 0 &&
688 y < static_cast<int>(image_.GetHeight()));
689
690 uint8_t* p = reinterpret_cast<uint8_t*>(image_.GetRow(y)) + x1;
691
692 for (int i = x1; i <= x2; i++, p++)
693 {
694 *p = (*p ^ 0xff);
695 }
696 }
697 };
698
662 DataAugmentationParameters dataAugmentation; 699 DataAugmentationParameters dataAugmentation;
663 std::string structureName; 700 std::string structureName;
664 std::string instanceId; 701 std::string instanceId;
665 bool compress = false; 702 bool compress = false;
666 703
733 } 770 }
734 771
735 accessor.GetRtStruct().GetStructurePoints(polygons, structureIndex, parameters->GetSopInstanceUid()); 772 accessor.GetRtStruct().GetStructurePoints(polygons, structureIndex, parameters->GetSopInstanceUid());
736 } 773 }
737 774
738 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, parameters->GetWidth(), parameters->GetHeight(), false); 775 XorFiller filler(parameters->GetWidth(), parameters->GetHeight());
739 Orthanc::ImageProcessing::Set(tmp, 0);
740
741 OrthancStone::AffineTransform2D transform = dataAugmentation.ComputeTransform(parameters->GetWidth(), parameters->GetHeight()); 776 OrthancStone::AffineTransform2D transform = dataAugmentation.ComputeTransform(parameters->GetWidth(), parameters->GetHeight());
742 777
743 for (std::list< std::vector<OrthancStone::Vector> >::const_iterator 778 for (std::list< std::vector<OrthancStone::Vector> >::const_iterator
744 it = polygons.begin(); it != polygons.end(); ++it) 779 it = polygons.begin(); it != polygons.end(); ++it)
745 { 780 {
756 transform.Apply(x, y); 791 transform.Apply(x, y);
757 792
758 points.push_back(Orthanc::ImageProcessing::ImagePoint(x, y)); 793 points.push_back(Orthanc::ImageProcessing::ImagePoint(x, y));
759 } 794 }
760 795
761 Orthanc::ImageProcessing::FillPolygon(tmp, points, 255); 796 Orthanc::ImageProcessing::FillPolygon(filler, points);
762 } 797 }
763 798
764 AnswerNumpyImage(output, tmp, compress); 799 AnswerNumpyImage(output, filler.GetImage(), compress);
765 } 800 }
766 801
767 802
768 803
769 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, 804 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,