annotate OrthancStone/Sources/Scene2D/Scene2D.cpp @ 1556:8898f8f755c8

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