35 #include <vtkColorTransferFunction.h>
41 #include <QMouseEvent>
42 #include <QColorDialog>
58 BaseWidget(parent,
"TransferFunctionColorWidget",
"Color Transfer Function"),
59 mCurrentClickPos(INT_MIN,INT_MIN),
62 this->setToolTip(
"Set the color part of a transfer function");
63 this->setFocusPolicy(Qt::StrongFocus);
82 this->setMouseTracking(
true);
87 this->setMouseTracking(
false);
108 QWidget::mousePressEvent(event);
111 if(event->button() == Qt::LeftButton)
120 QWidget::mouseReleaseEvent(event);
127 QWidget::mouseMoveEvent(event);
129 if(event->buttons() == Qt::LeftButton)
153 this->setToolTip(tip);
164 if (event->key()==Qt::Key_Left)
166 if (event->key()==Qt::Key_Right)
179 QWidget::keyPressEvent(event);
187 (intensity -
mImage->getMin()) /
188 static_cast<double>(
mImage->getRange()));
204 QWidget::paintEvent(event);
206 QPainter painter(
this);
209 painter.fillRect(this->
mFullArea, QColor(170, 170, 170));
210 painter.fillRect(this->
mPlotArea, QColor(200, 200, 200));
228 double* rgb = trFunc->GetColor(intensity);
229 painter.setPen(QColor::fromRgbF(rgb[0], rgb[1], rgb[2]));
231 if (( imin <= intensity )&&( intensity <= imax ))
238 int halfAreaTop =
mPlotArea.top() + areaHeight / 4;
239 int halfAreaBottom =
mPlotArea.bottom() - areaHeight / 4;
240 painter.drawLine(x, halfAreaTop, x, halfAreaBottom);
250 for (ColorMap::iterator colorPoint = colorMap.begin(); colorPoint != colorMap.end(); ++colorPoint)
270 painter.drawRect(pointRect);
277 QWidget::resizeEvent(evt);
280 this->
mFullArea = QRect(0, 0, width(), height());
287 std::map<int, QRect>::const_iterator it =
mPointRects.begin();
290 if (it->second.contains(pos))
295 if (colorMap.find(retval.
intensity) != colorMap.end())
326 menu.exec(event->globalPos());
344 double* rgb = trFunc->GetColor(point.
intensity);
345 point.
value = QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
389 ColorMap::iterator pointIterator = colorMap.find(selectedPointIntensity);
391 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
392 if (pointIterator!=colorMap.begin())
394 ColorMap::iterator prevPointIterator = pointIterator;
396 range.first = std::max(range.first, prevPointIterator->first + 1);
399 ColorMap::iterator nextPointIterator = pointIterator;
401 if (nextPointIterator!=colorMap.end())
403 range.second = std::min(range.second, nextPointIterator->first - 1);
421 QColor result = QColorDialog::getColor( newPoint.
value,
this);
423 if (result.isValid() && (result!=newPoint.
value))
QString color2string(QColor color)
boost::shared_ptr< class Image > ImagePtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
double roundAwayFromZero(double val)
vtkSmartPointer< class vtkColorTransferFunction > vtkColorTransferFunctionPtr
std::map< int, QColor > ColorMap
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
double constrainValue(double val, double min, double max)
boost::shared_ptr< class ImageTFData > ImageTFDataPtr