Mercurial > hg > orthanc-stone
annotate Resources/Graveyard/ReferenceLineFactory.cpp @ 1023:701f36c28193
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 03 Oct 2019 14:38:06 +0200 |
parents | b70e9be013e4 |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
22 #include "ReferenceLineFactory.h" |
0 | 23 |
24 #include "LineLayerRenderer.h" | |
25 | |
26 namespace OrthancStone | |
27 { | |
391 | 28 ReferenceLineFactory::ReferenceLineFactory(SliceViewerWidget& owner, |
29 SliceViewerWidget& sibling) : | |
0 | 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 | |
399
885e1ebd315c
rename SliceChange as SliceContentChange
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
392
diff
changeset
|
40 void ReferenceLineFactory::NotifySliceContentChange(const SliceViewerWidget& source, |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
41 const SliceGeometry& slice) |
0 | 42 { |
43 if (&source == &sibling_) | |
44 { | |
45 SetSlice(slice); | |
46 } | |
47 } | |
48 | |
49 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
50 void ReferenceLineFactory::SetLayerIndex(size_t layerIndex) |
0 | 51 { |
52 hasLayerIndex_ = true; | |
53 layerIndex_ = layerIndex; | |
54 } | |
55 | |
56 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
57 void ReferenceLineFactory::SetStyle(const RenderStyle& style) |
0 | 58 { |
59 style_ = style; | |
60 } | |
61 | |
62 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
63 RenderStyle ReferenceLineFactory::GetRenderStyle() |
0 | 64 { |
65 return style_; | |
66 } | |
67 | |
68 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
69 void ReferenceLineFactory::SetSlice(const SliceGeometry& slice) |
0 | 70 { |
71 slice_ = slice; | |
72 | |
73 if (hasLayerIndex_) | |
74 { | |
75 owner_.InvalidateLayer(layerIndex_); | |
76 } | |
77 } | |
78 | |
79 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
80 ILayerRenderer* ReferenceLineFactory::CreateLayerRenderer(const SliceGeometry& viewportSlice) |
0 | 81 { |
82 Vector p, d; | |
83 | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
84 // Compute the line of intersection between the two slices |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
85 if (!GeometryToolbox::IntersectTwoPlanes(p, d, |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
86 slice_.GetOrigin(), slice_.GetNormal(), |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
87 viewportSlice.GetOrigin(), viewportSlice.GetNormal())) |
0 | 88 { |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
89 // The two slice are parallel, don't try and display the intersection |
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
90 return NULL; |
0 | 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)); | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
105 layer->SetLayerStyle(style_); |
0 | 106 return layer.release(); |
107 } | |
108 else | |
109 { | |
110 // Parallel slices | |
111 return NULL; | |
112 } | |
113 } | |
114 | |
115 | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
116 ISliceableVolume& ReferenceLineFactory::GetSourceVolume() const |
0 | 117 { |
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
119 } | |
120 | |
121 | |
391 | 122 void ReferenceLineFactory::Configure(SliceViewerWidget& a, |
123 SliceViewerWidget& b) | |
0 | 124 { |
125 { | |
126 size_t layerIndex; | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
127 ILayerRendererFactory& factory = a.AddLayer(layerIndex, new ReferenceLineFactory(a, b)); |
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
128 dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex); |
0 | 129 } |
130 | |
131 { | |
132 size_t layerIndex; | |
390
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
133 ILayerRendererFactory& factory = b.AddLayer(layerIndex, new ReferenceLineFactory(b, a)); |
0cb925325470
renamed SiblingSliceLocation as ReferenceLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
196
diff
changeset
|
134 dynamic_cast<ReferenceLineFactory&>(factory).SetLayerIndex(layerIndex); |
0 | 135 } |
136 } | |
137 } |