Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Layers/DicomStructureSetSlicer.cpp @ 732:c35e98d22764
move Deprecated classes to a separate folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 14:27:35 +0200 |
parents | Framework/Layers/DicomStructureSetSlicer.cpp@4f2416d519b4 |
children | 04f518ebd132 |
comparison
equal
deleted
inserted
replaced
729:529189f399ec | 732:c35e98d22764 |
---|---|
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 "DicomStructureSetSlicer.h" | |
23 | |
24 namespace Deprecated | |
25 { | |
26 class DicomStructureSetSlicer::Renderer : public ILayerRenderer | |
27 { | |
28 private: | |
29 class Structure | |
30 { | |
31 private: | |
32 bool visible_; | |
33 uint8_t red_; | |
34 uint8_t green_; | |
35 uint8_t blue_; | |
36 std::string name_; | |
37 std::vector< std::vector<OrthancStone::DicomStructureSet::PolygonPoint> > polygons_; | |
38 | |
39 public: | |
40 Structure(OrthancStone::DicomStructureSet& structureSet, | |
41 const OrthancStone::CoordinateSystem3D& plane, | |
42 size_t index) : | |
43 name_(structureSet.GetStructureName(index)) | |
44 { | |
45 structureSet.GetStructureColor(red_, green_, blue_, index); | |
46 visible_ = structureSet.ProjectStructure(polygons_, index, plane); | |
47 } | |
48 | |
49 void Render(OrthancStone::CairoContext& context) | |
50 { | |
51 if (visible_) | |
52 { | |
53 cairo_t* cr = context.GetObject(); | |
54 | |
55 context.SetSourceColor(red_, green_, blue_); | |
56 | |
57 for (size_t i = 0; i < polygons_.size(); i++) | |
58 { | |
59 cairo_move_to(cr, polygons_[i][0].first, polygons_[i][0].second); | |
60 | |
61 for (size_t j = 1; j < polygons_[i].size(); j++) | |
62 { | |
63 cairo_line_to(cr, polygons_[i][j].first, polygons_[i][j].second); | |
64 } | |
65 | |
66 cairo_line_to(cr, polygons_[i][0].first, polygons_[i][0].second); | |
67 cairo_stroke(cr); | |
68 } | |
69 } | |
70 } | |
71 }; | |
72 | |
73 typedef std::list<Structure*> Structures; | |
74 | |
75 OrthancStone::CoordinateSystem3D plane_; | |
76 Structures structures_; | |
77 | |
78 public: | |
79 Renderer(OrthancStone::DicomStructureSet& structureSet, | |
80 const OrthancStone::CoordinateSystem3D& plane) : | |
81 plane_(plane) | |
82 { | |
83 for (size_t k = 0; k < structureSet.GetStructureCount(); k++) | |
84 { | |
85 structures_.push_back(new Structure(structureSet, plane, k)); | |
86 } | |
87 } | |
88 | |
89 virtual ~Renderer() | |
90 { | |
91 for (Structures::iterator it = structures_.begin(); | |
92 it != structures_.end(); ++it) | |
93 { | |
94 delete *it; | |
95 } | |
96 } | |
97 | |
98 virtual bool RenderLayer(OrthancStone::CairoContext& context, | |
99 const ViewportGeometry& view) | |
100 { | |
101 cairo_set_line_width(context.GetObject(), 2.0f / view.GetZoom()); | |
102 | |
103 for (Structures::const_iterator it = structures_.begin(); | |
104 it != structures_.end(); ++it) | |
105 { | |
106 assert(*it != NULL); | |
107 (*it)->Render(context); | |
108 } | |
109 | |
110 return true; | |
111 } | |
112 | |
113 virtual const OrthancStone::CoordinateSystem3D& GetLayerPlane() | |
114 { | |
115 return plane_; | |
116 } | |
117 | |
118 virtual void SetLayerStyle(const RenderStyle& style) | |
119 { | |
120 } | |
121 | |
122 virtual bool IsFullQuality() | |
123 { | |
124 return true; | |
125 } | |
126 }; | |
127 | |
128 | |
129 class DicomStructureSetSlicer::RendererFactory : public LayerReadyMessage::IRendererFactory | |
130 { | |
131 private: | |
132 OrthancStone::DicomStructureSet& structureSet_; | |
133 const OrthancStone::CoordinateSystem3D& plane_; | |
134 | |
135 public: | |
136 RendererFactory(OrthancStone::DicomStructureSet& structureSet, | |
137 const OrthancStone::CoordinateSystem3D& plane) : | |
138 structureSet_(structureSet), | |
139 plane_(plane) | |
140 { | |
141 } | |
142 | |
143 virtual ILayerRenderer* CreateRenderer() const | |
144 { | |
145 return new Renderer(structureSet_, plane_); | |
146 } | |
147 }; | |
148 | |
149 | |
150 DicomStructureSetSlicer::DicomStructureSetSlicer(OrthancStone::MessageBroker& broker, | |
151 StructureSetLoader& loader) : | |
152 IVolumeSlicer(broker), | |
153 IObserver(broker), | |
154 loader_(loader) | |
155 { | |
156 loader_.RegisterObserverCallback( | |
157 new OrthancStone::Callable<DicomStructureSetSlicer, StructureSetLoader::ContentChangedMessage> | |
158 (*this, &DicomStructureSetSlicer::OnStructureSetLoaded)); | |
159 } | |
160 | |
161 | |
162 void DicomStructureSetSlicer::ScheduleLayerCreation(const OrthancStone::CoordinateSystem3D& viewportPlane) | |
163 { | |
164 if (loader_.HasStructureSet()) | |
165 { | |
166 RendererFactory factory(loader_.GetStructureSet(), viewportPlane); | |
167 BroadcastMessage(IVolumeSlicer::LayerReadyMessage(*this, factory, viewportPlane)); | |
168 } | |
169 } | |
170 } |