comparison Framework/Layers/DicomStructureSetSlicer.cpp @ 398:d257ea56b7be

renamed DicomStructureSetRendererFactory as DicomStructureSetSlicer, VolumeImageSource as VolumeImageMPRSlicer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 10 Nov 2018 09:41:59 +0100
parents Framework/Layers/DicomStructureSetRendererFactory.cpp@17d54c028805
children f1c769b3a5c2
comparison
equal deleted inserted replaced
397:1d9dd542adfe 398:d257ea56b7be
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-2018 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 OrthancStone
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<DicomStructureSet::PolygonPoint> > polygons_;
38
39 public:
40 Structure(DicomStructureSet& structureSet,
41 const 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(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 CoordinateSystem3D plane_;
76 Structures structures_;
77
78 public:
79 Renderer(DicomStructureSet& structureSet,
80 const 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(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 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 DicomStructureSet& structureSet_;
133 const CoordinateSystem3D& plane_;
134
135 public:
136 RendererFactory(DicomStructureSet& structureSet,
137 const 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 void DicomStructureSetSlicer::ScheduleLayerCreation(const CoordinateSystem3D& viewportPlane)
151 {
152 if (loader_.HasStructureSet())
153 {
154 RendererFactory factory(loader_.GetStructureSet(), viewportPlane);
155 NotifyLayerReady(factory, viewportPlane);
156 }
157 }
158 }