36 #include <vtkImageData.h>
37 #include <vtkPointData.h>
38 #include <vtkImageAccumulate.h>
43 #include <QMouseEvent>
49 #include "vtkDataArray.h"
56 BaseWidget(parent,
"TransferFunctionAlphaWidget",
"Alpha Transfer Function"),
60 this->setFocusPolicy(Qt::StrongFocus);
73 "<h3>Alpha Transfer Function.</h3>"
74 "<p>Lets you set the alpha part of a transfer function.</p>"
101 this->setMouseTracking(
true);
106 this->setMouseTracking(
false);
113 QWidget::mousePressEvent(event);
115 if(event->button() == Qt::LeftButton)
119 else if(event->button() == Qt::RightButton)
131 QWidget::mouseReleaseEvent(event);
144 QWidget::mouseMoveEvent(event);
146 if(event->buttons() == Qt::LeftButton)
160 if (event->key()==Qt::Key_Left)
162 if (event->key()==Qt::Key_Right)
164 if (event->key()==Qt::Key_Down)
166 if (event->key()==Qt::Key_Up)
169 if ((shift!=0) || (alphaShift!=0))
173 newPoint.
value += alphaShift;
181 QWidget::keyPressEvent(event);
195 QString tip = QString(
"alpha(%1)=%2").arg(point.
position).arg(
double(point.
value)/255, 0,
'f', 2);
196 this->setToolTip(tip);
203 QWidget::paintEvent(event);
204 QPainter painter(
this);
205 this->clearBackground(painter);
214 void TransferFunctionAlphaWidget::clearBackground(QPainter& painter)
217 const QBrush frameBrush = QBrush(QColor(170, 170, 170));
218 const QBrush backgroundBrush = QBrush(QColor(200, 200, 200));
219 painter.fillRect(this->
mFullArea, frameBrush);
220 painter.fillRect(this->
mPlotArea, backgroundBrush);
226 QPen pointPen, pointLinePen;
227 pointPen.setColor(QColor(0, 0, 150));
228 pointLinePen.setColor(QColor(150, 100, 100));
233 QPoint lastScreenPoint;
235 for (IntIntMap::iterator opPoint = opacityMap.begin();
236 opPoint != opacityMap.end();
240 AlphaPoint pt(opPoint->first, opPoint->second);
244 if (opPoint==opacityMap.begin())
246 lastScreenPoint = QPoint(
mPlotArea.left(), screenPoint.y());
250 painter.setPen(pointLinePen);
251 painter.drawLine(lastScreenPoint, screenPoint);
254 QRect pointRect(screenPoint.x() -
mBorder, screenPoint.y() -
mBorder,
258 pointPen.setWidth(2);
259 painter.setPen(pointPen);
263 pointPen.setWidth(1);
264 painter.setPen(pointPen);
266 painter.drawRect(pointRect);
270 lastScreenPoint = screenPoint;
274 QPoint screenPoint(
mPlotArea.right(), lastScreenPoint.y());
275 painter.setPen(pointLinePen);
276 painter.drawLine(lastScreenPoint, screenPoint);
282 QPoint screenPoint = QPoint(
285 static_cast<double>(
mImage->getRange())),
288 static_cast<double>(
mImage->getMaxAlphaValue())) );
298 int histogramSize = histogram->GetComponentExtent()[1] -
299 histogram->GetComponentExtent()[0];
301 painter.setPen(QColor(140, 140, 210));
305 double barHeightMult = (this->height() -
mBorder*2)
306 / log(histogram->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]+1);
308 double posMult = (this->width() -
mBorder*2) /
double(histogramSize);
309 for (
int i =
mImage->getMin(); i <=
mImage->getMax(); i++)
311 x = ((i-
mImage->getMin()) * posMult);
312 y = log(
double(static_cast<int*>(histogram->GetOutput()->GetScalarPointer())[i -
mImage->getMin()]+1)) * barHeightMult;
324 QWidget::resizeEvent(evt);
327 this->
mFullArea = QRect(0, 0, width(), height());
334 std::map<int, QRect>::iterator it =
mPointRects.begin();
337 if (it->second.contains(pos))
342 if (opactiyMap.find(retval.
position) != opactiyMap.end())
366 point.
position = int(dposition+0.5);
367 point.
value = int(dvalue+0.5);
418 IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);
420 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
421 if (pointIterator!=opacityMap.begin())
423 IntIntMap::iterator prevPointIterator = pointIterator;
425 range.first = std::max(range.first, prevPointIterator->first + 1);
428 IntIntMap::iterator nextPointIterator = pointIterator;
430 if (nextPointIterator!=opacityMap.end())
432 range.second = std::min(range.second, nextPointIterator->first - 1);
vtkSmartPointer< class vtkImageAccumulate > vtkImageAccumulatePtr
boost::shared_ptr< class Image > ImagePtr
double constrainValue(double val, double min, double max)
std::map< int, int > IntIntMap
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static ActiveImageProxyPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ImageTFData > ImageTFDataPtr