comparison Framework/Deprecated/Layers/FrameRenderer.cpp @ 732:c35e98d22764

move Deprecated classes to a separate folder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 May 2019 14:27:35 +0200
parents Framework/Layers/FrameRenderer.cpp@4f2416d519b4
children 2d8ab34c8c91
comparison
equal deleted inserted replaced
729:529189f399ec 732:c35e98d22764
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "FrameRenderer.h"
23
24 #include "GrayscaleFrameRenderer.h"
25 #include "ColorFrameRenderer.h"
26
27 #include <Core/OrthancException.h>
28
29 namespace Deprecated
30 {
31 FrameRenderer::FrameRenderer(const OrthancStone::CoordinateSystem3D& framePlane,
32 double pixelSpacingX,
33 double pixelSpacingY,
34 bool isFullQuality) :
35 framePlane_(framePlane),
36 pixelSpacingX_(pixelSpacingX),
37 pixelSpacingY_(pixelSpacingY),
38 isFullQuality_(isFullQuality)
39 {
40 }
41
42
43 bool FrameRenderer::RenderLayer(OrthancStone::CairoContext& context,
44 const ViewportGeometry& view)
45 {
46 if (!style_.visible_)
47 {
48 return true;
49 }
50
51 if (display_.get() == NULL)
52 {
53 display_.reset(GenerateDisplay(style_));
54 }
55
56 assert(display_.get() != NULL);
57
58 cairo_t *cr = context.GetObject();
59
60 cairo_save(cr);
61
62 cairo_matrix_t transform;
63 cairo_matrix_init_identity(&transform);
64 cairo_matrix_scale(&transform, pixelSpacingX_, pixelSpacingY_);
65 cairo_matrix_translate(&transform, -0.5, -0.5);
66 cairo_transform(cr, &transform);
67
68 //cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
69 cairo_set_source_surface(cr, display_->GetObject(), 0, 0);
70
71 switch (style_.interpolation_)
72 {
73 case OrthancStone::ImageInterpolation_Nearest:
74 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
75 break;
76
77 case OrthancStone::ImageInterpolation_Bilinear:
78 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR);
79 break;
80
81 default:
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
83 }
84
85 cairo_paint_with_alpha(cr, style_.alpha_);
86
87 if (style_.drawGrid_)
88 {
89 context.SetSourceColor(style_.drawColor_);
90 cairo_set_line_width(cr, 0.5 / view.GetZoom());
91
92 for (unsigned int x = 0; x <= display_->GetWidth(); x++)
93 {
94 cairo_move_to(cr, x, 0);
95 cairo_line_to(cr, x, display_->GetHeight());
96 }
97
98 for (unsigned int y = 0; y <= display_->GetHeight(); y++)
99 {
100 cairo_move_to(cr, 0, y);
101 cairo_line_to(cr, display_->GetWidth(), y);
102 }
103
104 cairo_stroke(cr);
105 }
106
107 cairo_restore(cr);
108
109 return true;
110 }
111
112
113 void FrameRenderer::SetLayerStyle(const RenderStyle& style)
114 {
115 style_ = style;
116 display_.reset(NULL);
117 }
118
119
120 ILayerRenderer* FrameRenderer::CreateRenderer(const Orthanc::ImageAccessor& frame,
121 const Deprecated::Slice& framePlane,
122 bool isFullQuality)
123 {
124 if (frame.GetFormat() == Orthanc::PixelFormat_RGB24)
125 {
126 return new ColorFrameRenderer(frame,
127 framePlane.GetGeometry(),
128 framePlane.GetPixelSpacingX(),
129 framePlane.GetPixelSpacingY(), isFullQuality);
130 }
131 else
132 {
133 return new GrayscaleFrameRenderer(frame,
134 framePlane.GetConverter(),
135 framePlane.GetGeometry(),
136 framePlane.GetPixelSpacingX(),
137 framePlane.GetPixelSpacingY(), isFullQuality);
138 }
139 }
140 }