Mercurial > hg > orthanc-stone
annotate Framework/Layers/FrameRenderer.cpp @ 371:fe4befe03935
integration legacy->default
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 Nov 2018 10:04:56 +0100 |
parents | 5412adf19980 |
children | 814fa32e2fcc |
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 | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 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 |
29 namespace OrthancStone | |
30 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
97
diff
changeset
|
31 FrameRenderer::FrameRenderer(const CoordinateSystem3D& frameSlice, |
0 | 32 double pixelSpacingX, |
33 double pixelSpacingY, | |
34 bool isFullQuality) : | |
35 frameSlice_(frameSlice), | |
36 pixelSpacingX_(pixelSpacingX), | |
37 pixelSpacingY_(pixelSpacingY), | |
38 isFullQuality_(isFullQuality) | |
39 { | |
40 } | |
41 | |
42 | |
43 bool FrameRenderer::RenderLayer(CairoContext& context, | |
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 { | |
73 case ImageInterpolation_Nearest: | |
74 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); | |
75 break; | |
76 | |
147
f48c5d422d45
removed meaningless ImageInterpolation_Linear value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
77 case 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 | |
120 ILayerRenderer* FrameRenderer::CreateRenderer(Orthanc::ImageAccessor* frame, | |
85 | 121 const Slice& frameSlice, |
0 | 122 bool isFullQuality) |
77 | 123 { |
0 | 124 std::auto_ptr<Orthanc::ImageAccessor> protect(frame); |
125 | |
126 if (frame->GetFormat() == Orthanc::PixelFormat_RGB24) | |
127 { | |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
128 return new ColorFrameRenderer(protect.release(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
129 frameSlice.GetGeometry(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
130 frameSlice.GetPixelSpacingX(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
131 frameSlice.GetPixelSpacingY(), isFullQuality); |
0 | 132 } |
133 else | |
134 { | |
97
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
135 return new GrayscaleFrameRenderer(protect.release(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
136 frameSlice.GetConverter(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
137 frameSlice.GetGeometry(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
138 frameSlice.GetPixelSpacingX(), |
d18dcc963930
separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
139 frameSlice.GetPixelSpacingY(), isFullQuality); |
0 | 140 } |
141 } | |
142 } |