36 #include <vtkImageData.h>
37 #include <vtkPointData.h>
38 #include <vtkImageAccumulate.h>
43 #include <QMouseEvent>
49 #include "vtkDataArray.h"
57 BaseWidget(parent,
"TransferFunctionAlphaWidget",
"Alpha Transfer Function"),
61 this->setToolTip(
"Set the alpha part of a transfer function");
62 this->setFocusPolicy(Qt::StrongFocus);
94 this->setMouseTracking(
true);
99 this->setMouseTracking(
false);
106 QWidget::mousePressEvent(event);
108 if(event->button() == Qt::LeftButton)
112 else if(event->button() == Qt::RightButton)
124 QWidget::mouseReleaseEvent(event);
137 QWidget::mouseMoveEvent(event);
139 if(event->buttons() == Qt::LeftButton)
152 if (event->key()==Qt::Key_Left)
154 if (event->key()==Qt::Key_Right)
156 if (event->key()==Qt::Key_Down)
158 if (event->key()==Qt::Key_Up)
161 if ((shift!=0) || (alphaShift!=0))
165 newPoint.
value += alphaShift;
173 QWidget::keyPressEvent(event);
187 QString tip = QString(
"alpha(%1)=%2").arg(point.
position).arg(
double(point.
value)/255, 0,
'f', 2);
188 this->setToolTip(tip);
195 QWidget::paintEvent(event);
196 QPainter painter(
this);
197 this->clearBackground(painter);
206 void TransferFunctionAlphaWidget::clearBackground(QPainter& painter)
209 const QBrush frameBrush = QBrush(QColor(170, 170, 170));
210 const QBrush backgroundBrush = QBrush(QColor(200, 200, 200));
211 painter.fillRect(this->
mFullArea, frameBrush);
212 painter.fillRect(this->
mPlotArea, backgroundBrush);
218 QPen pointPen, pointLinePen;
219 pointPen.setColor(QColor(0, 0, 150));
220 pointLinePen.setColor(QColor(150, 100, 100));
225 QPoint lastScreenPoint;
227 for (IntIntMap::iterator opPoint = opacityMap.begin();
228 opPoint != opacityMap.end();
232 AlphaPoint pt(opPoint->first, opPoint->second);
236 if (opPoint==opacityMap.begin())
238 lastScreenPoint = QPoint(
mPlotArea.left(), screenPoint.y());
242 painter.setPen(pointLinePen);
243 painter.drawLine(lastScreenPoint, screenPoint);
246 QRect pointRect(screenPoint.x() -
mBorder, screenPoint.y() -
mBorder,
250 pointPen.setWidth(2);
251 painter.setPen(pointPen);
255 pointPen.setWidth(1);
256 painter.setPen(pointPen);
258 painter.drawRect(pointRect);
262 lastScreenPoint = screenPoint;
266 QPoint screenPoint(
mPlotArea.right(), lastScreenPoint.y());
267 painter.setPen(pointLinePen);
268 painter.drawLine(lastScreenPoint, screenPoint);
274 QPoint screenPoint = QPoint(
277 static_cast<double>(
mImage->getRange())),
280 static_cast<double>(
mImage->getMaxAlphaValue())) );
290 int histogramSize = histogram->GetComponentExtent()[1] -
291 histogram->GetComponentExtent()[0];
293 painter.setPen(QColor(140, 140, 210));
295 double numElementsInBinWithMostElements = log(histogram->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]+1);
296 double barHeightMult = (this->height() -
mBorder*2) / numElementsInBinWithMostElements;
298 double posMult = (this->width() -
mBorder*2) /
double(histogramSize);
299 for (
int i =
mImage->getMin(); i <=
mImage->getMax(); i++)
301 int x = ((i-
mImage->getMin()) * posMult);
302 int y = log(
double(static_cast<int*>(histogram->GetOutput()->GetScalarPointer(i -
mImage->getMin(), 0, 0))[0]+1)) * barHeightMult;
314 QWidget::resizeEvent(evt);
317 this->
mFullArea = QRect(0, 0, width(), height());
324 std::map<int, QRect>::iterator it =
mPointRects.begin();
327 if (it->second.contains(pos))
332 if (opactiyMap.find(retval.
position) != opactiyMap.end())
408 IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);
410 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
411 if (pointIterator!=opacityMap.begin())
413 IntIntMap::iterator prevPointIterator = pointIterator;
415 range.first = std::max(range.first, prevPointIterator->first + 1);
418 IntIntMap::iterator nextPointIterator = pointIterator;
420 if (nextPointIterator!=opacityMap.end())
422 range.second = std::min(range.second, nextPointIterator->first - 1);
vtkSmartPointer< class vtkImageAccumulate > vtkImageAccumulatePtr
boost::shared_ptr< class Image > ImagePtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
double roundAwayFromZero(double val)
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
double constrainValue(double val, double min, double max)
std::map< int, int > IntIntMap
boost::shared_ptr< class ImageTFData > ImageTFDataPtr