MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / getCurrentPath

Method getCurrentPath

ASAP/annotation/PolyQtAnnotation.cpp:81–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81QPainterPath PolyQtAnnotation::getCurrentPath(const std::vector<Point>& coords) const {
82 QPainterPath pth;
83 pth.moveTo(0, 0);
84 if (coords.size() > 1) {
85 for (unsigned int i = 0; i < coords.size() - 1; ++i) {
86 if (_type != "spline") {
87 pth.lineTo(this->mapFromScene(coords[i + 1].getX()*_scale, coords[i + 1].getY()*_scale));
88 }
89 else {
90 QPointF p1 = this->mapFromScene(coords[i].getX()*_scale, coords[i].getY()*_scale);
91 QPointF p2 = this->mapFromScene(coords[i + 1].getX()*_scale, coords[i + 1].getY()*_scale);
92 QPointF p0 = p1 - (p2 - p1);
93 if (i > 0) {
94 p0 = this->mapFromScene(coords[i - 1].getX()*_scale, coords[i - 1].getY()*_scale);
95 }
96 else if (i == 0 && _closed && coords.size() > 2) {
97 p0 = this->mapFromScene(coords[coords.size() - 1].getX()*_scale, coords[coords.size() - 1].getY()*_scale);
98 }
99 QPointF p3 = p2 + (p2 - p1);
100 if (i < coords.size() - 2) {
101 p3 = this->mapFromScene(coords[i + 2].getX()*_scale, coords[i + 2].getY()*_scale);
102 }
103 std::vector<QPointF> bezierPoints = catmullRomToBezier(p0, p1, p2, p3);
104 pth.cubicTo(bezierPoints[1], bezierPoints[2], bezierPoints[3]);
105 }
106 }
107 if (_closed) {
108 if (_type != "spline") {
109 pth.lineTo(0, 0);
110 }
111 else {
112 if (coords.size() > 1) {
113 QPointF p1 = this->mapFromScene(coords[coords.size() - 1].getX()*_scale, coords[coords.size() - 1].getY()*_scale);
114 QPointF p2 = this->mapFromScene(coords[0].getX()*_scale, coords[0].getY()*_scale);
115 QPointF p0 = p1 - (p2 - p1);
116 if (coords.size() > 2) {
117 QPointF p0 = this->mapFromScene(coords[coords.size() - 2].getX()*_scale, coords[coords.size() - 2].getY()*_scale);
118 }
119 QPointF p3 = this->mapFromScene(coords[1].getX()*_scale, coords[1].getY()*_scale);
120 std::vector<QPointF> bezierPoints = catmullRomToBezier(p0, p1, p2, p3);
121 pth.cubicTo(bezierPoints[1], bezierPoints[2], bezierPoints[3]);
122 }
123 }
124 }
125 }
126 return pth;
127}
128
129void PolyQtAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
130 QWidget *widget) {

Callers

nothing calls this directly

Calls 2

moveToMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected