Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Layers/FrameRenderer.cpp @ 1229:b9f2a111c5b9 broker
fix compilation of WebAssemblyOracle
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Dec 2019 14:41:37 +0100 |
parents | c35e98d22764 |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 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 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Core/OrthancException.h> |
0 | 28 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
29 namespace Deprecated |
0 | 30 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
31 FrameRenderer::FrameRenderer(const OrthancStone::CoordinateSystem3D& framePlane, |
0 | 32 double pixelSpacingX, |
33 double pixelSpacingY, | |
34 bool isFullQuality) : | |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
35 framePlane_(framePlane), |
0 | 36 pixelSpacingX_(pixelSpacingX), |
37 pixelSpacingY_(pixelSpacingY), | |
38 isFullQuality_(isFullQuality) | |
39 { | |
40 } | |
41 | |
42 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
43 bool FrameRenderer::RenderLayer(OrthancStone::CairoContext& context, |
0 | 44 const ViewportGeometry& view) |
94 | 45 { |
0 | 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 | |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
62 cairo_matrix_t transform; |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
63 cairo_matrix_init_identity(&transform); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
64 cairo_matrix_scale(&transform, pixelSpacingX_, pixelSpacingY_); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
65 cairo_matrix_translate(&transform, -0.5, -0.5); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
66 cairo_transform(cr, &transform); |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
67 |
0 | 68 //cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
69 cairo_set_source_surface(cr, display_->GetObject(), 0, 0); | |
70 | |
71 switch (style_.interpolation_) | |
72 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
73 case OrthancStone::ImageInterpolation_Nearest: |
0 | 74 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); |
75 break; | |
76 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
77 case OrthancStone::ImageInterpolation_Bilinear: |
0 | 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 | |
378 | 120 ILayerRenderer* FrameRenderer::CreateRenderer(const Orthanc::ImageAccessor& frame, |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
121 const Deprecated::Slice& framePlane, |
0 | 122 bool isFullQuality) |
77 | 123 { |
378 | 124 if (frame.GetFormat() == Orthanc::PixelFormat_RGB24) |
0 | 125 { |
378 | 126 return new ColorFrameRenderer(frame, |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
127 framePlane.GetGeometry(), |
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
128 framePlane.GetPixelSpacingX(), |
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
129 framePlane.GetPixelSpacingY(), isFullQuality); |
0 | 130 } |
131 else | |
132 { | |
378 | 133 return new GrayscaleFrameRenderer(frame, |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
134 framePlane.GetConverter(), |
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
135 framePlane.GetGeometry(), |
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
136 framePlane.GetPixelSpacingX(), |
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
137 framePlane.GetPixelSpacingY(), isFullQuality); |
0 | 138 } |
139 } | |
140 } |