comparison Framework/Scene2D/PolylineSceneLayer.cpp @ 584:434ceeb0bcab

layers: InfoPanel, Polyline, Texture
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 Apr 2019 17:36:00 +0200
parents
children 500c3f70b6c2
comparison
equal deleted inserted replaced
583:f9ac154c5a63 584:434ceeb0bcab
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
22 #include "PolylineSceneLayer.h"
23
24 #include <Core/OrthancException.h>
25
26 namespace OrthancStone
27 {
28 ISceneLayer* PolylineSceneLayer::Clone() const
29 {
30 std::auto_ptr<PolylineSceneLayer> cloned(new PolylineSceneLayer);
31 cloned->Copy(*this);
32 return cloned.release();
33 }
34
35
36 void PolylineSceneLayer::SetThickness(double thickness)
37 {
38 if (thickness <= 0)
39 {
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
41 }
42 else
43 {
44 thickness_ = thickness;
45 }
46 }
47
48
49 void PolylineSceneLayer::Copy(const PolylineSceneLayer& from)
50 {
51 SetColor(from.GetRed(), from.GetGreen(), from.GetBlue());
52 chains_ = from.chains_;
53 closed_ = from.closed_;
54 thickness_ = from.thickness_;
55 }
56
57
58 void PolylineSceneLayer::Reserve(size_t countChains)
59 {
60 chains_.reserve(countChains);
61 closed_.reserve(countChains);
62 }
63
64
65 void PolylineSceneLayer::AddChain(const Chain& chain,
66 bool isClosed)
67 {
68 if (!chain.empty())
69 {
70 chains_.push_back(chain);
71 closed_.push_back(isClosed);
72 }
73 }
74
75
76 const PolylineSceneLayer::Chain& PolylineSceneLayer::GetChain(size_t i) const
77 {
78 if (i < chains_.size())
79 {
80 return chains_[i];
81 }
82 else
83 {
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
85 }
86 }
87
88
89 bool PolylineSceneLayer::IsClosedChain(size_t i) const
90 {
91 if (i < closed_.size())
92 {
93 return closed_[i];
94 }
95 else
96 {
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
98 }
99 }
100
101
102 bool PolylineSceneLayer::GetBoundingBox(Extent2D& target) const
103 {
104 target.Reset();
105
106 for (size_t i = 0; i < chains_.size(); i++)
107 {
108 for (size_t j = 0; j < chains_[i].size(); j++)
109 {
110 const ScenePoint2D& p = chains_[i][j];
111 target.AddPoint(p.GetX(), p.GetY());
112 }
113 }
114
115 return true;
116 }
117 }