comparison OrthancStone/Resources/Graveyard/RTStructTentativeReimplementation-BGO/DicomStructureSetSlicer2.cpp @ 1908:affde38b84de

moved tentative bgo reimplementation of rt-struct into graveyard
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Feb 2022 08:38:32 +0100
parents OrthancStone/Sources/Volumes/DicomStructureSetSlicer2.cpp@14c8f339d480
children 07964689cb0b
comparison
equal deleted inserted replaced
1907:0208f99b8bde 1908:affde38b84de
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-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
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
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 **/
22
23 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
24
25 #include "DicomStructureSetSlicer2.h"
26
27 #include "../Toolbox/GeometryToolbox.h"
28 #include "../Volumes/IVolumeSlicer.h"
29 #include "../Scene2D/PolylineSceneLayer.h"
30
31 namespace OrthancStone
32 {
33 DicomStructureSetSlicer2::DicomStructureSetSlicer2(boost::shared_ptr<DicomStructureSet2> structureSet)
34 : structureSet_(structureSet)
35 {}
36
37 IVolumeSlicer::IExtractedSlice* DicomStructureSetSlicer2::ExtractSlice(const CoordinateSystem3D& cuttingPlane)
38 {
39 // revision is always the same, hence 0
40 return new DicomStructureSetSlice2(structureSet_, 0, cuttingPlane);
41 }
42
43 DicomStructureSetSlice2::DicomStructureSetSlice2(
44 boost::weak_ptr<DicomStructureSet2> structureSet,
45 uint64_t revision,
46 const CoordinateSystem3D& cuttingPlane)
47 : structureSet_(structureSet.lock())
48 , isValid_(false)
49 {
50 bool opposite = false;
51
52 if (structureSet_->GetStructuresCount() == 0)
53 {
54 isValid_ = false;
55 }
56 else
57 {
58 // some structures seen in real life have no polygons. We must be
59 // careful
60 bool found = false;
61 size_t curStructure = 0;
62 while (!found && curStructure < structureSet_->GetStructuresCount())
63 {
64 if (structureSet_->GetStructure(curStructure).IsValid())
65 {
66 found = true;
67 const Vector normal = structureSet_->GetStructure(0).GetNormal();
68 isValid_ = (
69 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetNormal()) ||
70 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisX()) ||
71 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisY()));
72 }
73 }
74 }
75 }
76
77 ISceneLayer* DicomStructureSetSlice2::CreateSceneLayer(
78 const ILayerStyleConfigurator* configurator,
79 const CoordinateSystem3D& cuttingPlane)
80 {
81 assert(isValid_);
82
83 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
84 layer->SetThickness(2); // thickness of the on-screen line
85
86 for (size_t i = 0; i < structureSet_->GetStructuresCount(); i++)
87 {
88 const DicomStructure2& structure = structureSet_->GetStructure(i);
89 if (structure.IsValid())
90 {
91 const Color& color = structure.GetColor();
92
93 std::vector< std::pair<ScenePoint2D, ScenePoint2D> > segments;
94
95 if (structure.Project(segments, cuttingPlane))
96 {
97 for (size_t j = 0; j < segments.size(); j++)
98 {
99 PolylineSceneLayer::Chain chain;
100 chain.resize(2);
101
102 chain[0] = ScenePoint2D(segments[j].first.GetX(), segments[j].first.GetY());
103 chain[1] = ScenePoint2D(segments[j].second.GetX(), segments[j].second.GetY());
104
105 layer->AddChain(chain, false /* NOT closed */, color);
106 }
107 }
108 }
109 }
110 return layer.release();
111 }
112 }
113
114
115 #endif
116 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2
117
118