Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2D/PolylineSceneLayer.cpp @ 1981:c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 31 Oct 2022 08:22:31 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
comparison
equal
deleted
inserted
replaced
1980:0aac8f552d89 | 1981:c074c75cf416 |
---|---|
22 | 22 |
23 | 23 |
24 #include "PolylineSceneLayer.h" | 24 #include "PolylineSceneLayer.h" |
25 | 25 |
26 #include <OrthancException.h> | 26 #include <OrthancException.h> |
27 | |
28 #include <boost/math/constants/constants.hpp> | |
29 | |
30 static const double PI = boost::math::constants::pi<double>(); | |
27 | 31 |
28 namespace OrthancStone | 32 namespace OrthancStone |
29 { | 33 { |
30 void PolylineSceneLayer::Copy(const PolylineSceneLayer& other) | 34 void PolylineSceneLayer::Copy(const PolylineSceneLayer& other) |
31 { | 35 { |
105 const ScenePoint2D& p = items_[i].chain_[j]; | 109 const ScenePoint2D& p = items_[i].chain_[j]; |
106 target.AddPoint(p.GetX(), p.GetY()); | 110 target.AddPoint(p.GetX(), p.GetY()); |
107 } | 111 } |
108 } | 112 } |
109 } | 113 } |
114 | |
115 | |
116 void PolylineSceneLayer::AddArc(double centerX, | |
117 double centerY, | |
118 double radiusX, | |
119 double radiusY, | |
120 double startAngle, | |
121 double endAngle, | |
122 Color color, | |
123 unsigned int countSegments) | |
124 { | |
125 assert(countSegments != 0); | |
126 | |
127 if (endAngle >= startAngle) | |
128 { | |
129 double increment = (endAngle - startAngle) / static_cast<double>(countSegments - 1); | |
130 | |
131 Chain chain; | |
132 chain.resize(countSegments); | |
133 | |
134 double theta = startAngle; | |
135 for (unsigned int i = 0; i < countSegments; i++) | |
136 { | |
137 chain[i] = ScenePoint2D(centerX + radiusX * cos(theta), | |
138 centerY + radiusY * sin(theta)); | |
139 theta += increment; | |
140 } | |
141 | |
142 AddChain(chain, false, color); | |
143 } | |
144 } | |
145 | |
146 | |
147 void PolylineSceneLayer::AddCircle(double centerX, | |
148 double centerY, | |
149 double radius, | |
150 Color color, | |
151 unsigned int countSegments) | |
152 { | |
153 AddArc(centerX, centerY, radius, radius, 0, 2.0 * PI, color, countSegments); | |
154 } | |
155 | |
156 | |
157 void PolylineSceneLayer::AddRectangle(double x1, | |
158 double y1, | |
159 double x2, | |
160 double y2, | |
161 Color color) | |
162 { | |
163 Chain chain; | |
164 chain.resize(4); | |
165 chain[0] = ScenePoint2D(x1, y1); | |
166 chain[1] = ScenePoint2D(x2, y1); | |
167 chain[2] = ScenePoint2D(x2, y2); | |
168 chain[3] = ScenePoint2D(x1, y2); | |
169 AddChain(chain, true, color); | |
170 } | |
171 | |
172 | |
173 void PolylineSceneLayer::AddSegment(double x1, | |
174 double y1, | |
175 double x2, | |
176 double y2, | |
177 Color color) | |
178 { | |
179 Chain chain; | |
180 chain.resize(2); | |
181 chain[0] = ScenePoint2D(x1, y1); | |
182 chain[1] = ScenePoint2D(x2, y2); | |
183 AddChain(chain, false, color); | |
184 } | |
110 } | 185 } |