Mercurial > hg > orthanc-stone
comparison Resources/Graveyard/ReferenceLineFactory.cpp @ 392:d87fe075d31b
to graveyard
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Nov 2018 17:59:35 +0100 |
parents | Framework/Layers/ReferenceLineFactory.cpp@021480604c92 |
children | 885e1ebd315c |
comparison
equal
deleted
inserted
replaced
391:021480604c92 | 392:d87fe075d31b |
---|---|
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 "ReferenceLineFactory.h" | |
23 | |
24 #include "LineLayerRenderer.h" | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 ReferenceLineFactory::ReferenceLineFactory(SliceViewerWidget& owner, | |
29 SliceViewerWidget& sibling) : | |
30 owner_(owner), | |
31 sibling_(sibling), | |
32 hasLayerIndex_(false) | |
33 { | |
34 style_.SetColor(0, 255, 0); | |
35 slice_ = sibling.GetSlice(); | |
36 sibling_.Register(*this); | |
37 } | |
38 | |
39 | |
40 void ReferenceLineFactory::NotifySliceChange(const SliceViewerWidget& source, | |
41 const SliceGeometry& slice) | |
42 { | |
43 if (&source == &sibling_) | |
44 { | |
45 SetSlice(slice); | |
46 } | |
47 } | |
48 | |
49 | |
50 void ReferenceLineFactory::SetLayerIndex(size_t layerIndex) | |
51 { | |
52 hasLayerIndex_ = true; | |
53 layerIndex_ = layerIndex; | |
54 } | |
55 | |
56 | |
57 void ReferenceLineFactory::SetStyle(const RenderStyle& style) | |
58 { | |
59 style_ = style; | |
60 } | |
61 | |
62 | |
63 RenderStyle ReferenceLineFactory::GetRenderStyle() | |
64 { | |
65 return style_; | |
66 } | |
67 | |
68 | |
69 void ReferenceLineFactory::SetSlice(const SliceGeometry& slice) | |
70 { | |
71 slice_ = slice; | |
72 | |
73 if (hasLayerIndex_) | |
74 { | |
75 owner_.InvalidateLayer(layerIndex_); | |
76 } | |
77 } | |
78 | |
79 | |
80 ILayerRenderer* ReferenceLineFactory::CreateLayerRenderer(const SliceGeometry& viewportSlice) | |
81 { | |
82 Vector p, d; | |
83 | |
84 // Compute the line of intersection between the two slices | |
85 if (!GeometryToolbox::IntersectTwoPlanes(p, d, | |
86 slice_.GetOrigin(), slice_.GetNormal(), | |
87 viewportSlice.GetOrigin(), viewportSlice.GetNormal())) | |
88 { | |
89 // The two slice are parallel, don't try and display the intersection | |
90 return NULL; | |
91 } | |
92 | |
93 double x1, y1, x2, y2; | |
94 viewportSlice.ProjectPoint(x1, y1, p); | |
95 viewportSlice.ProjectPoint(x2, y2, p + 1000.0 * d); | |
96 | |
97 double sx1, sy1, sx2, sy2; | |
98 owner_.GetView().GetSceneExtent(sx1, sy1, sx2, sy2); | |
99 | |
100 if (GeometryToolbox::ClipLineToRectangle(x1, y1, x2, y2, | |
101 x1, y1, x2, y2, | |
102 sx1, sy1, sx2, sy2)) | |
103 { | |
104 std::auto_ptr<ILayerRenderer> layer(new LineLayerRenderer(x1, y1, x2, y2)); | |
105 layer->SetLayerStyle(style_); | |
106 return layer.release(); | |
107 } | |
108 else | |
109 { | |
110 // Parallel slices | |
111 return NULL; | |
112 } | |
113 } | |
114 | |
115 | |
116 ISliceableVolume& ReferenceLineFactory::GetSourceVolume() const | |
117 { | |
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
119 } | |
120 | |
121 | |
122 void ReferenceLineFactory::Configure(SliceViewerWidget& a, | |
123 SliceViewerWidget& b) | |
124 { | |
125 { | |
126 size_t layerIndex; | |
127 ILayerRendererFactory& factory = a.AddLayer(layerIndex, new ReferenceLineFactory(a, b)); | |
128 dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex); | |
129 } | |
130 | |
131 { | |
132 size_t layerIndex; | |
133 ILayerRendererFactory& factory = b.AddLayer(layerIndex, new ReferenceLineFactory(b, a)); | |
134 dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex); | |
135 } | |
136 } | |
137 } |