35 #include <vtkColorTransferFunction.h>
41 #include <QMouseEvent>
42 #include <QColorDialog>
57 BaseWidget(parent,
"TransferFunctionColorWidget",
"Color Transfer Function"),
58 mCurrentClickPos(INT_MIN,INT_MIN),
61 this->setToolTip(
"Set the color part of a transfer function");
62 this->setFocusPolicy(Qt::StrongFocus);
81 this->setMouseTracking(
true);
86 this->setMouseTracking(
false);
107 QWidget::mousePressEvent(event);
110 if(event->button() == Qt::LeftButton)
119 QWidget::mouseReleaseEvent(event);
126 QWidget::mouseMoveEvent(event);
128 if(event->buttons() == Qt::LeftButton)
152 this->setToolTip(tip);
163 if (event->key()==Qt::Key_Left)
165 if (event->key()==Qt::Key_Right)
178 QWidget::keyPressEvent(event);
186 (intensity -
mImage->getMin()) /
187 static_cast<double>(
mImage->getRange()));
195 int retval = int(i+0.5);
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());
342 double* rgb = trFunc->GetColor(point.
intensity);
343 point.
value = QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
387 ColorMap::iterator pointIterator = colorMap.find(selectedPointIntensity);
389 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
390 if (pointIterator!=colorMap.begin())
392 ColorMap::iterator prevPointIterator = pointIterator;
394 range.first = std::max(range.first, prevPointIterator->first + 1);
397 ColorMap::iterator nextPointIterator = pointIterator;
399 if (nextPointIterator!=colorMap.end())
401 range.second = std::min(range.second, nextPointIterator->first - 1);
419 QColor result = QColorDialog::getColor( newPoint.
value,
this);
421 if (result.isValid() && (result!=newPoint.
value))
QString color2string(QColor color)
boost::shared_ptr< class Image > ImagePtr
vtkSmartPointer< class vtkColorTransferFunction > vtkColorTransferFunctionPtr
std::map< int, QColor > ColorMap
double constrainValue(double val, double min, double max)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static ActiveImageProxyPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ImageTFData > ImageTFDataPtr