comparison Framework/Deprecated/Layers/RenderStyle.cpp @ 754:92c400a09f1b

Merge from default
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 22 May 2019 16:13:46 +0200
parents be3671662eec
children 2d8ab34c8c91
comparison
equal deleted inserted replaced
753:a386bbc955dc 754:92c400a09f1b
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 "RenderStyle.h"
23
24 #include "../../Volumes/ImageBuffer3D.h"
25 #include "../Toolbox/DicomFrameConverter.h"
26
27 #include <Core/OrthancException.h>
28
29 namespace Deprecated
30 {
31 RenderStyle::RenderStyle()
32 {
33 visible_ = true;
34 reverse_ = false;
35 windowing_ = OrthancStone::ImageWindowing_Custom;
36 alpha_ = 1;
37 applyLut_ = false;
38 lut_ = Orthanc::EmbeddedResources::COLORMAP_HOT;
39 drawGrid_ = false;
40 drawColor_[0] = 255;
41 drawColor_[1] = 255;
42 drawColor_[2] = 255;
43 customWindowCenter_ = 128;
44 customWindowWidth_ = 256;
45 interpolation_ = OrthancStone::ImageInterpolation_Nearest;
46 fontSize_ = 14;
47 }
48
49
50 void RenderStyle::ComputeWindowing(float& targetCenter,
51 float& targetWidth,
52 float defaultCenter,
53 float defaultWidth) const
54 {
55 if (windowing_ == OrthancStone::ImageWindowing_Custom)
56 {
57 targetCenter = customWindowCenter_;
58 targetWidth = customWindowWidth_;
59 }
60 else
61 {
62 return ::OrthancStone::ComputeWindowing
63 (targetCenter, targetWidth, windowing_, defaultCenter, defaultWidth);
64 }
65 }
66
67
68 void RenderStyle::SetColor(uint8_t red,
69 uint8_t green,
70 uint8_t blue)
71 {
72 drawColor_[0] = red;
73 drawColor_[1] = green;
74 drawColor_[2] = blue;
75 }
76
77
78 bool RenderStyle::FitRange(const OrthancStone::ImageBuffer3D& image,
79 const DicomFrameConverter& converter)
80 {
81 float minValue, maxValue;
82
83 windowing_ = OrthancStone::ImageWindowing_Custom;
84
85 if (image.GetRange(minValue, maxValue))
86 {
87 // casting the narrower type to wider before calling the + operator
88 // will prevent overflowing (this is why the cast to double is only
89 // done on the first operand)
90 customWindowCenter_ = static_cast<float>(
91 converter.Apply((static_cast<double>(minValue) + maxValue) / 2.0));
92
93 customWindowWidth_ = static_cast<float>(
94 converter.Apply(static_cast<double>(maxValue) - minValue));
95
96 if (customWindowWidth_ > 1)
97 {
98 return true;
99 }
100 }
101
102 customWindowCenter_ = 128.0;
103 customWindowWidth_ = 256.0;
104 return false;
105 }
106 }