Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Layers/DicomStructureSetSlicer.cpp @ 1101:141593f1aa88
fix build on ubuntu
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 26 Oct 2019 11:35:41 +0200 |
parents | 287ec78f63b4 |
children | f72d1ab42932 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 | |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
21 #include "DicomStructureSetSlicer.h" |
0 | 22 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
23 namespace Deprecated |
0 | 24 { |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
25 class DicomStructureSetSlicer::Renderer : public ILayerRenderer |
0 | 26 { |
27 private: | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
28 class Structure |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
29 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
30 private: |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
31 bool visible_; |
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
32 uint8_t red_; |
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
33 uint8_t green_; |
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
34 uint8_t blue_; |
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
35 std::string name_; |
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
36 std::vector< std::pair<OrthancStone::Point2D, OrthancStone::Point2D> > segments_; |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
37 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
38 public: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
39 Structure(OrthancStone::DicomStructureSet& structureSet, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
40 const OrthancStone::CoordinateSystem3D& plane, |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
41 size_t index) : |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
42 name_(structureSet.GetStructureName(index)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
43 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
44 structureSet.GetStructureColor(red_, green_, blue_, index); |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
45 visible_ = structureSet.ProjectStructure(segments_, index, plane); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
46 } |
0 | 47 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
48 void Render(OrthancStone::CairoContext& context) |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
49 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
50 if (visible_) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
51 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
52 cairo_t* cr = context.GetObject(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
53 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
54 context.SetSourceColor(red_, green_, blue_); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
55 |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
56 for (size_t i = 0; i < segments_.size(); i++) |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
57 { |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
58 cairo_move_to(cr, segments_[i].first.x, segments_[i].first.y); |
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
984
diff
changeset
|
59 cairo_move_to(cr, segments_[i].second.x, segments_[i].second.y); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
60 cairo_stroke(cr); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
61 } |
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 } |
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 typedef std::list<Structure*> Structures; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
67 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
68 OrthancStone::CoordinateSystem3D plane_; |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
69 Structures structures_; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
70 |
0 | 71 public: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
72 Renderer(OrthancStone::DicomStructureSet& structureSet, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
73 const OrthancStone::CoordinateSystem3D& plane) : |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
74 plane_(plane) |
0 | 75 { |
794 | 76 for (size_t k = 0; k < structureSet.GetStructuresCount(); k++) |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
77 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
78 structures_.push_back(new Structure(structureSet, plane, k)); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
79 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
80 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
81 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
82 virtual ~Renderer() |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
83 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
84 for (Structures::iterator it = structures_.begin(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
85 it != structures_.end(); ++it) |
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 delete *it; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
88 } |
0 | 89 } |
90 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
91 virtual bool RenderLayer(OrthancStone::CairoContext& context, |
0 | 92 const ViewportGeometry& view) |
93 { | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
94 cairo_set_line_width(context.GetObject(), 2.0f / view.GetZoom()); |
125 | 95 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
96 for (Structures::const_iterator it = structures_.begin(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
97 it != structures_.end(); ++it) |
0 | 98 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
99 assert(*it != NULL); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
100 (*it)->Render(context); |
0 | 101 } |
102 | |
103 return true; | |
104 } | |
105 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
106 virtual const OrthancStone::CoordinateSystem3D& GetLayerPlane() |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
107 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
108 return plane_; |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
109 } |
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
110 |
0 | 111 virtual void SetLayerStyle(const RenderStyle& style) |
112 { | |
113 } | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
114 |
0 | 115 virtual bool IsFullQuality() |
116 { | |
117 return true; | |
118 } | |
119 }; | |
120 | |
121 | |
398
d257ea56b7be
renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
122 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
|
123 { |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
124 private: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
125 OrthancStone::DicomStructureSet& structureSet_; |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
126 const OrthancStone::CoordinateSystem3D& plane_; |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
127 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
128 public: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
129 RendererFactory(OrthancStone::DicomStructureSet& structureSet, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
130 const OrthancStone::CoordinateSystem3D& plane) : |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
131 structureSet_(structureSet), |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
132 plane_(plane) |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
133 { |
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 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
136 virtual ILayerRenderer* CreateRenderer() const |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
137 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
138 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
|
139 } |
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 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
143 DicomStructureSetSlicer::DicomStructureSetSlicer(OrthancStone::MessageBroker& broker, |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
144 StructureSetLoader& loader) : |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
145 IVolumeSlicer(broker), |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
146 IObserver(broker), |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
147 loader_(loader) |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
148 { |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
149 loader_.RegisterObserverCallback( |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
150 new OrthancStone::Callable<DicomStructureSetSlicer, StructureSetLoader::ContentChangedMessage> |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
151 (*this, &DicomStructureSetSlicer::OnStructureSetLoaded)); |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
152 } |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
153 |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
154 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
155 void DicomStructureSetSlicer::ScheduleLayerCreation(const OrthancStone::CoordinateSystem3D& viewportPlane) |
0 | 156 { |
130 | 157 if (loader_.HasStructureSet()) |
0 | 158 { |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
159 RendererFactory factory(loader_.GetStructureSet(), viewportPlane); |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
160 BroadcastMessage(IVolumeSlicer::LayerReadyMessage(*this, factory, viewportPlane)); |
0 | 161 } |
162 } | |
163 } |