815
|
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 "DicomVolumeImageReslicer.h"
|
|
23
|
|
24 #include <Core/OrthancException.h>
|
|
25
|
|
26 namespace OrthancStone
|
|
27 {
|
|
28 class DicomVolumeImageReslicer::Slice : public IVolumeSlicer::IExtractedSlice
|
|
29 {
|
|
30 private:
|
|
31 DicomVolumeImageReslicer& that_;
|
|
32 CoordinateSystem3D cuttingPlane_;
|
|
33
|
|
34 public:
|
|
35 Slice(DicomVolumeImageReslicer& that,
|
|
36 const CoordinateSystem3D& cuttingPlane) :
|
|
37 that_(that),
|
|
38 cuttingPlane_(cuttingPlane)
|
|
39 {
|
|
40 }
|
|
41
|
|
42 virtual bool IsValid()
|
|
43 {
|
|
44 return true;
|
|
45 }
|
|
46
|
|
47 virtual uint64_t GetRevision()
|
|
48 {
|
|
49 return that_.volume_->GetRevision();
|
|
50 }
|
|
51
|
|
52 virtual ISceneLayer* CreateSceneLayer(const ILayerStyleConfigurator* configurator,
|
|
53 const CoordinateSystem3D& cuttingPlane)
|
|
54 {
|
|
55 VolumeReslicer& reslicer = that_.reslicer_;
|
|
56
|
|
57 if (configurator == NULL)
|
|
58 {
|
|
59 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
|
|
60 "Must provide a layer style configurator");
|
|
61 }
|
|
62
|
|
63 reslicer.SetOutputFormat(that_.volume_->GetPixelData().GetFormat());
|
|
64 reslicer.Apply(that_.volume_->GetPixelData(),
|
|
65 that_.volume_->GetGeometry(),
|
|
66 cuttingPlane);
|
|
67
|
|
68 if (reslicer.IsSuccess())
|
|
69 {
|
|
70 std::auto_ptr<TextureBaseSceneLayer> layer
|
|
71 (configurator->CreateTextureFromDicom(reslicer.GetOutputSlice(),
|
|
72 that_.volume_->GetDicomParameters()));
|
|
73 if (layer.get() == NULL)
|
|
74 {
|
|
75 return NULL;
|
|
76 }
|
|
77
|
|
78 double s = reslicer.GetPixelSpacing();
|
|
79 layer->SetPixelSpacing(s, s);
|
|
80 layer->SetOrigin(reslicer.GetOutputExtent().GetX1() + 0.5 * s,
|
|
81 reslicer.GetOutputExtent().GetY1() + 0.5 * s);
|
|
82
|
|
83 // TODO - Angle!!
|
|
84
|
|
85 return layer.release();
|
|
86 }
|
|
87 else
|
|
88 {
|
|
89 return NULL;
|
|
90 }
|
|
91 }
|
|
92 };
|
|
93
|
|
94
|
|
95 DicomVolumeImageReslicer::DicomVolumeImageReslicer(const boost::shared_ptr<DicomVolumeImage>& volume) :
|
|
96 volume_(volume)
|
|
97 {
|
|
98 if (volume.get() == NULL)
|
|
99 {
|
|
100 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
|
|
101 }
|
|
102 }
|
|
103
|
|
104
|
|
105 IVolumeSlicer::IExtractedSlice* DicomVolumeImageReslicer::ExtractSlice(const CoordinateSystem3D& cuttingPlane)
|
|
106 {
|
|
107 if (volume_->HasGeometry())
|
|
108 {
|
|
109 return new Slice(*this, cuttingPlane);
|
|
110 }
|
|
111 else
|
|
112 {
|
|
113 return new IVolumeSlicer::InvalidSlice;
|
|
114 }
|
|
115 }
|
|
116 }
|