コード例 #1
0
void TransferFunctionAlphaWidget::paintOpacityGraph(QPainter& painter)
{
	QPen pointPen, pointLinePen;
	pointPen.setColor(QColor(0, 0, 150));
	pointLinePen.setColor(QColor(150, 100, 100));

	// Go through each point and draw squares and lines
	IntIntMap opacityMap = mImageTF->getOpacityMap();

	QPoint lastScreenPoint;
	this->mPointRects.clear();
	for (IntIntMap::iterator opPoint = opacityMap.begin();
		 opPoint != opacityMap.end();
		 ++opPoint)
	{
	  // Get the screen (plot) position of this point
		AlphaPoint pt(opPoint->first, opPoint->second);
		QPoint screenPoint = this->alpha2screen(pt);

		// draw line from left edge to first point:
		if (opPoint==opacityMap.begin())
		{
			lastScreenPoint = QPoint(mPlotArea.left(), screenPoint.y());
		}

	  // Draw line from previous point
		painter.setPen(pointLinePen);
		painter.drawLine(lastScreenPoint, screenPoint);

	  // Draw the rectangle
	  QRect pointRect(screenPoint.x() - mBorder, screenPoint.y() - mBorder,
					  mBorder*2, mBorder*2);
	  if (opPoint->first==mSelectedAlphaPoint.position)
	  {
		  pointPen.setWidth(2);
		  painter.setPen(pointPen);
	  }
	  else
	  {
		  pointPen.setWidth(1);
		  painter.setPen(pointPen);
	  }
	  painter.drawRect(pointRect);
	  this->mPointRects[opPoint->first] = pointRect;

	  // Store the point
	  lastScreenPoint = screenPoint;
	}

	// draw a line from the last point to the right end
	QPoint screenPoint(mPlotArea.right(), lastScreenPoint.y());
	painter.setPen(pointLinePen);
	painter.drawLine(lastScreenPoint, screenPoint);

}
コード例 #2
0
std::pair<int,int> TransferFunctionAlphaWidget::findAllowedMoveRangeAroundAlphaPoint(int selectedPointIntensity)
{
	// constrain new point intensity between the two neigbours
	IntIntMap opacityMap = mImageTF->getOpacityMap();
	IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);

	std::pair<int,int> range(mImage->getMin(), mImage->getMax());
	if (pointIterator!=opacityMap.begin())
	{
		IntIntMap::iterator prevPointIterator = pointIterator;
		--prevPointIterator;
		range.first = std::max(range.first, prevPointIterator->first + 1);
	}

	IntIntMap::iterator nextPointIterator = pointIterator;
	++nextPointIterator;
	if (nextPointIterator!=opacityMap.end())
	{
		range.second = std::min(range.second, nextPointIterator->first - 1);
	}

	return range;
}