annotate OrthancStone/Sources/Scene2D/OsiriXLayerFactory.cpp @ 1640:52b8b96cb55f

cleaning namespaces
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Nov 2020 16:55:22 +0100
parents f5d4bd7b5593
children 9ac2a65d4172
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
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * as published by the Free Software Foundation, either version 3 of
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Lesser General Public License for more details.
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * License along with this program. If not, see
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * <http://www.gnu.org/licenses/>.
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
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 #include "OsiriXLayerFactory.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../Toolbox/OsiriX/AngleAnnotation.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Toolbox/OsiriX/LineAnnotation.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../Toolbox/OsiriX/TextAnnotation.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "ArrowSceneLayer.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "PolylineSceneLayer.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "TextSceneLayer.h"
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <OrthancException.h>
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <boost/math/constants/constants.hpp>
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace OrthancStone
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 OsiriXLayerFactory::OsiriXLayerFactory() :
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 thickness_(1),
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 arrowLength_(10), // 10 pixels
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 arrowAngle_(boost::math::constants::pi<double>() / 12.0), // 15 degrees
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 fontIndex_(0)
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
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 ISceneLayer* OsiriXLayerFactory::Create(const OsiriX::Annotation& annotation,
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const CoordinateSystem3D& plane) const
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 switch (annotation.GetType())
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 case OsiriX::Annotation::Type_Line:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const OsiriX::LineAnnotation& line = dynamic_cast<const OsiriX::LineAnnotation&>(annotation);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const ScenePoint2D p1 = plane.ProjectPoint(line.GetPoint1());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 const ScenePoint2D p2 = plane.ProjectPoint(line.GetPoint2());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (line.IsArrow())
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 std::unique_ptr<ArrowSceneLayer> layer(new ArrowSceneLayer(p1, p2));
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 layer->SetColor(color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 layer->SetThickness(thickness_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 layer->SetArrowAngle(arrowAngle_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 layer->SetArrowLength(arrowLength_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 else
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 PolylineSceneLayer::Chain chain;
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 chain.push_back(p1);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 chain.push_back(p2);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 layer->AddChain(chain, false, color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 layer->SetThickness(thickness_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
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 break;
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
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 case OsiriX::Annotation::Type_Angle:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 const OsiriX::AngleAnnotation& angle = dynamic_cast<const OsiriX::AngleAnnotation&>(annotation);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 const ScenePoint2D a = plane.ProjectPoint(angle.GetA());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 const ScenePoint2D center = plane.ProjectPoint(angle.GetCenter());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 const ScenePoint2D b = plane.ProjectPoint(angle.GetB());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 PolylineSceneLayer::Chain chain;
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 chain.push_back(a);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 chain.push_back(center);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 chain.push_back(b);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 layer->AddChain(chain, false, color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 layer->SetThickness(thickness_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
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 case OsiriX::Annotation::Type_Text:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 const OsiriX::TextAnnotation& text = dynamic_cast<const OsiriX::TextAnnotation&>(annotation);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 const ScenePoint2D center = plane.ProjectPoint(text.GetCenter());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 std::unique_ptr<TextSceneLayer> layer(new TextSceneLayer());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 layer->SetPosition(center.GetX(), center.GetY());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 layer->SetText(text.GetText());
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 layer->SetAnchor(BitmapAnchor_Center);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 layer->SetColor(color_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 layer->SetFontIndex(fontIndex_);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return layer.release();
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
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 default:
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 "Annotation type not implemented: " +
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 boost::lexical_cast<std::string>(annotation.GetType()));
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
f5d4bd7b5593 new class: OsiriXLayerFactory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }