Mercurial > hg > orthanc-stone
diff 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 |
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2D/PolylineSceneLayer.cpp Sun Oct 30 10:26:32 2022 +0100 +++ b/OrthancStone/Sources/Scene2D/PolylineSceneLayer.cpp Mon Oct 31 08:22:31 2022 +0100 @@ -25,6 +25,10 @@ #include <OrthancException.h> +#include <boost/math/constants/constants.hpp> + +static const double PI = boost::math::constants::pi<double>(); + namespace OrthancStone { void PolylineSceneLayer::Copy(const PolylineSceneLayer& other) @@ -107,4 +111,75 @@ } } } + + + void PolylineSceneLayer::AddArc(double centerX, + double centerY, + double radiusX, + double radiusY, + double startAngle, + double endAngle, + Color color, + unsigned int countSegments) + { + assert(countSegments != 0); + + if (endAngle >= startAngle) + { + double increment = (endAngle - startAngle) / static_cast<double>(countSegments - 1); + + Chain chain; + chain.resize(countSegments); + + double theta = startAngle; + for (unsigned int i = 0; i < countSegments; i++) + { + chain[i] = ScenePoint2D(centerX + radiusX * cos(theta), + centerY + radiusY * sin(theta)); + theta += increment; + } + + AddChain(chain, false, color); + } + } + + + void PolylineSceneLayer::AddCircle(double centerX, + double centerY, + double radius, + Color color, + unsigned int countSegments) + { + AddArc(centerX, centerY, radius, radius, 0, 2.0 * PI, color, countSegments); + } + + + void PolylineSceneLayer::AddRectangle(double x1, + double y1, + double x2, + double y2, + Color color) + { + Chain chain; + chain.resize(4); + chain[0] = ScenePoint2D(x1, y1); + chain[1] = ScenePoint2D(x2, y1); + chain[2] = ScenePoint2D(x2, y2); + chain[3] = ScenePoint2D(x1, y2); + AddChain(chain, true, color); + } + + + void PolylineSceneLayer::AddSegment(double x1, + double y1, + double x2, + double y2, + Color color) + { + Chain chain; + chain.resize(2); + chain[0] = ScenePoint2D(x1, y1); + chain[1] = ScenePoint2D(x2, y2); + AddChain(chain, false, color); + } }