Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Scene2D.cpp @ 1925:a7a77488ddb1
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Mar 2022 14:21:22 +0100 |
parents | 7053b8a0aaec |
children | e8b9a2ba1df1 |
rev | line source |
---|---|
582 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
582 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
582 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
582 | 21 **/ |
22 | |
23 | |
24 #include "Scene2D.h" | |
25 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1380
diff
changeset
|
26 #include <OrthancException.h> |
582 | 27 |
28 | |
29 namespace OrthancStone | |
30 { | |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
31 class Scene2D::Item |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
32 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
33 private: |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
34 std::unique_ptr<ISceneLayer> layer_; |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
35 uint64_t identifier_; |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
36 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
37 public: |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
38 Item(ISceneLayer* layer, |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
39 uint64_t identifier) : |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
40 layer_(layer), |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
41 identifier_(identifier) |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
42 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
43 if (layer == NULL) |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
44 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
45 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
46 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
47 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
48 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
49 ISceneLayer& GetLayer() const |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
50 { |
606
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
51 if (layer_.get() == NULL) |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
52 { |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
53 LOG(ERROR) << "Scene2D::Item::GetLayer(): (layer_.get() == NULL)"; |
606
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
55 } |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
56 else |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
57 { |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
58 return *layer_; |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
59 } |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
60 } |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
61 |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
62 ISceneLayer* ReleaseLayer() |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
63 { |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
64 if (layer_.get() == NULL) |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
65 { |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
66 LOG(ERROR) << "Scene2D::Item::ReleaseLayer(): (layer_.get() == NULL)"; |
606
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
67 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
68 } |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
69 else |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
70 { |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
71 return layer_.release(); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
72 } |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
73 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
74 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
75 uint64_t GetIdentifier() const |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
76 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
77 return identifier_; |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
78 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
79 }; |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
80 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
81 |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
646
diff
changeset
|
82 Scene2D::Scene2D(const Scene2D& other) |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
83 : sceneToCanvas_(other.sceneToCanvas_) |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
646
diff
changeset
|
84 , canvasToScene_(other.canvasToScene_) |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
646
diff
changeset
|
85 , layerCounter_(0) |
582 | 86 { |
87 for (Content::const_iterator it = other.content_.begin(); | |
88 it != other.content_.end(); ++it) | |
89 { | |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
90 content_[it->first] = new Item(it->second->GetLayer().Clone(), layerCounter_++); |
582 | 91 } |
92 } | |
93 | |
94 | |
95 Scene2D::~Scene2D() | |
96 { | |
97 for (Content::iterator it = content_.begin(); | |
98 it != content_.end(); ++it) | |
99 { | |
100 assert(it->second != NULL); | |
101 delete it->second; | |
102 } | |
103 } | |
104 | |
105 | |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
106 ISceneLayer& Scene2D::SetLayer(int depth, |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
107 ISceneLayer* layer) // Takes ownership |
582 | 108 { |
824
15d493101c1e
support of SleepOracleCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
700
diff
changeset
|
109 LOG(TRACE) << "SetLayer(" << depth << ", " << reinterpret_cast<intptr_t>(layer) << ")"; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
110 std::unique_ptr<Item> item(new Item(layer, layerCounter_++)); |
582 | 111 |
112 if (layer == NULL) | |
113 { | |
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
115 } | |
116 | |
117 Content::iterator found = content_.find(depth); | |
118 | |
119 if (found == content_.end()) | |
120 { | |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
121 content_[depth] = item.release(); |
582 | 122 } |
123 else | |
124 { | |
125 assert(found->second != NULL); | |
126 delete found->second; | |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
127 found->second = item.release(); |
582 | 128 } |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
129 |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
130 return *layer; |
582 | 131 } |
132 | |
133 | |
134 void Scene2D::DeleteLayer(int depth) | |
135 { | |
632
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
136 |
582 | 137 Content::iterator found = content_.find(depth); |
138 | |
139 if (found != content_.end()) | |
140 { | |
934
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
824
diff
changeset
|
141 LOG(TRACE) << "DeleteLayer --found-- (" << depth << ")"; |
582 | 142 assert(found->second != NULL); |
143 delete found->second; | |
144 content_.erase(found); | |
145 } | |
146 } | |
147 | |
148 | |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
149 bool Scene2D::HasLayer(int depth) const |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
150 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
151 return (content_.find(depth) != content_.end()); |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
152 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
153 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
154 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
155 ISceneLayer& Scene2D::GetLayer(int depth) const |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
156 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
157 Content::const_iterator found = content_.find(depth); |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
158 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
159 if (found == content_.end()) |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
160 { |
606
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
161 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
602
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
162 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
163 else |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
164 { |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
165 assert(found->second != NULL); |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
166 return found->second->GetLayer(); |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
167 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
168 } |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
169 |
03c4b998fcd0
display scene positions in the basic sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
600
diff
changeset
|
170 |
632
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
171 int Scene2D::GetMinDepth() const |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
172 { |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
173 if (content_.size() == 0) |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
174 return 0; |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
175 else |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
176 return content_.begin()->first; |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
177 } |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
178 |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
179 |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
180 int Scene2D::GetMaxDepth() const |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
181 { |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
182 if (content_.size() == 0) |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
183 return 0; |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
184 else |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
185 return content_.rbegin()->first; |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
186 } |
500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
Benjamin Golinvaux <bgo@osimis.io>
parents:
606
diff
changeset
|
187 |
606
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
188 ISceneLayer* Scene2D::ReleaseLayer(int depth) |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
189 { |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
190 Content::iterator found = content_.find(depth); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
191 |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
192 if (found == content_.end()) |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
193 { |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
194 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
195 } |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
196 else |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
197 { |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
198 assert(found->second != NULL); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
199 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
200 std::unique_ptr<ISceneLayer> layer(found->second->ReleaseLayer()); |
606
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
201 assert(layer.get() != NULL); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
202 |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
203 content_.erase(found); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
204 |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
205 return layer.release(); |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
206 } |
d9c0a66304cb
Scene2D::ReleaseLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
602
diff
changeset
|
207 } |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
934
diff
changeset
|
208 |
600
6129b1e5ba42
BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
582
diff
changeset
|
209 void Scene2D::Apply(IVisitor& visitor) const |
582 | 210 { |
211 for (Content::const_iterator it = content_.begin(); | |
212 it != content_.end(); ++it) | |
213 { | |
214 assert(it->second != NULL); | |
1211
d10d2acb8a02
compositors do not keep a reference to the scene anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
215 visitor.Visit(*this, it->second->GetLayer(), it->second->GetIdentifier(), it->first); |
582 | 216 } |
217 } | |
218 | |
219 | |
220 void Scene2D::SetSceneToCanvasTransform(const AffineTransform2D& transform) | |
221 { | |
222 // Make sure the transform is invertible before making any change | |
223 AffineTransform2D inverse = AffineTransform2D::Invert(transform); | |
224 | |
225 sceneToCanvas_ = transform; | |
226 canvasToScene_ = inverse; | |
227 } | |
228 | |
1610
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
229 void Scene2D::GetBoundingBox(Extent2D& target) const |
1374
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
230 { |
1610
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
231 target.Clear(); |
1374
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
232 |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
233 for (Content::const_iterator it = content_.begin(); |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
234 it != content_.end(); ++it) |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
235 { |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
236 assert(it->second != NULL); |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
237 |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
238 Extent2D tmp; |
1610
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
239 it->second->GetLayer().GetBoundingBox(tmp); |
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
240 target.Union(tmp); |
1374
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
241 } |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
242 } |
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
243 |
582 | 244 void Scene2D::FitContent(unsigned int canvasWidth, |
245 unsigned int canvasHeight) | |
246 { | |
247 Extent2D extent; | |
248 | |
1374
1e4878ed1d77
added GetBoundingBox to Scene2D
Alain Mazy <alain@mazy.be>
parents:
1298
diff
changeset
|
249 GetBoundingBox(extent); |
582 | 250 |
251 if (!extent.IsEmpty()) | |
252 { | |
253 double zoomX = static_cast<double>(canvasWidth) / extent.GetWidth(); | |
254 double zoomY = static_cast<double>(canvasHeight) / extent.GetHeight(); | |
255 | |
256 double zoom = std::min(zoomX, zoomY); | |
257 if (LinearAlgebra::IsCloseToZero(zoom)) | |
258 { | |
259 zoom = 1; | |
260 } | |
261 | |
262 double panX = extent.GetCenterX(); | |
263 double panY = extent.GetCenterY(); | |
264 | |
265 // Bring the center of the scene to (0,0) | |
266 AffineTransform2D t1 = AffineTransform2D::CreateOffset(-panX, -panY); | |
267 | |
268 // Scale the scene | |
269 AffineTransform2D t2 = AffineTransform2D::CreateScaling(zoom, zoom); | |
270 | |
271 SetSceneToCanvasTransform(AffineTransform2D::Combine(t2, t1)); | |
272 } | |
273 } | |
274 } |