コード例 #1
0
static cairo_status_t
line_to (void *closure,
	 const cairo_point_t *point)
{
    struct stroker *stroker = closure;
    cairo_stroke_face_t start;
    cairo_point_t *p1 = &stroker->current_face.point;
    cairo_slope_t dev_slope;

    stroker->has_initial_sub_path = TRUE;

    if (p1->x == point->x && p1->y == point->y)
	return CAIRO_STATUS_SUCCESS;

#if DEBUG
    _cairo_contour_add_point (&stroker->path, point);
#endif

    _cairo_slope_init (&dev_slope, p1, point);
    compute_face (p1, &dev_slope, stroker, &start);

    if (stroker->has_current_face) {
	int clockwise = _cairo_slope_compare (&stroker->current_face.dev_vector,
					      &start.dev_vector);
	if (clockwise) {
	    clockwise = clockwise < 0;
	    /* Join with final face from previous segment */
	    if (! within_tolerance (&stroker->current_face.ccw, &start.ccw,
				    stroker->contour_tolerance) ||
		! within_tolerance (&stroker->current_face.cw, &start.cw,
				    stroker->contour_tolerance))
	    {
		outer_join (stroker, &stroker->current_face, &start, clockwise);
		inner_join (stroker, &stroker->current_face, &start, clockwise);
	    }
	}
    } else {
	if (! stroker->has_first_face) {
	    /* Save sub path's first face in case needed for closing join */
	    stroker->first_face = start;
	    stroker->has_first_face = TRUE;
	}
	stroker->has_current_face = TRUE;

	contour_add_point (stroker, &stroker->cw, &start.cw);
	contour_add_point (stroker, &stroker->ccw, &start.ccw);
    }

    stroker->current_face = start;
    stroker->current_face.point = *point;
    stroker->current_face.ccw.x += dev_slope.dx;
    stroker->current_face.ccw.y += dev_slope.dy;
    stroker->current_face.cw.x += dev_slope.dx;
    stroker->current_face.cw.y += dev_slope.dy;

    contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw);
    contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw);

    return CAIRO_STATUS_SUCCESS;
}
コード例 #2
0
static cairo_status_t
line_to (void *closure,
         const cairo_point_t *point)
{
    struct stroker *stroker = closure;
    cairo_stroke_face_t start;
    cairo_point_t *p1 = &stroker->current_face.point;
    cairo_slope_t dev_slope;

    stroker->has_sub_path = TRUE;

    if (p1->x == point->x && p1->y == point->y)
        return CAIRO_STATUS_SUCCESS;

    _cairo_slope_init (&dev_slope, p1, point);
    compute_face (p1, &dev_slope, stroker, &start);

    if (stroker->has_current_face) {
        int clockwise = join_is_clockwise (&stroker->current_face, &start);
        /* Join with final face from previous segment */
        outer_join (stroker, &stroker->current_face, &start, clockwise);
        inner_join (stroker, &stroker->current_face, &start, clockwise);
    } else {
        if (! stroker->has_first_face) {
            /* Save sub path's first face in case needed for closing join */
            stroker->first_face = start;
            _cairo_tristrip_move_to (stroker->strip, &start.cw);
            stroker->has_first_face = TRUE;
        }
        stroker->has_current_face = TRUE;

        _cairo_tristrip_add_point (stroker->strip, &start.cw);
        _cairo_tristrip_add_point (stroker->strip, &start.ccw);
    }

    stroker->current_face = start;
    stroker->current_face.point = *point;
    stroker->current_face.ccw.x += dev_slope.dx;
    stroker->current_face.ccw.y += dev_slope.dy;
    stroker->current_face.cw.x += dev_slope.dx;
    stroker->current_face.cw.y += dev_slope.dy;

    _cairo_tristrip_add_point (stroker->strip, &stroker->current_face.cw);
    _cairo_tristrip_add_point (stroker->strip, &stroker->current_face.ccw);

    return CAIRO_STATUS_SUCCESS;
}
コード例 #3
0
static cairo_status_t
curve_to (void *closure,
          const cairo_point_t *b,
          const cairo_point_t *c,
          const cairo_point_t *d)
{
    struct stroker *stroker = closure;
    cairo_spline_t spline;
    cairo_stroke_face_t face;

    if (stroker->has_limits) {
        if (! _cairo_spline_intersects (&stroker->current_face.point, b, c, d,
                                        &stroker->limit))
            return line_to (closure, d);
    }

    if (! _cairo_spline_init (&spline, spline_to, stroker,
                              &stroker->current_face.point, b, c, d))
        return line_to (closure, d);

    compute_face (&stroker->current_face.point, &spline.initial_slope,
                  stroker, &face);

    if (stroker->has_current_face) {
        int clockwise = join_is_clockwise (&stroker->current_face, &face);
        /* Join with final face from previous segment */
        outer_join (stroker, &stroker->current_face, &face, clockwise);
        inner_join (stroker, &stroker->current_face, &face, clockwise);
    } else {
        if (! stroker->has_first_face) {
            /* Save sub path's first face in case needed for closing join */
            stroker->first_face = face;
            _cairo_tristrip_move_to (stroker->strip, &face.cw);
            stroker->has_first_face = TRUE;
        }
        stroker->has_current_face = TRUE;

        _cairo_tristrip_add_point (stroker->strip, &face.cw);
        _cairo_tristrip_add_point (stroker->strip, &face.ccw);
    }
    stroker->current_face = face;

    return _cairo_spline_decompose (&spline, stroker->tolerance);
}
コード例 #4
0
static void
add_caps (struct stroker *stroker)
{
    /* check for a degenerative sub_path */
    if (stroker->has_sub_path &&
            ! stroker->has_first_face &&
            ! stroker->has_current_face &&
            stroker->style.line_cap == CAIRO_LINE_CAP_ROUND)
    {
        /* pick an arbitrary slope to use */
        cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 };
        cairo_stroke_face_t face;

        /* arbitrarily choose first_point */
        compute_face (&stroker->first_point, &slope, stroker, &face);

        add_leading_cap (stroker, &face);
        add_trailing_cap (stroker, &face);

        /* ensure the circle is complete */
        //_cairo_contour_add_point (&stroker->ccw.contour,
        //_cairo_contour_first_point (&stroker->ccw.contour));
    } else {
        if (stroker->has_current_face)
            add_trailing_cap (stroker, &stroker->current_face);

        //_cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour);
        //_cairo_contour_reset (&stroker->ccw.contour);

        if (stroker->has_first_face) {
            //_cairo_contour_add_point (&stroker->ccw.contour,
            //&stroker->first_face.cw);
            add_leading_cap (stroker, &stroker->first_face);
            //_cairo_polygon_add_contour (stroker->polygon,
            //&stroker->ccw.contour);
            //_cairo_contour_reset (&stroker->ccw.contour);
        }
    }
}
コード例 #5
0
static cairo_status_t
spline_to (void *closure,
           const cairo_point_t *point,
           const cairo_slope_t *tangent)
{
    struct stroker *stroker = closure;
    cairo_stroke_face_t face;

    if (tangent->dx == 0 && tangent->dy == 0) {
        const cairo_point_t *inpt, *outpt;
        cairo_point_t t;
        int clockwise;

        face = stroker->current_face;

        face.usr_vector.x = -face.usr_vector.x;
        face.usr_vector.y = -face.usr_vector.y;
        face.dev_vector.dx = -face.dev_vector.dx;
        face.dev_vector.dy = -face.dev_vector.dy;

        t = face.cw;
        face.cw = face.ccw;
        face.ccw = t;

        clockwise = join_is_clockwise (&stroker->current_face, &face);
        if (clockwise) {
            inpt = &stroker->current_face.cw;
            outpt = &face.cw;
        } else {
            inpt = &stroker->current_face.ccw;
            outpt = &face.ccw;
        }

        add_fan (stroker,
                 &stroker->current_face.dev_vector,
                 &face.dev_vector,
                 &stroker->current_face.point, inpt, outpt,
                 clockwise);
    } else {
        compute_face (point, tangent, stroker, &face);

        if (face.dev_slope.x * stroker->current_face.dev_slope.x +
                face.dev_slope.y * stroker->current_face.dev_slope.y < 0)
        {
            const cairo_point_t *inpt, *outpt;
            int clockwise = join_is_clockwise (&stroker->current_face, &face);

            stroker->current_face.cw.x += face.point.x - stroker->current_face.point.x;
            stroker->current_face.cw.y += face.point.y - stroker->current_face.point.y;
            //contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw);

            stroker->current_face.ccw.x += face.point.x - stroker->current_face.point.x;
            stroker->current_face.ccw.y += face.point.y - stroker->current_face.point.y;
            //contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw);

            if (clockwise) {
                inpt = &stroker->current_face.cw;
                outpt = &face.cw;
            } else {
                inpt = &stroker->current_face.ccw;
                outpt = &face.ccw;
            }
            add_fan (stroker,
                     &stroker->current_face.dev_vector,
                     &face.dev_vector,
                     &stroker->current_face.point, inpt, outpt,
                     clockwise);
        }

        _cairo_tristrip_add_point (stroker->strip, &face.cw);
        _cairo_tristrip_add_point (stroker->strip, &face.ccw);
    }

    stroker->current_face = face;

    return CAIRO_STATUS_SUCCESS;
}
コード例 #6
0
static void
add_caps (struct stroker *stroker)
{
    /* check for a degenerative sub_path */
    if (stroker->has_initial_sub_path &&
	! stroker->has_first_face &&
	! stroker->has_current_face &&
	stroker->style.line_cap == CAIRO_LINE_CAP_ROUND)
    {
	/* pick an arbitrary slope to use */
	cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 };
	cairo_stroke_face_t face;

	/* arbitrarily choose first_point */
	compute_face (&stroker->first_point, &slope, stroker, &face);

	add_leading_cap (stroker, &face, &stroker->ccw);
	add_trailing_cap (stroker, &face, &stroker->ccw);

	/* ensure the circle is complete */
	_cairo_contour_add_point (&stroker->ccw.contour,
				  _cairo_contour_first_point (&stroker->ccw.contour));

	_cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour);
	_cairo_contour_reset (&stroker->ccw.contour);
    } else {
	if (stroker->has_current_face)
	    add_trailing_cap (stroker, &stroker->current_face, &stroker->ccw);

#if DEBUG
	{
	    FILE *file = fopen ("contours.txt", "a");
	    _cairo_debug_print_contour (file, &stroker->path);
	    _cairo_debug_print_contour (file, &stroker->cw.contour);
	    _cairo_debug_print_contour (file, &stroker->ccw.contour);
	    fclose (file);
	    _cairo_contour_reset (&stroker->path);
	}
#endif

	_cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour);
	_cairo_contour_reset (&stroker->ccw.contour);

	if (stroker->has_first_face) {
	    _cairo_contour_add_point (&stroker->ccw.contour,
				      &stroker->first_face.cw);
	    add_leading_cap (stroker, &stroker->first_face, &stroker->ccw);
#if DEBUG
	    {
		FILE *file = fopen ("contours.txt", "a");
		_cairo_debug_print_contour (file, &stroker->ccw.contour);
		fclose (file);
	    }
#endif

	    _cairo_polygon_add_contour (stroker->polygon,
					&stroker->ccw.contour);
	    _cairo_contour_reset (&stroker->ccw.contour);
	}

	_cairo_polygon_add_contour (stroker->polygon, &stroker->cw.contour);
	_cairo_contour_reset (&stroker->cw.contour);
    }
}
コード例 #7
0
static cairo_status_t
spline_to (void *closure,
	   const cairo_point_t *point,
	   const cairo_slope_t *tangent)
{
    struct stroker *stroker = closure;
    cairo_stroke_face_t face;

#if DEBUG
    _cairo_contour_add_point (&stroker->path, point);
#endif
    if ((tangent->dx | tangent->dy) == 0) {
	const cairo_point_t *inpt, *outpt;
	struct stroke_contour *outer;
	cairo_point_t t;
	int clockwise;

	face = stroker->current_face;

	face.usr_vector.x = -face.usr_vector.x;
	face.usr_vector.y = -face.usr_vector.y;
	face.dev_vector.dx = -face.dev_vector.dx;
	face.dev_vector.dy = -face.dev_vector.dy;

	t = face.cw;
	face.cw = face.ccw;
	face.ccw = t;

	clockwise = join_is_clockwise (&stroker->current_face, &face);
	if (clockwise) {
	    inpt = &stroker->current_face.cw;
	    outpt = &face.cw;
	    outer = &stroker->cw;
	} else {
	    inpt = &stroker->current_face.ccw;
	    outpt = &face.ccw;
	    outer = &stroker->ccw;
	}

	add_fan (stroker,
		 &stroker->current_face.dev_vector,
		 &face.dev_vector,
		 &stroker->current_face.point,
		 clockwise, outer);
    } else {
	compute_face (point, tangent, stroker, &face);

	if ((face.dev_slope.x * stroker->current_face.dev_slope.x +
	     face.dev_slope.y * stroker->current_face.dev_slope.y) < stroker->spline_cusp_tolerance)
	{
	    const cairo_point_t *inpt, *outpt;
	    struct stroke_contour *outer;
	    int clockwise = join_is_clockwise (&stroker->current_face, &face);

	    stroker->current_face.cw.x += face.point.x - stroker->current_face.point.x;
	    stroker->current_face.cw.y += face.point.y - stroker->current_face.point.y;
	    contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw);

	    stroker->current_face.ccw.x += face.point.x - stroker->current_face.point.x;
	    stroker->current_face.ccw.y += face.point.y - stroker->current_face.point.y;
	    contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw);

	    if (clockwise) {
		inpt = &stroker->current_face.cw;
		outpt = &face.cw;
		outer = &stroker->cw;
	    } else {
		inpt = &stroker->current_face.ccw;
		outpt = &face.ccw;
		outer = &stroker->ccw;
	    }
	    add_fan (stroker,
		     &stroker->current_face.dev_vector,
		     &face.dev_vector,
		     &stroker->current_face.point,
		     clockwise, outer);
	}

	contour_add_point (stroker, &stroker->cw, &face.cw);
	contour_add_point (stroker, &stroker->ccw, &face.ccw);
    }

    stroker->current_face = face;

    return CAIRO_STATUS_SUCCESS;
}
コード例 #8
0
ファイル: Viewer.cpp プロジェクト: kriolog/cgal
void Viewer::compute_elements()
{
  LCC &lcc = *scene->lcc;

  pos_facets.clear();
  flat_normals.clear();
  smooth_normals.clear();
  colors.clear();
  pos_lines.clear();
  pos_points.clear();

  if ( lcc.is_empty() )
  {
    bb = LCC::Point(CGAL::ORIGIN).bbox();
    bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer
    return;
  }

  LCC::size_type markvertex = lcc.get_new_mark();
  LCC::size_type markedge   = lcc.get_new_mark();
  LCC::size_type markface   = lcc.get_new_mark();

  bool empty = true;
  for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(),
         itend=lcc.attributes<3>().end(); it!=itend; ++it )
  {
    if ( it->info().is_visible() )
    {
      for(LCC::Dart_of_cell_range<3>::iterator
            dartIter=lcc.darts_of_cell<3>(lcc.dart_of_attribute<3>(it)).begin();
          dartIter.cont(); ++dartIter)
      {
        if ( it->info().is_filled() && !lcc.is_marked(dartIter, markface) )
          compute_face(dartIter, markface);

        if ( !lcc.is_marked(dartIter, markedge) )
          compute_edge(dartIter, markedge);

        if ( !lcc.is_marked(dartIter, markvertex) )
        compute_vertex(dartIter, markvertex, empty);
      }
    }
  }

  if ( empty )
  {
    bb = LCC::Point(CGAL::ORIGIN).bbox();
    bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer
  }

  for (LCC::Dart_range::iterator it=lcc.darts().begin(),
         itend=lcc.darts().end(); it!=itend; ++it )
  {
    lcc.unmark(it, markvertex);
    lcc.unmark(it, markedge);
    lcc.unmark(it, markface);
  }

  lcc.free_mark(markvertex);
  lcc.free_mark(markedge);
  lcc.free_mark(markface);
}