Пример #1
0
void QSegmentWidget::DrawCylinder(const Cylinder &cyl,
  const SegmentList &s, const bool erase)
{
  if (!m_pixmap)
    InitPixmap();
  qreal border = 0;
  QPainter painter(m_pixmap);
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setRenderHint(QPainter::SmoothPixmapTransform);
  painter.setWindow( -(BM_OSIZE / 2), -(BM_OSIZE / 2),
    BM_OSIZE, BM_OSIZE);
  QRectF rco(-cyl.outerRadius, -cyl.outerRadius, (cyl.outerRadius * 2.0)+border,
      (cyl.outerRadius * 2.0)+border);
  QRectF rci(-cyl.innerRadius, -cyl.innerRadius, (cyl.innerRadius * 2.0)+border,
      (cyl.innerRadius * 2.0)+border);
  QRegion ro(rco.toRect(), QRegion::Rectangle);
  QRegion ri(rci.toRect(), QRegion::Ellipse);
  QRegion region = ro.subtracted(ri);
  painter.setClipRegion(region);
  if (erase) {
      painter.setBrush(Qt::NoBrush);
      painter.setPen(Qt::NoPen);
  } else {
    QBrush b(cyl.color);
    painter.setBrush(b);
    painter.setPen(QPen(cyl.color.darker(200),border));
  }
  DrawSegments(&painter, s, cyl.outerRadius);
}
Пример #2
0
void DrawCircle(udword nb_segments, const Matrix4x4& matrix, const Point& color, float radius, bool semi_circle)
{
	float step = TWOPI / float(nb_segments);
	udword segs = nb_segments;
	if(semi_circle)
		segs /= 2;

	Point* tmp = (Point*)StackAlloc(sizeof(Point)*segs*2);
	for(udword i=0;i<segs;i++)
	{
		udword j=i+1;
		if(j==nb_segments)
			j=0;

		const float angle0 = float(i) * step;
		const float angle1 = float(j) * step;

		const Point p0 = Point(radius * sinf(angle0), radius * cosf(angle0), 0.0f) * matrix;
		const Point p1 = Point(radius * sinf(angle1), radius * cosf(angle1), 0.0f) * matrix;

//		DrawLine(p0, p1, color);
		tmp[i*2+0] = p0;
		tmp[i*2+1] = p1;
	}
	DrawSegments(segs, tmp, color, 1.0f);
}
Пример #3
0
/*******************************************************************************
   K-means segment the image
        image - Input image
        gridSize - Initial size of the segments
        numIterations - Number of iterations to run k-means
        spatialSigma - Spatial sigma for measuring distance
        colorSigma - Color sigma for measuring distance
        matchCost - The match cost for each pixel at each disparity
        numDisparities - Number of disparity levels
        segmentImage - Image showing segmentations

*******************************************************************************/
void MainWindow::Segment(QImage image, int gridSize, int numIterations, double spatialSigma, double colorSigma,
                         double *matchCost, int numDisparities, QImage *segmentImage)
{
    int w = image.width();
    int h = image.height();
    int iter;
    int numSegments = 0;

    // Stores the segment assignment for each pixel
    int *segment = new int [w*h];

    // Compute an initial segmentation
    GridSegmentation(segment, numSegments, gridSize, w, h);

    // allocate memory for storing the segments mean position and color
    double (*meanSpatial)[2] = new double [numSegments][2];
    double (*meanColor)[3] = new double [numSegments][3];

    // Iteratively update the segmentation
    for(iter=1;iter<numIterations;iter++)
    {
        // Compute new means
        ComputeSegmentMeans(image, segment, numSegments, meanSpatial, meanColor);
        // Compute new pixel assignment to pixels
        AssignPixelsToSegments(image, segment, numSegments, meanSpatial, meanColor, spatialSigma, colorSigma);
    }

    // Update means again for display
    ComputeSegmentMeans(image, segment, numSegments, meanSpatial, meanColor);
    // Display the segmentation
    DrawSegments(segmentImage, segment, meanColor);

    // Update the match cost based on the segmentation
    SegmentAverageMatchCost(segment, numSegments, w, h, numDisparities, matchCost);

    delete [] meanSpatial;
    delete [] meanColor;
    delete [] segment;
}