15 #include <vtkImageData.h> 16 #include <vtkPointData.h> 17 #include <vtkImageAccumulate.h> 22 #include <QMouseEvent> 28 #include "vtkDataArray.h" 34 BaseWidget(parent,
"transfer_function_alpha_widget",
"Alpha Transfer Function"),
38 this->setToolTip(
"Set the alpha part of a transfer function");
39 this->setFocusPolicy(Qt::StrongFocus);
71 this->setMouseTracking(
true);
76 this->setMouseTracking(
false);
83 QWidget::mousePressEvent(event);
85 if(event->button() == Qt::LeftButton)
89 else if(event->button() == Qt::RightButton)
101 QWidget::mouseReleaseEvent(event);
114 QWidget::mouseMoveEvent(event);
116 if(event->buttons() == Qt::LeftButton)
129 if (event->key()==Qt::Key_Left)
131 if (event->key()==Qt::Key_Right)
133 if (event->key()==Qt::Key_Down)
135 if (event->key()==Qt::Key_Up)
138 if ((shift!=0) || (alphaShift!=0))
142 newPoint.
value += alphaShift;
150 QWidget::keyPressEvent(event);
164 QString tip = QString(
"alpha(%1)=%2").arg(point.
position).arg(
double(point.
value)/255, 0,
'f', 2);
165 this->setToolTip(tip);
172 QWidget::paintEvent(event);
173 QPainter painter(
this);
174 this->clearBackground(painter);
183 void TransferFunctionAlphaWidget::clearBackground(QPainter& painter)
186 const QBrush frameBrush = QBrush(QColor(170, 170, 170));
187 const QBrush backgroundBrush = QBrush(QColor(200, 200, 200));
188 painter.fillRect(this->
mFullArea, frameBrush);
189 painter.fillRect(this->
mPlotArea, backgroundBrush);
195 QPen pointPen, pointLinePen;
196 pointPen.setColor(QColor(0, 0, 150));
197 pointLinePen.setColor(QColor(150, 100, 100));
202 QPoint lastScreenPoint;
204 for (IntIntMap::iterator opPoint = opacityMap.begin();
205 opPoint != opacityMap.end();
209 AlphaPoint pt(opPoint->first, opPoint->second);
213 if (opPoint==opacityMap.begin())
215 lastScreenPoint = QPoint(
mPlotArea.left(), screenPoint.y());
219 painter.setPen(pointLinePen);
220 painter.drawLine(lastScreenPoint, screenPoint);
223 QRect pointRect(screenPoint.x() -
mBorder, screenPoint.y() -
mBorder,
227 pointPen.setWidth(2);
228 painter.setPen(pointPen);
232 pointPen.setWidth(1);
233 painter.setPen(pointPen);
235 painter.drawRect(pointRect);
239 lastScreenPoint = screenPoint;
243 QPoint screenPoint(
mPlotArea.right(), lastScreenPoint.y());
244 painter.setPen(pointLinePen);
245 painter.drawLine(lastScreenPoint, screenPoint);
251 QPoint screenPoint = QPoint(
254 static_cast<double>(
mImage->getRange())),
257 static_cast<double>(
mImage->getMaxAlphaValue())) );
267 int histogramSize = histogram->GetComponentExtent()[1] -
268 histogram->GetComponentExtent()[0];
270 painter.setPen(QColor(140, 140, 210));
272 double numElementsInBinWithMostElements = log(histogram->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]+1);
273 double barHeightMult = (this->height() -
mBorder*2) / numElementsInBinWithMostElements;
275 double posMult = (this->width() -
mBorder*2) /
double(histogramSize);
276 for (
int i =
mImage->getMin(); i <=
mImage->getMax(); i++)
278 int x = int(std::lround(((i-
mImage->getMin()) * posMult)));
279 int y = int(std::lround(log(
double(static_cast<int*>(histogram->GetOutput()->GetScalarPointer(i -
mImage->getMin(), 0, 0))[0]+1)) * barHeightMult));
291 QWidget::resizeEvent(evt);
294 this->
mFullArea = QRect(0, 0, width(), height());
301 std::map<int, QRect>::iterator it =
mPointRects.begin();
304 if (it->second.contains(pos))
309 if (opactiyMap.find(retval.
position) != opactiyMap.end())
333 point.
position = int(std::lround(dposition));
334 point.
value = int(std::lround(dvalue));
385 IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);
387 std::pair<int,int> range(
mImage->getMin(),
mImage->getMax());
388 if (pointIterator!=opacityMap.begin())
390 IntIntMap::iterator prevPointIterator = pointIterator;
392 range.first = std::max(range.first, prevPointIterator->first + 1);
395 IntIntMap::iterator nextPointIterator = pointIterator;
397 if (nextPointIterator!=opacityMap.end())
399 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
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.