Mercurial > hg > orthanc-stone
annotate Framework/Layers/DicomStructureSetSlicer.cpp @ 585:b9ce24c606ae
TextSceneLayer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Apr 2019 17:57:58 +0200 |
parents | b70e9be013e4 |
children | 42dadae61fa9 |
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 | |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
22 #include "DicomStructureSetSlicer.h" |
0 | 23 |
24 namespace OrthancStone | |
25 { | |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
26 class DicomStructureSetSlicer::Renderer : public ILayerRenderer |
0 | 27 { |
28 private: | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
29 class Structure |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
30 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
31 private: |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
32 bool visible_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
33 uint8_t red_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
34 uint8_t green_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
35 uint8_t blue_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
36 std::string name_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
37 std::vector< std::vector<DicomStructureSet::PolygonPoint> > polygons_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
38 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
39 public: |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
40 Structure(DicomStructureSet& structureSet, |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
41 const CoordinateSystem3D& plane, |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
42 size_t index) : |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
43 name_(structureSet.GetStructureName(index)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
44 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
45 structureSet.GetStructureColor(red_, green_, blue_, index); |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
46 visible_ = structureSet.ProjectStructure(polygons_, index, plane); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
47 } |
0 | 48 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
49 void Render(CairoContext& context) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
50 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
51 if (visible_) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
52 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
53 cairo_t* cr = context.GetObject(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
54 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
55 context.SetSourceColor(red_, green_, blue_); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
56 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
57 for (size_t i = 0; i < polygons_.size(); i++) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
58 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
59 cairo_move_to(cr, polygons_[i][0].first, polygons_[i][0].second); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
60 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
61 for (size_t j = 1; j < polygons_[i].size(); j++) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
62 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
63 cairo_line_to(cr, polygons_[i][j].first, polygons_[i][j].second); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
64 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
65 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
66 cairo_line_to(cr, polygons_[i][0].first, polygons_[i][0].second); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
67 cairo_stroke(cr); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
68 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
69 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
70 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
71 }; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
72 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
73 typedef std::list<Structure*> Structures; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
74 |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
75 CoordinateSystem3D plane_; |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
76 Structures structures_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
77 |
0 | 78 public: |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
79 Renderer(DicomStructureSet& structureSet, |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
80 const CoordinateSystem3D& plane) : |
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
81 plane_(plane) |
0 | 82 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
83 for (size_t k = 0; k < structureSet.GetStructureCount(); k++) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
84 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
85 structures_.push_back(new Structure(structureSet, plane, k)); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
86 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
87 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
88 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
89 virtual ~Renderer() |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
90 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
91 for (Structures::iterator it = structures_.begin(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
92 it != structures_.end(); ++it) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
93 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
94 delete *it; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
95 } |
0 | 96 } |
97 | |
98 virtual bool RenderLayer(CairoContext& context, | |
99 const ViewportGeometry& view) | |
100 { | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
101 cairo_set_line_width(context.GetObject(), 2.0f / view.GetZoom()); |
125 | 102 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
103 for (Structures::const_iterator it = structures_.begin(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
104 it != structures_.end(); ++it) |
0 | 105 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
106 assert(*it != NULL); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
107 (*it)->Render(context); |
0 | 108 } |
109 | |
110 return true; | |
111 } | |
112 | |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
113 virtual const CoordinateSystem3D& GetLayerPlane() |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
114 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
115 return plane_; |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
116 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
117 |
0 | 118 virtual void SetLayerStyle(const RenderStyle& style) |
119 { | |
120 } | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
121 |
0 | 122 virtual bool IsFullQuality() |
123 { | |
124 return true; | |
125 } | |
126 }; | |
127 | |
128 | |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
129 class DicomStructureSetSlicer::RendererFactory : public LayerReadyMessage::IRendererFactory |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
130 { |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
131 private: |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
132 DicomStructureSet& structureSet_; |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
133 const CoordinateSystem3D& plane_; |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
134 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
135 public: |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
136 RendererFactory(DicomStructureSet& structureSet, |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
137 const CoordinateSystem3D& plane) : |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
138 structureSet_(structureSet), |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
139 plane_(plane) |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
140 { |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
141 } |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
142 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
143 virtual ILayerRenderer* CreateRenderer() const |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
144 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
145 return new Renderer(structureSet_, plane_); |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
146 } |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
147 }; |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
148 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
149 |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
150 DicomStructureSetSlicer::DicomStructureSetSlicer(MessageBroker& broker, |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
151 StructureSetLoader& loader) : |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
152 IVolumeSlicer(broker), |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
153 IObserver(broker), |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
154 loader_(loader) |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
155 { |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
156 loader_.RegisterObserverCallback( |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
157 new Callable<DicomStructureSetSlicer, StructureSetLoader::ContentChangedMessage> |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
158 (*this, &DicomStructureSetSlicer::OnStructureSetLoaded)); |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
159 } |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
160 |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
161 |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
162 void DicomStructureSetSlicer::ScheduleLayerCreation(const CoordinateSystem3D& viewportPlane) |
0 | 163 { |
130 | 164 if (loader_.HasStructureSet()) |
0 | 165 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
166 RendererFactory factory(loader_.GetStructureSet(), viewportPlane); |
401
f1c769b3a5c2
start getting rid of VolumeSlicerBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
167 EmitMessage(IVolumeSlicer::LayerReadyMessage(*this, factory, viewportPlane)); |
0 | 168 } |
169 } | |
170 } |