Mercurial > hg > orthanc-stone
comparison Applications/Samples/SingleFrameEditorApplication.h @ 348:dadee0f7f1b3 am-2
testing crop
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 23 Oct 2018 12:05:49 +0200 |
parents | cd65103c9172 |
children | c57e049ed079 |
comparison
equal
deleted
inserted
replaced
347:cd65103c9172 | 348:dadee0f7f1b3 |
---|---|
67 double panX_; | 67 double panX_; |
68 double panY_; | 68 double panY_; |
69 double angle_; | 69 double angle_; |
70 | 70 |
71 | 71 |
72 protected: | |
72 static Matrix CreateOffsetMatrix(double dx, | 73 static Matrix CreateOffsetMatrix(double dx, |
73 double dy) | 74 double dy) |
74 { | 75 { |
75 Matrix m = LinearAlgebra::IdentityMatrix(3); | 76 Matrix m = LinearAlgebra::IdentityMatrix(3); |
76 m(0, 2) = dx; | 77 m(0, 2) = dx; |
98 LinearAlgebra::FillMatrix(m, 3, 3, v); | 99 LinearAlgebra::FillMatrix(m, 3, 3, v); |
99 return m; | 100 return m; |
100 } | 101 } |
101 | 102 |
102 | 103 |
104 private: | |
103 static void ApplyTransform(double& x /* inout */, | 105 static void ApplyTransform(double& x /* inout */, |
104 double& y /* inout */, | 106 double& y /* inout */, |
105 const Matrix& transform) | 107 const Matrix& transform) |
106 { | 108 { |
107 Vector p; | 109 Vector p; |
168 void ResetCrop() | 170 void ResetCrop() |
169 { | 171 { |
170 hasCrop_ = false; | 172 hasCrop_ = false; |
171 } | 173 } |
172 | 174 |
173 void Crop(unsigned int x, | 175 void SetCrop(unsigned int x, |
174 unsigned int y, | 176 unsigned int y, |
175 unsigned int width, | 177 unsigned int width, |
176 unsigned int height) | 178 unsigned int height) |
177 { | 179 { |
180 if (!hasSize_) | |
181 { | |
182 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
183 } | |
184 | |
185 if (x + width > width_ || | |
186 y + height > height_) | |
187 { | |
188 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
189 } | |
190 | |
178 hasCrop_ = true; | 191 hasCrop_ = true; |
179 cropX_ = x; | 192 cropX_ = x; |
180 cropY_ = y; | 193 cropY_ = y; |
181 cropWidth_ = width; | 194 cropWidth_ = width; |
182 cropHeight_ = height; | 195 cropHeight_ = height; |
196 | |
197 UpdateTransform(); | |
183 } | 198 } |
184 | 199 |
185 void GetCrop(unsigned int& x, | 200 void GetCrop(unsigned int& x, |
186 unsigned int& y, | 201 unsigned int& y, |
187 unsigned int& width, | 202 unsigned int& width, |
237 | 252 |
238 hasSize_ = true; | 253 hasSize_ = true; |
239 width_ = width; | 254 width_ = width; |
240 height_ = height; | 255 height_ = height; |
241 | 256 |
257 | |
258 //SetCrop(0, 0, 2, 2); | |
259 | |
260 | |
242 UpdateTransform(); | 261 UpdateTransform(); |
243 } | 262 } |
244 | 263 |
245 | 264 |
246 void CheckSize(unsigned int width, | 265 void CheckSize(unsigned int width, |
260 Extent2D extent; | 279 Extent2D extent; |
261 | 280 |
262 unsigned int x, y, width, height; | 281 unsigned int x, y, width, height; |
263 GetCrop(x, y, width, height); | 282 GetCrop(x, y, width, height); |
264 | 283 |
265 double dx = static_cast<double>(x) - 0.5; | 284 double dx = static_cast<double>(x) /* - 0.5 */; |
266 double dy = static_cast<double>(y) - 0.5; | 285 double dy = static_cast<double>(y) /* - 0.5 */; |
267 double dwidth = static_cast<double>(width); | 286 double dwidth = static_cast<double>(width); |
268 double dheight = static_cast<double>(height); | 287 double dheight = static_cast<double>(height); |
269 | 288 |
270 AddToExtent(extent, dx, dy); | 289 AddToExtent(extent, dx, dy); |
271 AddToExtent(extent, dx + dwidth, dy); | 290 AddToExtent(extent, dx + dwidth, dy); |
357 | 376 |
358 | 377 |
359 void GetCenter(double& centerX, | 378 void GetCenter(double& centerX, |
360 double& centerY) const | 379 double& centerY) const |
361 { | 380 { |
362 centerX = static_cast<double>(width_) / 2.0; | 381 unsigned int x, y, width, height; |
363 centerY = static_cast<double>(height_) / 2.0; | 382 GetCrop(x, y, width, height); |
383 | |
384 centerX = static_cast<double>(width) / 2.0; | |
385 centerY = static_cast<double>(height) / 2.0; | |
364 ApplyTransform(centerX, centerY, transform_); | 386 ApplyTransform(centerX, centerY, transform_); |
365 } | 387 } |
366 | 388 |
367 | 389 |
368 void DrawBorders(CairoContext& context, | 390 void DrawBorders(CairoContext& context, |
532 pixelSpacing.size() == 2) | 554 pixelSpacing.size() == 2) |
533 { | 555 { |
534 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]); | 556 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]); |
535 } | 557 } |
536 | 558 |
537 SetPan(-0.5 * GetPixelSpacingX(), -0.5 * GetPixelSpacingY()); | 559 //SetPan(-0.5 * GetPixelSpacingX(), -0.5 * GetPixelSpacingY()); |
538 | 560 |
539 static unsigned int c = 0; | 561 static unsigned int c = 0; |
540 if (c == 0) | 562 if (c == 0) |
541 { | 563 { |
542 SetPan(400, 0); | 564 SetPan(400, 0); |
663 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) | 685 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) |
664 { | 686 { |
665 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 687 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
666 } | 688 } |
667 | 689 |
668 Matrix m = LinearAlgebra::Product(view.GetMatrix(), GetTransform()); | 690 unsigned int cropX, cropY, cropWidth, cropHeight; |
691 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
692 | |
693 Matrix m = LinearAlgebra::Product(view.GetMatrix(), | |
694 GetTransform(), | |
695 CreateOffsetMatrix(cropX, cropY)); | |
696 | |
697 Orthanc::ImageAccessor cropped; | |
698 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
669 | 699 |
670 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); | 700 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); |
671 ApplyProjectiveTransform(tmp, *alpha_, m, interpolation, true /* clear */); | 701 ApplyProjectiveTransform(tmp, cropped, m, interpolation, true /* clear */); |
672 | 702 |
673 // Blit | 703 // Blit |
674 const unsigned int width = buffer.GetWidth(); | 704 const unsigned int width = buffer.GetWidth(); |
675 const unsigned int height = buffer.GetHeight(); | 705 const unsigned int height = buffer.GetHeight(); |
676 | 706 |
782 } | 812 } |
783 | 813 |
784 | 814 |
785 size_t LoadText(const Orthanc::Font& font, | 815 size_t LoadText(const Orthanc::Font& font, |
786 const std::string& utf8, | 816 const std::string& utf8, |
787 double x, | 817 float foreground) |
788 double y) | |
789 { | 818 { |
790 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(*this)); | 819 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(*this)); |
791 alpha->LoadText(font, utf8); | 820 alpha->LoadText(font, utf8); |
821 alpha->SetForegroundValue(foreground); | |
822 | |
823 size_t bitmap = countBitmaps_++; | |
824 | |
825 bitmaps_[bitmap] = alpha.release(); | |
826 | |
827 return bitmap; | |
828 } | |
829 | |
830 | |
831 size_t LoadTestBlock(unsigned int width, | |
832 unsigned int height, | |
833 float foreground) | |
834 { | |
835 std::auto_ptr<AlphaBitmap> alpha(new AlphaBitmap(*this)); | |
836 | |
837 std::auto_ptr<Orthanc::Image> block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false)); | |
838 | |
839 for (unsigned int padding = 0; | |
840 (width > 2 * padding) && (height > 2 * padding); | |
841 padding++) | |
842 { | |
843 uint8_t color; | |
844 if (255 > 10 * padding) | |
845 { | |
846 color = 255 - 10 * padding; | |
847 } | |
848 else | |
849 { | |
850 color = 0; | |
851 } | |
852 | |
853 Orthanc::ImageAccessor region; | |
854 block->GetRegion(region, padding, padding, width - 2 * padding, height - 2 * padding); | |
855 Orthanc::ImageProcessing::Set(region, color); | |
856 } | |
857 | |
858 alpha->SetAlpha(block.release()); | |
859 alpha->SetForegroundValue(foreground); | |
792 | 860 |
793 size_t bitmap = countBitmaps_++; | 861 size_t bitmap = countBitmaps_++; |
794 | 862 |
795 bitmaps_[bitmap] = alpha.release(); | 863 bitmaps_[bitmap] = alpha.release(); |
796 | 864 |
992 double clickAngle_; | 1060 double clickAngle_; |
993 bool roundAngles_; | 1061 bool roundAngles_; |
994 | 1062 |
995 bool ComputeAngle(double& angle /* out */, | 1063 bool ComputeAngle(double& angle /* out */, |
996 double sceneX, | 1064 double sceneX, |
997 double sceneY) | 1065 double sceneY) const |
998 { | 1066 { |
999 Vector u; | 1067 Vector u; |
1000 LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_); | 1068 LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_); |
1001 | 1069 |
1002 double nu = boost::numeric::ublas::norm_2(u); | 1070 double nu = boost::numeric::ublas::norm_2(u); |
1310 { | 1378 { |
1311 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(), | 1379 Orthanc::Image buffer(Orthanc::PixelFormat_Float32, target.GetWidth(), |
1312 target.GetHeight(), false); | 1380 target.GetHeight(), false); |
1313 | 1381 |
1314 // TODO => rendering quality | 1382 // TODO => rendering quality |
1315 //stack_.Render(buffer, GetView(), ImageInterpolation_Nearest); | 1383 stack_.Render(buffer, GetView(), ImageInterpolation_Nearest); |
1316 stack_.Render(buffer, GetView(), ImageInterpolation_Bilinear); | 1384 //stack_.Render(buffer, GetView(), ImageInterpolation_Bilinear); |
1317 | 1385 |
1318 // As in GrayscaleFrameRenderer => TODO MERGE? | 1386 // As in GrayscaleFrameRenderer => TODO MERGE? |
1319 | 1387 |
1320 float windowCenter, windowWidth; | 1388 float windowCenter, windowWidth; |
1321 if (!stack_.GetWindowing(windowCenter, windowWidth)) | 1389 if (!stack_.GetWindowing(windowCenter, windowWidth)) |
1554 | 1622 |
1555 Orthanc::FontRegistry fonts; | 1623 Orthanc::FontRegistry fonts; |
1556 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); | 1624 fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); |
1557 | 1625 |
1558 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_)); | 1626 stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_)); |
1559 stack_->LoadFrame(instance, frame, false); | 1627 //stack_->LoadFrame(instance, frame, false); |
1560 stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", frame, false); | 1628 //stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", frame, false); |
1561 stack_->LoadText(fonts.GetFont(0), "Hello\nworld\nBonjour, Alain", 0, -50); | 1629 //stack_->LoadText(fonts.GetFont(0), "Hello\nworld\nBonjour, Alain", 256); |
1630 stack_->LoadTestBlock(20, 10, 256); | |
1562 | 1631 |
1563 mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget"); | 1632 mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget"); |
1564 mainWidget_->SetTransmitMouseOver(true); | 1633 mainWidget_->SetTransmitMouseOver(true); |
1565 | 1634 |
1566 mainWidgetInteractor_.reset(new Interactor(*this)); | 1635 mainWidgetInteractor_.reset(new Interactor(*this)); |