comparison Applications/Samples/SingleFrameEditorApplication.h @ 344:fdec8e6893cb am-2

ordering of bitmap layers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Oct 2018 14:48:18 +0200
parents 712acc87fa2e
children 55438b1ca317
comparison
equal deleted inserted replaced
343:712acc87fa2e 344:fdec8e6893cb
684 void Render(Orthanc::ImageAccessor& buffer, 684 void Render(Orthanc::ImageAccessor& buffer,
685 const ViewportGeometry& view) const 685 const ViewportGeometry& view) const
686 { 686 {
687 Orthanc::ImageProcessing::Set(buffer, 0); 687 Orthanc::ImageProcessing::Set(buffer, 0);
688 688
689 for (Bitmaps::const_iterator it = bitmaps_.begin(); 689 // Render layers in the background-to-foreground order
690 it != bitmaps_.end(); ++it) 690 for (size_t index = 0; index < countBitmaps_; index++)
691 { 691 {
692 assert(it->second != NULL); 692 Bitmaps::const_iterator it = bitmaps_.find(index);
693 it->second->Render(buffer, view); 693 if (it != bitmaps_.end())
694 {
695 assert(it->second != NULL);
696 it->second->Render(buffer, view);
697 }
694 } 698 }
695 } 699 }
696 700
697 701
698 bool LookupBitmap(size_t& index /* out */, 702 bool LookupBitmap(size_t& index /* out */,
699 double x, 703 double x,
700 double y) const 704 double y) const
701 { 705 {
702 for (Bitmaps::const_iterator it = bitmaps_.begin(); 706 // Render layers in the foreground-to-background order
703 it != bitmaps_.end(); ++it) 707 for (size_t i = countBitmaps_; i > 0; i--)
704 { 708 {
705 assert(it->second != NULL); 709 index = i - 1;
706 if (it->second->Contains(x, y)) 710 Bitmaps::const_iterator it = bitmaps_.find(index);
707 { 711 if (it != bitmaps_.end())
708 index = it->first; 712 {
709 return true; 713 assert(it->second != NULL);
714 if (it->second->Contains(x, y))
715 {
716 return true;
717 }
710 } 718 }
711 } 719 }
712 720
713 return false; 721 return false;
714 } 722 }
838 if (button == MouseButton_Left) 846 if (button == MouseButton_Left)
839 { 847 {
840 size_t bitmap; 848 size_t bitmap;
841 if (stack_.LookupBitmap(bitmap, x, y)) 849 if (stack_.LookupBitmap(bitmap, x, y))
842 { 850 {
843 printf("CLICK on bitmap %d\n", bitmap); 851 printf("CLICK on bitmap %ld\n", bitmap);
844 return new MoveBitmapTracker(stack_, bitmap, x, y, 852 return new MoveBitmapTracker(stack_, bitmap, x, y,
845 (modifiers & KeyboardModifiers_Shift)); 853 (modifiers & KeyboardModifiers_Shift));
846 } 854 }
847 else 855 else
848 { 856 {
895 BitmapStackInteractor myInteractor_; 903 BitmapStackInteractor myInteractor_;
896 904
897 protected: 905 protected:
898 virtual Extent2D GetSceneExtent() 906 virtual Extent2D GetSceneExtent()
899 { 907 {
900 printf("Get extent\n");
901 return stack_.GetSceneExtent(); 908 return stack_.GetSceneExtent();
902 } 909 }
903 910
904 virtual bool RenderScene(CairoContext& context, 911 virtual bool RenderScene(CairoContext& context,
905 const ViewportGeometry& view) 912 const ViewportGeometry& view)
936 NotifyContentChanged(); 943 NotifyContentChanged();
937 } 944 }
938 945
939 virtual bool Render(Orthanc::ImageAccessor& target) 946 virtual bool Render(Orthanc::ImageAccessor& target)
940 { 947 {
941 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(), target.GetHeight(), false); 948 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(),
949 target.GetHeight(), false);
942 stack_.Render(buffer, GetView()); 950 stack_.Render(buffer, GetView());
943 951
944 // As in GrayscaleFrameRenderer => TODO MERGE 952 // As in GrayscaleFrameRenderer => TODO MERGE?
945 953
946 float windowCenter, windowWidth; 954 float windowCenter, windowWidth;
947 if (!stack_.GetWindowing(windowCenter, windowWidth)) 955 if (!stack_.GetWindowing(windowCenter, windowWidth))
948 { 956 {
949 windowCenter = 128; 957 windowCenter = 128;
951 } 959 }
952 960
953 float x0 = windowCenter - windowWidth / 2.0f; 961 float x0 = windowCenter - windowWidth / 2.0f;
954 float x1 = windowCenter + windowWidth / 2.0f; 962 float x1 = windowCenter + windowWidth / 2.0f;
955 963
956 const unsigned int width = target.GetWidth(); 964 if (windowWidth >= 0.001f) // Avoid division by zero at (*)
957 const unsigned int height = target.GetHeight(); 965 {
966 const unsigned int width = target.GetWidth();
967 const unsigned int height = target.GetHeight();
958 968
959 for (unsigned int y = 0; y < height; y++) 969 for (unsigned int y = 0; y < height; y++)
960 { 970 {
961 const float* p = reinterpret_cast<const float*>(buffer.GetConstRow(y)); 971 const float* p = reinterpret_cast<const float*>(buffer.GetConstRow(y));
962 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 972 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
963 973
964 for (unsigned int x = 0; x < width; x++, p++, q += 4) 974 for (unsigned int x = 0; x < width; x++, p++, q += 4)
965 {
966 uint8_t v = 0;
967 if (windowWidth >= 0.001f) // Avoid division by zero
968 { 975 {
976 uint8_t v = 0;
969 if (*p >= x1) 977 if (*p >= x1)
970 { 978 {
971 v = 255; 979 v = 255;
972 } 980 }
973 else if (*p <= x0) 981 else if (*p <= x0)
975 v = 0; 983 v = 0;
976 } 984 }
977 else 985 else
978 { 986 {
979 // https://en.wikipedia.org/wiki/Linear_interpolation 987 // https://en.wikipedia.org/wiki/Linear_interpolation
980 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); 988 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); // (*)
981 } 989 }
982 990
983 // TODO MONOCHROME1 991 // TODO MONOCHROME1
984 /*if (invert_) 992 /*if (invert_)
985 { 993 {
986 v = 255 - v; 994 v = 255 - v;
987 }*/ 995 }*/
996
997 q[0] = v;
998 q[1] = v;
999 q[2] = v;
1000 q[3] = 255;
988 } 1001 }
989 1002 }
990 q[3] = 255; 1003 }
991 q[2] = v; 1004 else
992 q[1] = v; 1005 {
993 q[0] = v; 1006 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255);
994 }
995 } 1007 }
996 1008
997 return true; 1009 return true;
998 } 1010 }
999 1011