comparison Framework/Volumes/DicomStructureSetSlicer2.cpp @ 998:38b6bb0bdd72

added a new set of classes that correctly handle non-convex polygons (not used yet because of limitations in coordinates computing): DicomStructure2, DicomStructureSet2, DicomStructurePolygon2, DicomStructureSetSlicer2. Too many shortcuts have been taken when computing the actual position.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 20 Sep 2019 11:58:00 +0200
parents
children 29f5f2031310
comparison
equal deleted inserted replaced
995:9893fa8cd7a6 998:38b6bb0bdd72
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 #include "DicomStructureSetSlicer2.h"
22
23 #include "../Toolbox/GeometryToolbox.h"
24 #include "../Volumes/IVolumeSlicer.h"
25 #include "../Scene2D/PolylineSceneLayer.h"
26
27 namespace OrthancStone
28 {
29 DicomStructureSetSlicer2::DicomStructureSetSlicer2(boost::shared_ptr<DicomStructureSet2> structureSet)
30 : structureSet_(structureSet)
31 {}
32
33 IVolumeSlicer::IExtractedSlice* DicomStructureSetSlicer2::ExtractSlice(const CoordinateSystem3D& cuttingPlane)
34 {
35 // revision is always the same, hence 0
36 return new DicomStructureSetSlice2(structureSet_, 0, cuttingPlane);
37 }
38
39 DicomStructureSetSlice2::DicomStructureSetSlice2(
40 boost::weak_ptr<DicomStructureSet2> structureSet,
41 uint64_t revision,
42 const CoordinateSystem3D& cuttingPlane)
43 : structureSet_(structureSet.lock())
44 , isValid_(false)
45 {
46 bool opposite = false;
47
48 if (structureSet_->GetStructuresCount() == 0)
49 {
50 isValid_ = false;
51 }
52 else
53 {
54 // some structures seen in real life have no polygons. We must be
55 // careful
56 bool found = false;
57 size_t curStructure = 0;
58 while (!found && curStructure < structureSet_->GetStructuresCount())
59 {
60 if (structureSet_->GetStructure(curStructure).IsValid())
61 {
62 found = true;
63 const Vector normal = structureSet_->GetStructure(0).GetNormal();
64 isValid_ = (
65 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetNormal()) ||
66 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisX()) ||
67 GeometryToolbox::IsParallelOrOpposite(opposite, normal, cuttingPlane.GetAxisY()));
68 }
69 }
70 }
71 }
72
73 ISceneLayer* DicomStructureSetSlice2::CreateSceneLayer(
74 const ILayerStyleConfigurator* configurator,
75 const CoordinateSystem3D& cuttingPlane)
76 {
77 assert(isValid_);
78
79 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
80 layer->SetThickness(2); // thickness of the on-screen line
81
82 for (size_t i = 0; i < structureSet_->GetStructuresCount(); i++)
83 {
84 const DicomStructure2& structure = structureSet_->GetStructure(i);
85 if (structure.IsValid())
86 {
87 const Color& color = structure.GetColor();
88
89 std::vector< std::pair<Point2D, Point2D> > segments;
90
91 if (structure.Project(segments, cuttingPlane))
92 {
93 for (size_t j = 0; j < segments.size(); j++)
94 {
95 PolylineSceneLayer::Chain chain;
96 chain.resize(2);
97
98 chain[0] = ScenePoint2D(segments[j].first.x, segments[j].first.y);
99 chain[1] = ScenePoint2D(segments[j].second.x, segments[j].second.y);
100
101 layer->AddChain(chain, false /* NOT closed */, color);
102 }
103 }
104 }
105 }
106 return layer.release();
107 }
108 }
109