Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Volumes/DicomStructureSetSlicer2.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Volumes/DicomStructureSetSlicer2.cpp@8a0a62189f46 |
children | 8563ea5d8ae4 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
22 | |
23 #include "DicomStructureSetSlicer2.h" | |
24 | |
25 #include "../Toolbox/GeometryToolbox.h" | |
26 #include "../Volumes/IVolumeSlicer.h" | |
27 #include "../Scene2D/PolylineSceneLayer.h" | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 DicomStructureSetSlicer2::DicomStructureSetSlicer2(boost::shared_ptr<DicomStructureSet2> structureSet) | |
32 : structureSet_(structureSet) | |
33 {} | |
34 | |
35 IVolumeSlicer::IExtractedSlice* DicomStructureSetSlicer2::ExtractSlice(const CoordinateSystem3D& cuttingPlane) | |
36 { | |
37 // revision is always the same, hence 0 | |
38 return new DicomStructureSetSlice2(structureSet_, 0, cuttingPlane); | |
39 } | |
40 | |
41 DicomStructureSetSlice2::DicomStructureSetSlice2( | |
42 boost::weak_ptr<DicomStructureSet2> structureSet, | |
43 uint64_t revision, | |
44 const CoordinateSystem3D& cuttingPlane) | |
45 : structureSet_(structureSet.lock()) | |
46 , isValid_(false) | |
47 { | |
48 bool opposite = false; | |
49 | |
50 if (structureSet_->GetStructuresCount() == 0) | |
51 { | |
52 isValid_ = false; | |
53 } | |
54 else | |
55 { | |
56 // some structures seen in real life have no polygons. We must be | |
57 // careful | |
58 bool found = false; | |
59 size_t curStructure = 0; | |
60 while (!found && curStructure < structureSet_->GetStructuresCount()) | |
61 { | |
62 if (structureSet_->GetStructure(curStructure).IsValid()) | |
63 { | |
64 found = true; | |
65 const Vector normal = structureSet_->GetStructure(0).GetNormal(); | |
66 isValid_ = ( | |
67 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetNormal()) || | |
68 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisX()) || | |
69 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisY())); | |
70 } | |
71 } | |
72 } | |
73 } | |
74 | |
75 ISceneLayer* DicomStructureSetSlice2::CreateSceneLayer( | |
76 const ILayerStyleConfigurator* configurator, | |
77 const CoordinateSystem3D& cuttingPlane) | |
78 { | |
79 assert(isValid_); | |
80 | |
81 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); | |
82 layer->SetThickness(2); // thickness of the on-screen line | |
83 | |
84 for (size_t i = 0; i < structureSet_->GetStructuresCount(); i++) | |
85 { | |
86 const DicomStructure2& structure = structureSet_->GetStructure(i); | |
87 if (structure.IsValid()) | |
88 { | |
89 const Color& color = structure.GetColor(); | |
90 | |
91 std::vector< std::pair<Point2D, Point2D> > segments; | |
92 | |
93 if (structure.Project(segments, cuttingPlane)) | |
94 { | |
95 for (size_t j = 0; j < segments.size(); j++) | |
96 { | |
97 PolylineSceneLayer::Chain chain; | |
98 chain.resize(2); | |
99 | |
100 chain[0] = ScenePoint2D(segments[j].first.x, segments[j].first.y); | |
101 chain[1] = ScenePoint2D(segments[j].second.x, segments[j].second.y); | |
102 | |
103 layer->AddChain(chain, false /* NOT closed */, color); | |
104 } | |
105 } | |
106 } | |
107 } | |
108 return layer.release(); | |
109 } | |
110 } | |
111 | |
112 | |
113 #endif | |
114 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
115 | |
116 |