comparison OrthancStone/Sources/Scene2D/OsiriXLayerFactory.cpp @ 1615:f5d4bd7b5593

new class: OsiriXLayerFactory
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Oct 2020 17:26:44 +0100
parents
children 9ac2a65d4172
comparison
equal deleted inserted replaced
1614:ad9b425f27ae 1615:f5d4bd7b5593
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 Lesser 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 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #include "OsiriXLayerFactory.h"
24
25 #include "../Toolbox/OsiriX/AngleAnnotation.h"
26 #include "../Toolbox/OsiriX/LineAnnotation.h"
27 #include "../Toolbox/OsiriX/TextAnnotation.h"
28
29 #include "ArrowSceneLayer.h"
30 #include "PolylineSceneLayer.h"
31 #include "TextSceneLayer.h"
32
33 #include <OrthancException.h>
34
35 #include <boost/math/constants/constants.hpp>
36
37 namespace OrthancStone
38 {
39 OsiriXLayerFactory::OsiriXLayerFactory() :
40 thickness_(1),
41 arrowLength_(10), // 10 pixels
42 arrowAngle_(boost::math::constants::pi<double>() / 12.0), // 15 degrees
43 fontIndex_(0)
44 {
45 }
46
47
48 ISceneLayer* OsiriXLayerFactory::Create(const OsiriX::Annotation& annotation,
49 const CoordinateSystem3D& plane) const
50 {
51 switch (annotation.GetType())
52 {
53 case OsiriX::Annotation::Type_Line:
54 {
55 const OsiriX::LineAnnotation& line = dynamic_cast<const OsiriX::LineAnnotation&>(annotation);
56
57 const ScenePoint2D p1 = plane.ProjectPoint(line.GetPoint1());
58 const ScenePoint2D p2 = plane.ProjectPoint(line.GetPoint2());
59
60 if (line.IsArrow())
61 {
62 std::unique_ptr<ArrowSceneLayer> layer(new ArrowSceneLayer(p1, p2));
63 layer->SetColor(color_);
64 layer->SetThickness(thickness_);
65 layer->SetArrowAngle(arrowAngle_);
66 layer->SetArrowLength(arrowLength_);
67 return layer.release();
68 }
69 else
70 {
71 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
72 PolylineSceneLayer::Chain chain;
73 chain.push_back(p1);
74 chain.push_back(p2);
75 layer->AddChain(chain, false, color_);
76 layer->SetThickness(thickness_);
77 return layer.release();
78 }
79
80 break;
81 }
82
83 case OsiriX::Annotation::Type_Angle:
84 {
85 const OsiriX::AngleAnnotation& angle = dynamic_cast<const OsiriX::AngleAnnotation&>(annotation);
86
87 const ScenePoint2D a = plane.ProjectPoint(angle.GetA());
88 const ScenePoint2D center = plane.ProjectPoint(angle.GetCenter());
89 const ScenePoint2D b = plane.ProjectPoint(angle.GetB());
90
91 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
92 PolylineSceneLayer::Chain chain;
93 chain.push_back(a);
94 chain.push_back(center);
95 chain.push_back(b);
96 layer->AddChain(chain, false, color_);
97 layer->SetThickness(thickness_);
98
99 return layer.release();
100 }
101
102 case OsiriX::Annotation::Type_Text:
103 {
104 const OsiriX::TextAnnotation& text = dynamic_cast<const OsiriX::TextAnnotation&>(annotation);
105
106 const ScenePoint2D center = plane.ProjectPoint(text.GetCenter());
107
108 std::unique_ptr<TextSceneLayer> layer(new TextSceneLayer());
109 layer->SetPosition(center.GetX(), center.GetY());
110 layer->SetText(text.GetText());
111 layer->SetAnchor(BitmapAnchor_Center);
112 layer->SetColor(color_);
113 layer->SetFontIndex(fontIndex_);
114
115 return layer.release();
116 }
117
118 default:
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
120 "Annotation type not implemented: " +
121 boost::lexical_cast<std::string>(annotation.GetType()));
122 }
123
124 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
125 }
126 }