Mercurial > hg > orthanc-stone
comparison Framework/Layers/DicomStructureSetRendererFactory.cpp @ 132:35c2b85836ce wasm
fix rtstruct projections
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 17 Nov 2017 18:01:31 +0100 |
parents | 1982d6c1d2ff |
children | e2fe9352f240 |
comparison
equal
deleted
inserted
replaced
131:3e6163a53b16 | 132:35c2b85836ce |
---|---|
24 namespace OrthancStone | 24 namespace OrthancStone |
25 { | 25 { |
26 class DicomStructureSetRendererFactory::Renderer : public ILayerRenderer | 26 class DicomStructureSetRendererFactory::Renderer : public ILayerRenderer |
27 { | 27 { |
28 private: | 28 private: |
29 DicomStructureSet& structureSet_; | 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& slice, | |
42 size_t index) : | |
43 name_(structureSet.GetStructureName(index)) | |
44 { | |
45 structureSet.GetStructureColor(red_, green_, blue_, index); | |
46 visible_ = structureSet.ProjectStructure(polygons_, index, slice); | |
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 | |
30 CoordinateSystem3D slice_; | 75 CoordinateSystem3D slice_; |
31 bool visible_; | 76 Structures structures_; |
32 | 77 |
33 public: | 78 public: |
34 Renderer(DicomStructureSet& structureSet, | 79 Renderer(DicomStructureSet& structureSet, |
35 const CoordinateSystem3D& slice) : | 80 const CoordinateSystem3D& slice) : |
36 structureSet_(structureSet), | 81 slice_(slice) |
37 slice_(slice), | |
38 visible_(true) | |
39 { | 82 { |
83 for (size_t k = 0; k < structureSet.GetStructureCount(); k++) | |
84 { | |
85 structures_.push_back(new Structure(structureSet, slice, 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 } | |
40 } | 96 } |
41 | 97 |
42 virtual bool RenderLayer(CairoContext& context, | 98 virtual bool RenderLayer(CairoContext& context, |
43 const ViewportGeometry& view) | 99 const ViewportGeometry& view) |
44 { | 100 { |
45 if (visible_) | 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) | |
46 { | 105 { |
47 cairo_set_line_width(context.GetObject(), 3.0f / view.GetZoom()); | 106 assert(*it != NULL); |
48 | 107 (*it)->Render(context); |
49 cairo_t* cr = context.GetObject(); | |
50 | |
51 for (size_t k = 0; k < structureSet_.GetStructureCount(); k++) | |
52 { | |
53 /*if (structureSet_.GetStructureName(k) != "CORD") | |
54 { | |
55 continue; | |
56 }*/ | |
57 | |
58 std::vector< std::vector<DicomStructureSet::PolygonPoint> > polygons; | |
59 | |
60 if (structureSet_.ProjectStructure(polygons, k, slice_)) | |
61 { | |
62 uint8_t red, green, blue; | |
63 structureSet_.GetStructureColor(red, green, blue, k); | |
64 context.SetSourceColor(red, green, blue); | |
65 | |
66 for (size_t i = 0; i < polygons.size(); i++) | |
67 { | |
68 cairo_move_to(cr, polygons[i][0].first, polygons[i][0].second); | |
69 | |
70 for (size_t j = 1; j < polygons[i].size(); j++) | |
71 { | |
72 cairo_line_to(cr, polygons[i][j].first, polygons[i][j].second); | |
73 } | |
74 | |
75 cairo_line_to(cr, polygons[i][0].first, polygons[i][0].second); | |
76 cairo_stroke(cr); | |
77 } | |
78 } | |
79 } | |
80 } | 108 } |
81 | 109 |
82 return true; | 110 return true; |
83 } | 111 } |
84 | 112 |
87 return slice_; | 115 return slice_; |
88 } | 116 } |
89 | 117 |
90 virtual void SetLayerStyle(const RenderStyle& style) | 118 virtual void SetLayerStyle(const RenderStyle& style) |
91 { | 119 { |
92 visible_ = style.visible_; | |
93 } | 120 } |
94 | 121 |
95 virtual bool IsFullQuality() | 122 virtual bool IsFullQuality() |
96 { | 123 { |
97 return true; | 124 return true; |
98 } | 125 } |
99 }; | 126 }; |