|
@@ -1,7 +1,7 @@
|
|
|
/*=========================================================================
|
|
|
|
|
|
Library: CTK
|
|
|
-
|
|
|
+
|
|
|
Copyright (c) 2010 Kitware Inc.
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -15,7 +15,7 @@
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
See the License for the specific language governing permissions and
|
|
|
limitations under the License.
|
|
|
-
|
|
|
+
|
|
|
=========================================================================*/
|
|
|
|
|
|
/// Qt includes
|
|
@@ -39,14 +39,17 @@ class ctkTransferFunctionBarsItemPrivate: public ctkPrivate<ctkTransferFunctionB
|
|
|
{
|
|
|
public:
|
|
|
ctkTransferFunctionBarsItemPrivate();
|
|
|
- qreal BarWidth;
|
|
|
- bool Log;
|
|
|
+ qreal BarWidth;
|
|
|
+ QColor BarColor;
|
|
|
+ bool LogMode;
|
|
|
};
|
|
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
ctkTransferFunctionBarsItemPrivate::ctkTransferFunctionBarsItemPrivate()
|
|
|
{
|
|
|
this->BarWidth = 0.6180; // golden ratio... why not.
|
|
|
- this->Log = true;
|
|
|
+ this->BarColor = QColor(191, 191, 191, 127);
|
|
|
+ this->LogMode = ctkTransferFunctionBarsItem::AutoLog;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -66,13 +69,14 @@ ctkTransferFunctionBarsItem::ctkTransferFunctionBarsItem(
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
ctkTransferFunctionBarsItem::~ctkTransferFunctionBarsItem()
|
|
|
-{
|
|
|
+{
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void ctkTransferFunctionBarsItem::setBarWidth(qreal newBarWidth)
|
|
|
{
|
|
|
CTK_D(ctkTransferFunctionBarsItem);
|
|
|
+ newBarWidth = qBound(0., newBarWidth, 1.);
|
|
|
if (d->BarWidth == newBarWidth)
|
|
|
{
|
|
|
return;
|
|
@@ -89,6 +93,20 @@ qreal ctkTransferFunctionBarsItem::barWidth()const
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
+void ctkTransferFunctionBarsItem::setBarColor(const QColor& color)
|
|
|
+{
|
|
|
+ CTK_D(ctkTransferFunctionBarsItem);
|
|
|
+ d->BarColor = color;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+QColor ctkTransferFunctionBarsItem::barColor()const
|
|
|
+{
|
|
|
+ CTK_D(const ctkTransferFunctionBarsItem);
|
|
|
+ return d->BarColor;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
void ctkTransferFunctionBarsItem::paint(
|
|
|
QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
|
|
|
{
|
|
@@ -106,16 +124,33 @@ void ctkTransferFunctionBarsItem::paint(
|
|
|
const QList<QPointF>& points = tfScene->points();
|
|
|
|
|
|
QPainterPath bars;
|
|
|
- QPen pen(QColor(255, 255, 255, 191), 1);
|
|
|
+ QPen pen( QColor(255, 255, 255, 191), 1);
|
|
|
pen.setCosmetic(true);
|
|
|
+ if (qFuzzyCompare(d->BarWidth, 1.))
|
|
|
+ {
|
|
|
+ pen = QPen(QBrush(), 0, Qt::NoPen);
|
|
|
+ }
|
|
|
painter->setPen(pen);
|
|
|
- painter->setBrush(QBrush(QColor(191, 191, 191, 127)));
|
|
|
+ painter->setBrush(QBrush(d->BarColor));
|
|
|
|
|
|
- qreal barWidth = d->BarWidth * (this->rect().width() / (points.size() - 1));
|
|
|
+ qreal barWidth = d->BarWidth * (this->rect().width() / (points.size() - 1));
|
|
|
+ bool useLog = false;
|
|
|
+ switch (d->LogMode)
|
|
|
+ {
|
|
|
+ case ctkTransferFunctionBarsItem::AutoLog:
|
|
|
+ useLog = this->transferFunction()->maxValue().toReal() - this->transferFunction()->minValue().toReal() > 1000.;
|
|
|
+ break;
|
|
|
+ case ctkTransferFunctionBarsItem::UseLog:
|
|
|
+ useLog = true;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ case ctkTransferFunctionBarsItem::NoLog:
|
|
|
+ useLog = false;
|
|
|
+ }
|
|
|
foreach(const QPointF& point, points)
|
|
|
{
|
|
|
qreal barHeight = point.y();
|
|
|
- if (d->Log && barHeight != 1.)
|
|
|
+ if (useLog && barHeight != 1.)
|
|
|
{
|
|
|
barHeight = this->rect().height() - log( tfScene->mapYFromScene(barHeight) )/log(this->transferFunction()->maxValue().toReal());// 1. - (-log(barHeight)/100.);
|
|
|
}
|