comparison Framework/Deprecated/Radiography/RadiographyWidget.h @ 1398:c5403d52078c

moved Radiography into Deprecated
author Alain Mazy <alain@mazy.be>
date Wed, 29 Apr 2020 20:43:09 +0200
parents Framework/Radiography/RadiographyWidget.h@379c00958553
children
comparison
equal deleted inserted replaced
1397:1c2d065ba372 1398:c5403d52078c
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-2020 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 #pragma once
23
24 #include "../Deprecated/Widgets/WorldSceneWidget.h"
25 #include "../Messages/ObserverBase.h"
26 #include "RadiographyScene.h"
27
28
29 namespace OrthancStone
30 {
31 class RadiographyMaskLayer;
32
33 class RadiographyWidget :
34 public Deprecated::WorldSceneWidget,
35 public ObserverBase<RadiographyWidget>,
36 public IObservable
37 {
38 public:
39 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, SelectionChangedMessage, RadiographyWidget);
40
41 private:
42 boost::shared_ptr<RadiographyScene> scene_;
43 std::unique_ptr<Orthanc::ImageAccessor> floatBuffer_;
44 std::unique_ptr<CairoSurface> cairoBuffer_;
45 bool invert_;
46 ImageInterpolation interpolation_;
47 bool hasSelection_;
48 size_t selectedLayer_;
49
50 bool RenderInternal(unsigned int width,
51 unsigned int height,
52 ImageInterpolation interpolation);
53
54 protected:
55 virtual Extent2D GetSceneExtent()
56 {
57 return scene_->GetSceneExtent(false);
58 }
59
60 virtual bool RenderScene(CairoContext& context,
61 const Deprecated::ViewportGeometry& view);
62
63 virtual void RenderBackground(Orthanc::ImageAccessor& image, float minValue, float maxValue);
64
65 bool IsInvertedInternal() const;
66
67 public:
68 RadiographyWidget(boost::shared_ptr<RadiographyScene> scene, // TODO: check how we can avoid boost::shared_ptr here since we don't want them in the public API (app is keeping a boost::shared_ptr to this right now)
69 const std::string& name);
70
71 RadiographyScene& GetScene() const
72 {
73 return *scene_;
74 }
75
76 void SetScene(boost::shared_ptr<RadiographyScene> scene);
77
78 void Select(size_t layer);
79
80 void Unselect();
81
82 template<typename LayerType> bool SelectLayerByType(size_t index = 0);
83
84 bool LookupSelectedLayer(size_t& layer) const;
85
86 void OnGeometryChanged(const RadiographyScene::GeometryChangedMessage& message);
87
88 void OnContentChanged(const RadiographyScene::ContentChangedMessage& message);
89
90 void OnLayerRemoved(const RadiographyScene::LayerRemovedMessage& message);
91
92 void SetInvert(bool invert);
93
94 void SwitchInvert();
95
96 bool IsInverted() const
97 {
98 return invert_;
99 }
100
101 void SetInterpolation(ImageInterpolation interpolation);
102
103 ImageInterpolation GetInterpolation() const
104 {
105 return interpolation_;
106 }
107 };
108
109 template<typename LayerType> bool RadiographyWidget::SelectLayerByType(size_t index)
110 {
111 std::vector<size_t> layerIndexes;
112 size_t count = 0;
113 scene_->GetLayersIndexes(layerIndexes);
114
115 for (size_t i = 0; i < layerIndexes.size(); ++i)
116 {
117 const LayerType* typedLayer = dynamic_cast<const LayerType*>(&(scene_->GetLayer(layerIndexes[i])));
118 if (typedLayer != NULL)
119 {
120 if (count == index)
121 {
122 Select(layerIndexes[i]);
123 return true;
124 }
125 count++;
126 }
127 }
128
129 return false;
130 }
131 }