14 #include <vtkColorTransferFunction.h>
20 #include <QMouseEvent>
21 #include <QColorDialog>
35 BaseWidget(parent,
"transfer_function_color_widget",
"Color Transfer Function"),
37 mCurrentClickPos(INT_MIN,INT_MIN)
39 this->setToolTip(
"Set the color part of a transfer function");
40 this->setFocusPolicy(Qt::StrongFocus);
59 this->setMouseTracking(
true);
64 this->setMouseTracking(
false);
85 QWidget::mousePressEvent(event);
88 if(event->button() == Qt::LeftButton)
97 QWidget::mouseReleaseEvent(event);
104 QWidget::mouseMoveEvent(event);
106 if(event->buttons() == Qt::LeftButton)
130 this->setToolTip(tip);
141 if (event->key()==Qt::Key_Left)
143 if (event->key()==Qt::Key_Right)
156 QWidget::keyPressEvent(event);
164 (intensity -
mImage->getMin()) /
165 static_cast<double>(
mImage->getRange()));
172 int retval = int(std::lround(i));
181 QWidget::paintEvent(event);
183 QPainter painter(
this);
186 painter.fillRect(this->
mFullArea, QColor(170, 170, 170));
187 painter.fillRect(this->
mPlotArea, QColor(200, 200, 200));
205 double* rgb = trFunc->GetColor(intensity);
206 painter.setPen(QColor::fromRgbF(rgb[0], rgb[1], rgb[2]));
208 if (( imin <= intensity )&&( intensity <= imax ))
215 int halfAreaTop =
mPlotArea.top() + areaHeight / 4;
216 int halfAreaBottom =
mPlotArea.bottom() - areaHeight / 4;
217 painter.drawLine(x, halfAreaTop, x, halfAreaBottom);
227 for (ColorMap::iterator colorPoint = colorMap.begin(); colorPoint != colorMap.end(); ++colorPoint)
247 painter.drawRect(pointRect);
254 QWidget::resizeEvent(evt);
257 this->
mFullArea = QRect(0, 0, width(), height());
264 std::map<int, QRect>::const_iterator it =
mPointRects.begin();
267 if (it->second.contains(pos))
272 if (colorMap.find(retval.
intensity) != colorMap.end())
303 menu.exec(event->globalPos());
321 double* rgb = trFunc->GetColor(point.
intensity);
322 point.
value = QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
366 ColorMap::iterator pointIterator = colorMap.find(selectedPointIntensity);
368 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
369 if (pointIterator!=colorMap.begin())
371 ColorMap::iterator prevPointIterator = pointIterator;
373 range.first = std::max(range.first, prevPointIterator->first + 1);
376 ColorMap::iterator nextPointIterator = pointIterator;
378 if (nextPointIterator!=colorMap.end())
380 range.second = std::min(range.second, nextPointIterator->first - 1);
398 QColor result = QColorDialog::getColor( newPoint.
value,
this);
400 if (result.isValid() && (result!=newPoint.
value))