comparison OrthancStone/Sources/Deprecated/Layers/DicomStructureSetSlicer.cpp @ 1512:244ad1e4e76a

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