15 #include <vtkImageData.h> 16 #include <vtkPointData.h> 17 #include <vtkImageAccumulate.h> 22 #include <QMouseEvent> 28 #include "vtkDataArray.h" 36 BaseWidget(parent,
"transfer_function_alpha_widget",
"Alpha Transfer Function"),
40 this->setToolTip(
"Set the alpha part of a transfer function");
41 this->setFocusPolicy(Qt::StrongFocus);
73 this->setMouseTracking(
true);
78 this->setMouseTracking(
false);
85 QWidget::mousePressEvent(event);
87 if(event->button() == Qt::LeftButton)
91 else if(event->button() == Qt::RightButton)
103 QWidget::mouseReleaseEvent(event);
116 QWidget::mouseMoveEvent(event);
118 if(event->buttons() == Qt::LeftButton)
131 if (event->key()==Qt::Key_Left)
133 if (event->key()==Qt::Key_Right)
135 if (event->key()==Qt::Key_Down)
137 if (event->key()==Qt::Key_Up)
140 if ((shift!=0) || (alphaShift!=0))
144 newPoint.
value += alphaShift;
152 QWidget::keyPressEvent(event);
166 QString tip = QString(
"alpha(%1)=%2").arg(point.
position).arg(
double(point.
value)/255, 0,
'f', 2);
167 this->setToolTip(tip);
174 QWidget::paintEvent(event);
175 QPainter painter(
this);
176 this->clearBackground(painter);
185 void TransferFunctionAlphaWidget::clearBackground(QPainter& painter)
188 const QBrush frameBrush = QBrush(QColor(170, 170, 170));
189 const QBrush backgroundBrush = QBrush(QColor(200, 200, 200));
190 painter.fillRect(this->
mFullArea, frameBrush);
191 painter.fillRect(this->
mPlotArea, backgroundBrush);
197 QPen pointPen, pointLinePen;
198 pointPen.setColor(QColor(0, 0, 150));
199 pointLinePen.setColor(QColor(150, 100, 100));
204 QPoint lastScreenPoint;
206 for (IntIntMap::iterator opPoint = opacityMap.begin();
207 opPoint != opacityMap.end();
211 AlphaPoint pt(opPoint->first, opPoint->second);
215 if (opPoint==opacityMap.begin())
217 lastScreenPoint = QPoint(
mPlotArea.left(), screenPoint.y());
221 painter.setPen(pointLinePen);
222 painter.drawLine(lastScreenPoint, screenPoint);
225 QRect pointRect(screenPoint.x() -
mBorder, screenPoint.y() -
mBorder,
229 pointPen.setWidth(2);
230 painter.setPen(pointPen);
234 pointPen.setWidth(1);
235 painter.setPen(pointPen);
237 painter.drawRect(pointRect);
241 lastScreenPoint = screenPoint;
245 QPoint screenPoint(
mPlotArea.right(), lastScreenPoint.y());
246 painter.setPen(pointLinePen);
247 painter.drawLine(lastScreenPoint, screenPoint);
253 QPoint screenPoint = QPoint(
256 static_cast<double>(
mImage->getRange())),
259 static_cast<double>(
mImage->getMaxAlphaValue())) );
269 int histogramSize = histogram->GetComponentExtent()[1] -
270 histogram->GetComponentExtent()[0];
272 painter.setPen(QColor(140, 140, 210));
274 double numElementsInBinWithMostElements = log(histogram->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]+1);
275 double barHeightMult = (this->height() -
mBorder*2) / numElementsInBinWithMostElements;
277 double posMult = (this->width() -
mBorder*2) /
double(histogramSize);
278 for (
int i =
mImage->getMin(); i <=
mImage->getMax(); i++)
280 int x = ((i-
mImage->getMin()) * posMult);
281 int y = log(
double(static_cast<int*>(histogram->GetOutput()->GetScalarPointer(i -
mImage->getMin(), 0, 0))[0]+1)) * barHeightMult;
293 QWidget::resizeEvent(evt);
296 this->
mFullArea = QRect(0, 0, width(), height());
303 std::map<int, QRect>::iterator it =
mPointRects.begin();
306 if (it->second.contains(pos))
311 if (opactiyMap.find(retval.
position) != opactiyMap.end())
387 IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);
389 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
390 if (pointIterator!=opacityMap.begin())
392 IntIntMap::iterator prevPointIterator = pointIterator;
394 range.first = std::max(range.first, prevPointIterator->first + 1);
397 IntIntMap::iterator nextPointIterator = pointIterator;
399 if (nextPointIterator!=opacityMap.end())
401 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
Namespace for all CustusX production code.