Mercurial > hg > orthanc-stone
comparison Framework/Scene2D/PolylineSceneLayer.cpp @ 804:61ba4b504e9a
PolylineSceneLayer now has one color per chain
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 28 May 2019 15:58:21 +0200 |
parents | 500c3f70b6c2 |
children | 2d8ab34c8c91 |
comparison
equal
deleted
inserted
replaced
802:f38c1fc08655 | 804:61ba4b504e9a |
---|---|
23 | 23 |
24 #include <Core/OrthancException.h> | 24 #include <Core/OrthancException.h> |
25 | 25 |
26 namespace OrthancStone | 26 namespace OrthancStone |
27 { | 27 { |
28 void PolylineSceneLayer::Copy(const PolylineSceneLayer& other) | |
29 { | |
30 items_ = other.items_; | |
31 thickness_ = other.thickness_; | |
32 revision_ ++; | |
33 } | |
34 | |
35 | |
28 ISceneLayer* PolylineSceneLayer::Clone() const | 36 ISceneLayer* PolylineSceneLayer::Clone() const |
29 { | 37 { |
30 std::auto_ptr<PolylineSceneLayer> cloned(new PolylineSceneLayer); | 38 std::auto_ptr<PolylineSceneLayer> cloned(new PolylineSceneLayer); |
31 cloned->Copy(*this); | 39 cloned->Copy(*this); |
32 return cloned.release(); | 40 return cloned.release(); |
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 48 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
41 } | 49 } |
42 else | 50 else |
43 { | 51 { |
44 thickness_ = thickness; | 52 thickness_ = thickness; |
45 BumpRevision(); | 53 revision_++; |
46 } | 54 } |
47 } | 55 } |
48 | 56 |
49 | 57 |
50 void PolylineSceneLayer::Copy(const PolylineSceneLayer& from) | |
51 { | |
52 SetColor(from.GetRed(), from.GetGreen(), from.GetBlue()); | |
53 chains_ = from.chains_; | |
54 closed_ = from.closed_; | |
55 thickness_ = from.thickness_; | |
56 BumpRevision(); | |
57 } | |
58 | |
59 | |
60 void PolylineSceneLayer::Reserve(size_t countChains) | |
61 { | |
62 chains_.reserve(countChains); | |
63 closed_.reserve(countChains); | |
64 } | |
65 | |
66 | |
67 void PolylineSceneLayer::AddChain(const Chain& chain, | 58 void PolylineSceneLayer::AddChain(const Chain& chain, |
68 bool isClosed) | 59 bool isClosed, |
60 uint8_t red, | |
61 uint8_t green, | |
62 uint8_t blue) | |
69 { | 63 { |
70 if (!chain.empty()) | 64 if (!chain.empty()) |
71 { | 65 { |
72 chains_.push_back(chain); | 66 items_.push_back(Item()); |
73 closed_.push_back(isClosed); | 67 items_.back().chain_ = chain; |
74 BumpRevision(); | 68 items_.back().closed_ = isClosed; |
69 items_.back().color_ = Color(red, green, blue); | |
70 | |
71 revision_++; | |
75 } | 72 } |
76 } | 73 } |
77 | 74 |
78 | 75 |
79 void PolylineSceneLayer::ClearAllChains() | 76 void PolylineSceneLayer::ClearAllChains() |
80 { | 77 { |
81 chains_.clear(); | 78 items_.clear(); |
82 closed_.clear(); | 79 revision_++; |
83 BumpRevision(); | |
84 } | 80 } |
85 | 81 |
86 const PolylineSceneLayer::Chain& PolylineSceneLayer::GetChain(size_t i) const | 82 const PolylineSceneLayer::Item& PolylineSceneLayer::GetItem(size_t i) const |
87 { | 83 { |
88 if (i < chains_.size()) | 84 if (i < items_.size()) |
89 { | 85 { |
90 return chains_[i]; | 86 return items_[i]; |
91 } | 87 } |
92 else | 88 else |
93 { | 89 { |
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 90 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
95 } | 91 } |
96 } | 92 } |
97 | 93 |
98 | 94 |
99 bool PolylineSceneLayer::IsClosedChain(size_t i) const | |
100 { | |
101 if (i < closed_.size()) | |
102 { | |
103 return closed_[i]; | |
104 } | |
105 else | |
106 { | |
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
108 } | |
109 } | |
110 | |
111 | |
112 bool PolylineSceneLayer::GetBoundingBox(Extent2D& target) const | 95 bool PolylineSceneLayer::GetBoundingBox(Extent2D& target) const |
113 { | 96 { |
114 target.Reset(); | 97 target.Reset(); |
115 | 98 |
116 for (size_t i = 0; i < chains_.size(); i++) | 99 for (size_t i = 0; i < items_.size(); i++) |
117 { | 100 { |
118 for (size_t j = 0; j < chains_[i].size(); j++) | 101 for (size_t j = 0; j < items_[i].chain_.size(); j++) |
119 { | 102 { |
120 const ScenePoint2D& p = chains_[i][j]; | 103 const ScenePoint2D& p = items_[i].chain_[j]; |
121 target.AddPoint(p.GetX(), p.GetY()); | 104 target.AddPoint(p.GetX(), p.GetY()); |
122 } | 105 } |
123 } | 106 } |
124 | 107 |
125 return true; | 108 return true; |