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->setFocusPolicy(Qt::StrongFocus);
81 "<h3>Color Transfer Function</h3>"
82 "<p>Let you set the color part of a transfer function.</p>"
89 this->setMouseTracking(
true);
94 this->setMouseTracking(
false);
115 QWidget::mousePressEvent(event);
118 if(event->button() == Qt::LeftButton)
127 QWidget::mouseReleaseEvent(event);
134 QWidget::mouseMoveEvent(event);
136 if(event->buttons() == Qt::LeftButton)
160 this->setToolTip(tip);
171 if (event->key()==Qt::Key_Left)
173 if (event->key()==Qt::Key_Right)
186 QWidget::keyPressEvent(event);
194 (intensity -
mImage->getMin()) /
195 static_cast<double>(
mImage->getRange()));
203 int retval = int(i+0.5);
212 QWidget::paintEvent(event);
214 QPainter painter(
this);
217 painter.fillRect(this->
mFullArea, QColor(170, 170, 170));
218 painter.fillRect(this->
mPlotArea, QColor(200, 200, 200));
236 double* rgb = trFunc->GetColor(intensity);
237 painter.setPen(QColor::fromRgbF(rgb[0], rgb[1], rgb[2]));
239 if (( imin <= intensity )&&( intensity <= imax ))
246 int halfAreaTop =
mPlotArea.top() + areaHeight / 4;
247 int halfAreaBottom =
mPlotArea.bottom() - areaHeight / 4;
248 painter.drawLine(x, halfAreaTop, x, halfAreaBottom);
258 for (ColorMap::iterator colorPoint = colorMap.begin(); colorPoint != colorMap.end(); ++colorPoint)
278 painter.drawRect(pointRect);
285 QWidget::resizeEvent(evt);
288 this->
mFullArea = QRect(0, 0, width(), height());
295 std::map<int, QRect>::const_iterator it =
mPointRects.begin();
298 if (it->second.contains(pos))
303 if (colorMap.find(retval.
intensity) != colorMap.end())
334 menu.exec(event->globalPos());
350 double* rgb = trFunc->GetColor(point.
intensity);
351 point.
value = QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
395 ColorMap::iterator pointIterator = colorMap.find(selectedPointIntensity);
397 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
398 if (pointIterator!=colorMap.begin())
400 ColorMap::iterator prevPointIterator = pointIterator;
402 range.first = std::max(range.first, prevPointIterator->first + 1);
405 ColorMap::iterator nextPointIterator = pointIterator;
407 if (nextPointIterator!=colorMap.end())
409 range.second = std::min(range.second, nextPointIterator->first - 1);
427 QColor result = QColorDialog::getColor( newPoint.
value,
this);
429 if (result.isValid() && (result!=newPoint.
value))
std::map< int, QColor > ColorMap
QString color2string(QColor color)
boost::shared_ptr< class Image > ImagePtr
vtkSmartPointer< class vtkColorTransferFunction > vtkColorTransferFunctionPtr
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