comparison Framework/Volumes/VolumeSceneLayerSource.cpp @ 815:df442f1ba0c6

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 May 2019 21:59:20 +0200
parents
children 81d30cd93b65
comparison
equal deleted inserted replaced
814:aead999345e0 815:df442f1ba0c6
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-2019 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 "VolumeSceneLayerSource.h"
23
24 #include <Core/OrthancException.h>
25
26 namespace OrthancStone
27 {
28 static bool IsSameCuttingPlane(const CoordinateSystem3D& a,
29 const CoordinateSystem3D& b)
30 {
31 // TODO - What if the normal is reversed?
32 double distance;
33 return (CoordinateSystem3D::ComputeDistance(distance, a, b) &&
34 LinearAlgebra::IsCloseToZero(distance));
35 }
36
37
38 void VolumeSceneLayerSource::ClearLayer()
39 {
40 scene_.DeleteLayer(layerDepth_);
41 lastPlane_.reset(NULL);
42 }
43
44
45 VolumeSceneLayerSource::VolumeSceneLayerSource(Scene2D& scene,
46 int layerDepth,
47 const boost::shared_ptr<IVolumeSlicer>& slicer) :
48 scene_(scene),
49 layerDepth_(layerDepth),
50 slicer_(slicer)
51 {
52 if (slicer == NULL)
53 {
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
55 }
56 }
57
58
59 void VolumeSceneLayerSource::RemoveConfigurator()
60 {
61 configurator_.reset();
62 lastPlane_.reset();
63 }
64
65
66 void VolumeSceneLayerSource::SetConfigurator(ILayerStyleConfigurator* configurator) // Takes ownership
67 {
68 if (configurator == NULL)
69 {
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
71 }
72
73 configurator_.reset(configurator);
74
75 // Invalidate the layer
76 lastPlane_.reset(NULL);
77 }
78
79
80 ILayerStyleConfigurator& VolumeSceneLayerSource::GetConfigurator() const
81 {
82 if (configurator_.get() == NULL)
83 {
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
85 }
86
87 return *configurator_;
88 }
89
90
91 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane)
92 {
93 assert(slicer_.get() != NULL);
94 std::auto_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane));
95
96 if (slice.get() == NULL)
97 {
98 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
99 }
100
101 if (!slice->IsValid())
102 {
103 // The slicer cannot handle this cutting plane: Clear the layer
104 ClearLayer();
105 }
106 else if (lastPlane_.get() != NULL &&
107 IsSameCuttingPlane(*lastPlane_, plane) &&
108 lastRevision_ == slice->GetRevision())
109 {
110 // The content of the slice has not changed: Don't update the
111 // layer content, but possibly update its style
112
113 if (configurator_.get() != NULL &&
114 configurator_->GetRevision() != lastConfiguratorRevision_ &&
115 scene_.HasLayer(layerDepth_))
116 {
117 configurator_->ApplyStyle(scene_.GetLayer(layerDepth_));
118 }
119 }
120 else
121 {
122 // Content has changed: An update is needed
123 lastPlane_.reset(new CoordinateSystem3D(plane));
124 lastRevision_ = slice->GetRevision();
125
126 std::auto_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane));
127 if (layer.get() == NULL)
128 {
129 ClearLayer();
130 }
131 else
132 {
133 if (configurator_.get() != NULL)
134 {
135 lastConfiguratorRevision_ = configurator_->GetRevision();
136 configurator_->ApplyStyle(*layer);
137 }
138
139 scene_.SetLayer(layerDepth_, layer.release());
140 }
141 }
142 }
143 }