Skip to content

Commit f4eeecb

Browse files
committed
BUG: ctkTransferFunction was not handling functions not starting in 0.
1 parent 56ba0a8 commit f4eeecb

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

Diff for: Libs/Widgets/ctkTransferFunctionControlPointsItem.cpp

+32-11
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,38 @@ void ctkTransferFunctionControlPointsItem::paint(
9292
qreal rangeX[2];
9393
this->transferFunction()->range(rangeX);
9494
qreal rangeXDiff = this->rect().width() / (rangeX[1] - rangeX[0]);
95+
qreal rangeXOffSet = rangeX[0];
96+
9597
QVariant rangeY[2];
9698
rangeY[0] = this->transferFunction()->minValue();
9799
rangeY[1] = this->transferFunction()->maxValue();
98100
qreal rangeYDiff = this->rect().height();
101+
qreal rangeYOffSet;
99102
if (rangeY[0].canConvert<qreal>())
100103
{
101-
rangeYDiff /= rangeY[1].toReal() - rangeY[0].toReal();
104+
if (rangeY[1].toReal() == rangeY[0].toReal())
105+
{
106+
rangeYDiff /= rangeY[0].toReal();
107+
rangeYOffSet = 0.;
108+
}
109+
else
110+
{
111+
rangeYDiff /= rangeY[1].toReal() - rangeY[0].toReal();
112+
rangeYOffSet = rangeY[0].toReal();
113+
}
102114
}
103-
else if (rangeY[0].canConvert<qreal>())
115+
else if (rangeY[0].canConvert<QColor>())
104116
{
105-
rangeYDiff /= rangeY[1].value<QColor>().alphaF() - rangeY[0].value<QColor>().alphaF();
117+
if ( rangeY[1].value<QColor>().alphaF() == rangeY[0].value<QColor>().alphaF())
118+
{
119+
rangeYDiff /= rangeY[0].value<QColor>().alphaF();
120+
rangeYOffSet = 0.;
121+
}
122+
else
123+
{
124+
rangeYDiff /= rangeY[1].value<QColor>().alphaF() - rangeY[0].value<QColor>().alphaF();
125+
rangeYOffSet = rangeY[0].value<QColor>().alphaF();
126+
}
106127
}
107128
else
108129
{
@@ -116,7 +137,7 @@ void ctkTransferFunctionControlPointsItem::paint(
116137

117138
QPainterPath path;
118139

119-
QPointF startPos(startCP->x(), this->y(startCP->value()));
140+
QPointF startPos(startCP->x() - rangeXOffSet, this->y(startCP->value()) - rangeYOffSet);
120141
startPos.rx() *= rangeXDiff;
121142
startPos.setY(this->rect().height()
122143
- startPos.y() * rangeYDiff);
@@ -135,12 +156,12 @@ void ctkTransferFunctionControlPointsItem::paint(
135156
for (j = 1; j < points.count(); ++j)
136157
{
137158
path.lineTo(
138-
QPointF(points[j].X * rangeXDiff, this->rect().height() -
139-
this->y(points[j].Value) * rangeYDiff));
159+
QPointF((points[j].X - rangeXOffSet) * rangeXDiff, this->rect().height() -
160+
(this->y(points[j].Value) - rangeYOffSet) * rangeYDiff));
140161
}
141-
j = points.count() -1;
142-
d->ControlPoints << QPointF(points[j].X * rangeXDiff, this->rect().height() -
143-
this->y(points[j].Value) * rangeYDiff);
162+
j = points.count() - 1;
163+
d->ControlPoints << QPointF((points[j].X - rangeXOffSet) * rangeXDiff, this->rect().height() -
164+
(this->y(points[j].Value)- rangeYOffSet) * rangeYDiff );
144165
}
145166
else //dynamic_cast<ctkBezierControlPoint*>(startCP))
146167
{
@@ -150,8 +171,8 @@ void ctkTransferFunctionControlPointsItem::paint(
150171
foreach(const ctkPoint& p, points)
151172
{
152173
bezierPoints <<
153-
QPointF(p.X * rangeXDiff,
154-
this->rect().height() - this->y(p.Value) * rangeYDiff);
174+
QPointF((p.X - rangeXOffSet)* rangeXDiff ,
175+
this->rect().height() - (this->y(p.Value) - rangeYOffSet)* rangeYDiff);
155176
}
156177
path.cubicTo(bezierPoints[1], bezierPoints[2], bezierPoints[3]);
157178
d->ControlPoints << bezierPoints[3];

0 commit comments

Comments
 (0)