annotate OrthancStone/Sources/Scene2D/OsiriXLayerFactory.cpp @ 2093:c336e07b675c dicom-sr

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 Nov 2023 12:37:42 +0100
parents 07964689cb0b
children c23eef785569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1615
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1615
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Lesser General Public License for more details.
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * License along with this program. If not, see
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "OsiriXLayerFactory.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Toolbox/OsiriX/AngleAnnotation.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../Toolbox/OsiriX/LineAnnotation.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../Toolbox/OsiriX/TextAnnotation.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "ArrowSceneLayer.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "PolylineSceneLayer.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "TextSceneLayer.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <OrthancException.h>
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <boost/math/constants/constants.hpp>
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace OrthancStone
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 OsiriXLayerFactory::OsiriXLayerFactory() :
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 thickness_(1),
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 arrowLength_(10), // 10 pixels
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 arrowAngle_(boost::math::constants::pi<double>() / 12.0), // 15 degrees
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 fontIndex_(0)
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ISceneLayer* OsiriXLayerFactory::Create(const OsiriX::Annotation& annotation,
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 const CoordinateSystem3D& plane) const
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 switch (annotation.GetType())
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 case OsiriX::Annotation::Type_Line:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const OsiriX::LineAnnotation& line = dynamic_cast<const OsiriX::LineAnnotation&>(annotation);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 const ScenePoint2D p1 = plane.ProjectPoint(line.GetPoint1());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 const ScenePoint2D p2 = plane.ProjectPoint(line.GetPoint2());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 if (line.IsArrow())
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 std::unique_ptr<ArrowSceneLayer> layer(new ArrowSceneLayer(p1, p2));
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 layer->SetColor(color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 layer->SetThickness(thickness_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 layer->SetArrowAngle(arrowAngle_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 layer->SetArrowLength(arrowLength_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 else
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 PolylineSceneLayer::Chain chain;
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 chain.push_back(p1);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 chain.push_back(p2);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 layer->AddChain(chain, false, color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 layer->SetThickness(thickness_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 break;
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 case OsiriX::Annotation::Type_Angle:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 const OsiriX::AngleAnnotation& angle = dynamic_cast<const OsiriX::AngleAnnotation&>(annotation);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 const ScenePoint2D a = plane.ProjectPoint(angle.GetA());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 const ScenePoint2D center = plane.ProjectPoint(angle.GetCenter());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 const ScenePoint2D b = plane.ProjectPoint(angle.GetB());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 PolylineSceneLayer::Chain chain;
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 chain.push_back(a);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 chain.push_back(center);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 chain.push_back(b);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 layer->AddChain(chain, false, color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 layer->SetThickness(thickness_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 case OsiriX::Annotation::Type_Text:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 const OsiriX::TextAnnotation& text = dynamic_cast<const OsiriX::TextAnnotation&>(annotation);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 const ScenePoint2D center = plane.ProjectPoint(text.GetCenter());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 std::unique_ptr<TextSceneLayer> layer(new TextSceneLayer());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 layer->SetPosition(center.GetX(), center.GetY());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 layer->SetText(text.GetText());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 layer->SetAnchor(BitmapAnchor_Center);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 layer->SetColor(color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 layer->SetFontIndex(fontIndex_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 default:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 "Annotation type not implemented: " +
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 boost::lexical_cast<std::string>(annotation.GetType()));
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }