Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/DicomVolumeImageReslicer.cpp @ 1886:ca89fec8c48f
test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Jan 2022 19:10:30 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
815 | 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 |
815 | 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 |
815 | 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:
1571
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/>. |
815 | 21 **/ |
22 | |
23 | |
24 #include "DicomVolumeImageReslicer.h" | |
25 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
26 #include <OrthancException.h> |
815 | 27 |
28 namespace OrthancStone | |
29 { | |
30 class DicomVolumeImageReslicer::Slice : public IVolumeSlicer::IExtractedSlice | |
31 { | |
32 private: | |
33 DicomVolumeImageReslicer& that_; | |
34 CoordinateSystem3D cuttingPlane_; | |
35 | |
36 public: | |
37 Slice(DicomVolumeImageReslicer& that, | |
38 const CoordinateSystem3D& cuttingPlane) : | |
39 that_(that), | |
40 cuttingPlane_(cuttingPlane) | |
41 { | |
42 } | |
43 | |
1571 | 44 virtual bool IsValid() ORTHANC_OVERRIDE |
815 | 45 { |
46 return true; | |
47 } | |
48 | |
1571 | 49 virtual uint64_t GetRevision() ORTHANC_OVERRIDE |
815 | 50 { |
51 return that_.volume_->GetRevision(); | |
52 } | |
53 | |
54 virtual ISceneLayer* CreateSceneLayer(const ILayerStyleConfigurator* configurator, | |
1571 | 55 const CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE |
815 | 56 { |
57 VolumeReslicer& reslicer = that_.reslicer_; | |
58 | |
59 if (configurator == NULL) | |
60 { | |
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
62 "Must provide a layer style configurator"); | |
63 } | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
64 |
815 | 65 reslicer.SetOutputFormat(that_.volume_->GetPixelData().GetFormat()); |
66 reslicer.Apply(that_.volume_->GetPixelData(), | |
67 that_.volume_->GetGeometry(), | |
68 cuttingPlane); | |
69 | |
70 if (reslicer.IsSuccess()) | |
71 { | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
72 std::unique_ptr<TextureBaseSceneLayer> texture |
815 | 73 (configurator->CreateTextureFromDicom(reslicer.GetOutputSlice(), |
74 that_.volume_->GetDicomParameters())); | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
75 if (texture.get() == NULL) |
815 | 76 { |
77 return NULL; | |
78 } | |
79 | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
80 const double s = reslicer.GetPixelSpacing(); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
81 |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
82 const double x1 = reslicer.GetOutputExtent().GetX1(); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
83 const double y1 = reslicer.GetOutputExtent().GetY1(); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
84 const Vector p1 = cuttingPlane.MapSliceToWorldCoordinates(x1, y1); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
85 |
1775
fca942f4b4a7
fix conversion from voxel centers to texture borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1771
diff
changeset
|
86 // The "0.5" shift is to move from the corner of voxel to the center of the voxel |
fca942f4b4a7
fix conversion from voxel centers to texture borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1771
diff
changeset
|
87 |
1786
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
88 texture->SetCuttingPlaneTransform( |
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
89 cuttingPlane, p1 + 0.5 * s * cuttingPlane.GetAxisX() + 0.5 * s * cuttingPlane.GetAxisY(), |
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
90 s * cuttingPlane.GetAxisX(), |
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
91 s * cuttingPlane.GetAxisY()); |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
92 |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
93 return texture.release(); |
815 | 94 } |
95 else | |
96 { | |
97 return NULL; | |
98 } | |
99 } | |
100 }; | |
101 | |
102 | |
103 DicomVolumeImageReslicer::DicomVolumeImageReslicer(const boost::shared_ptr<DicomVolumeImage>& volume) : | |
104 volume_(volume) | |
105 { | |
106 if (volume.get() == NULL) | |
107 { | |
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
109 } | |
110 } | |
111 | |
112 | |
113 IVolumeSlicer::IExtractedSlice* DicomVolumeImageReslicer::ExtractSlice(const CoordinateSystem3D& cuttingPlane) | |
114 { | |
115 if (volume_->HasGeometry()) | |
116 { | |
117 return new Slice(*this, cuttingPlane); | |
118 } | |
119 else | |
120 { | |
121 return new IVolumeSlicer::InvalidSlice; | |
122 } | |
123 } | |
124 } |