Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/DicomVolumeImageReslicer.cpp @ 1792:373d7f7e796e
ICompositor::ComputeTextBoundingBox()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 17 May 2021 16:59:03 +0200 |
parents | 748bfa7df18b |
children | 3889ae96d2e9 |
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 | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
815 | 6 * |
7 * 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
|
8 * modify it under the terms of the GNU Lesser General Public License |
815 | 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 | |
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
|
14 * 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
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
815 | 20 **/ |
21 | |
22 | |
23 #include "DicomVolumeImageReslicer.h" | |
24 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
25 #include <OrthancException.h> |
815 | 26 |
27 namespace OrthancStone | |
28 { | |
29 class DicomVolumeImageReslicer::Slice : public IVolumeSlicer::IExtractedSlice | |
30 { | |
31 private: | |
32 DicomVolumeImageReslicer& that_; | |
33 CoordinateSystem3D cuttingPlane_; | |
34 | |
35 public: | |
36 Slice(DicomVolumeImageReslicer& that, | |
37 const CoordinateSystem3D& cuttingPlane) : | |
38 that_(that), | |
39 cuttingPlane_(cuttingPlane) | |
40 { | |
41 } | |
42 | |
1571 | 43 virtual bool IsValid() ORTHANC_OVERRIDE |
815 | 44 { |
45 return true; | |
46 } | |
47 | |
1571 | 48 virtual uint64_t GetRevision() ORTHANC_OVERRIDE |
815 | 49 { |
50 return that_.volume_->GetRevision(); | |
51 } | |
52 | |
53 virtual ISceneLayer* CreateSceneLayer(const ILayerStyleConfigurator* configurator, | |
1571 | 54 const CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE |
815 | 55 { |
56 VolumeReslicer& reslicer = that_.reslicer_; | |
57 | |
58 if (configurator == NULL) | |
59 { | |
60 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
61 "Must provide a layer style configurator"); | |
62 } | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
63 |
815 | 64 reslicer.SetOutputFormat(that_.volume_->GetPixelData().GetFormat()); |
65 reslicer.Apply(that_.volume_->GetPixelData(), | |
66 that_.volume_->GetGeometry(), | |
67 cuttingPlane); | |
68 | |
69 if (reslicer.IsSuccess()) | |
70 { | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
71 std::unique_ptr<TextureBaseSceneLayer> texture |
815 | 72 (configurator->CreateTextureFromDicom(reslicer.GetOutputSlice(), |
73 that_.volume_->GetDicomParameters())); | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
74 if (texture.get() == NULL) |
815 | 75 { |
76 return NULL; | |
77 } | |
78 | |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
79 const double s = reslicer.GetPixelSpacing(); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
80 |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
81 const double x1 = reslicer.GetOutputExtent().GetX1(); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
82 const double y1 = reslicer.GetOutputExtent().GetY1(); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
83 const Vector p1 = cuttingPlane.MapSliceToWorldCoordinates(x1, y1); |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
84 |
1775
fca942f4b4a7
fix conversion from voxel centers to texture borders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1771
diff
changeset
|
85 // 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
|
86 |
1786
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
87 texture->SetCuttingPlaneTransform( |
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
88 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
|
89 s * cuttingPlane.GetAxisX(), |
748bfa7df18b
removing test code in DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1775
diff
changeset
|
90 s * cuttingPlane.GetAxisY()); |
1771
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
91 |
f302bbddf94d
sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
92 return texture.release(); |
815 | 93 } |
94 else | |
95 { | |
96 return NULL; | |
97 } | |
98 } | |
99 }; | |
100 | |
101 | |
102 DicomVolumeImageReslicer::DicomVolumeImageReslicer(const boost::shared_ptr<DicomVolumeImage>& volume) : | |
103 volume_(volume) | |
104 { | |
105 if (volume.get() == NULL) | |
106 { | |
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
108 } | |
109 } | |
110 | |
111 | |
112 IVolumeSlicer::IExtractedSlice* DicomVolumeImageReslicer::ExtractSlice(const CoordinateSystem3D& cuttingPlane) | |
113 { | |
114 if (volume_->HasGeometry()) | |
115 { | |
116 return new Slice(*this, cuttingPlane); | |
117 } | |
118 else | |
119 { | |
120 return new IVolumeSlicer::InvalidSlice; | |
121 } | |
122 } | |
123 } |