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->setToolTip(
"Set the alpha part of a transfer function");
61 this->setFocusPolicy(Qt::StrongFocus);
93 this->setMouseTracking(
true);
98 this->setMouseTracking(
false);
105 QWidget::mousePressEvent(event);
107 if(event->button() == Qt::LeftButton)
111 else if(event->button() == Qt::RightButton)
123 QWidget::mouseReleaseEvent(event);
136 QWidget::mouseMoveEvent(event);
138 if(event->buttons() == Qt::LeftButton)
151 if (event->key()==Qt::Key_Left)
153 if (event->key()==Qt::Key_Right)
155 if (event->key()==Qt::Key_Down)
157 if (event->key()==Qt::Key_Up)
160 if ((shift!=0) || (alphaShift!=0))
164 newPoint.
value += alphaShift;
172 QWidget::keyPressEvent(event);
186 QString tip = QString(
"alpha(%1)=%2").arg(point.
position).arg(
double(point.
value)/255, 0,
'f', 2);
187 this->setToolTip(tip);
194 QWidget::paintEvent(event);
195 QPainter painter(
this);
196 this->clearBackground(painter);
205 void TransferFunctionAlphaWidget::clearBackground(QPainter& painter)
208 const QBrush frameBrush = QBrush(QColor(170, 170, 170));
209 const QBrush backgroundBrush = QBrush(QColor(200, 200, 200));
210 painter.fillRect(this->
mFullArea, frameBrush);
211 painter.fillRect(this->
mPlotArea, backgroundBrush);
217 QPen pointPen, pointLinePen;
218 pointPen.setColor(QColor(0, 0, 150));
219 pointLinePen.setColor(QColor(150, 100, 100));
224 QPoint lastScreenPoint;
226 for (IntIntMap::iterator opPoint = opacityMap.begin();
227 opPoint != opacityMap.end();
231 AlphaPoint pt(opPoint->first, opPoint->second);
235 if (opPoint==opacityMap.begin())
237 lastScreenPoint = QPoint(
mPlotArea.left(), screenPoint.y());
241 painter.setPen(pointLinePen);
242 painter.drawLine(lastScreenPoint, screenPoint);
245 QRect pointRect(screenPoint.x() -
mBorder, screenPoint.y() -
mBorder,
249 pointPen.setWidth(2);
250 painter.setPen(pointPen);
254 pointPen.setWidth(1);
255 painter.setPen(pointPen);
257 painter.drawRect(pointRect);
261 lastScreenPoint = screenPoint;
265 QPoint screenPoint(
mPlotArea.right(), lastScreenPoint.y());
266 painter.setPen(pointLinePen);
267 painter.drawLine(lastScreenPoint, screenPoint);
273 QPoint screenPoint = QPoint(
276 static_cast<double>(
mImage->getRange())),
279 static_cast<double>(
mImage->getMaxAlphaValue())) );
289 int histogramSize = histogram->GetComponentExtent()[1] -
290 histogram->GetComponentExtent()[0];
292 painter.setPen(QColor(140, 140, 210));
296 double numElementsInBinWithMostElements = log(histogram->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]+1);
297 double barHeightMult = (this->height() -
mBorder*2) / numElementsInBinWithMostElements;
299 double posMult = (this->width() -
mBorder*2) /
double(histogramSize);
300 for (
int i =
mImage->getMin(); i <=
mImage->getMax(); i++)
302 x = ((i-
mImage->getMin()) * posMult);
303 y = log(
double(static_cast<int*>(histogram->GetOutput()->GetScalarPointer(i -
mImage->getMin(), 0, 0))[0]+1)) * barHeightMult;
315 QWidget::resizeEvent(evt);
318 this->
mFullArea = QRect(0, 0, width(), height());
325 std::map<int, QRect>::iterator it =
mPointRects.begin();
328 if (it->second.contains(pos))
333 if (opactiyMap.find(retval.
position) != opactiyMap.end())
357 point.
position = int(dposition+0.5);
358 point.
value = int(dvalue+0.5);
409 IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);
411 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
412 if (pointIterator!=opacityMap.begin())
414 IntIntMap::iterator prevPointIterator = pointIterator;
416 range.first = std::max(range.first, prevPointIterator->first + 1);
419 IntIntMap::iterator nextPointIterator = pointIterator;
421 if (nextPointIterator!=opacityMap.end())
423 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)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
std::map< int, int > IntIntMap
static ActiveImageProxyPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ImageTFData > ImageTFDataPtr