Ejemplo n.º 1
0
/**
 * Triangulates the given (convex or concave) simple polygon to a list of triangle vertices.
 * \param vertices pairs describing vertices of the polygon, in either clockwise or counterclockwise order.
 * \return triples of triangle indices in clockwise order.
 *         Note the returned array is reused for later calls to the same method.
 */
void BLI_polyfill_calc_ex(
        const float (*coords)[2],
        const unsigned int coords_tot,
        unsigned int (*r_tris)[3],

        unsigned int *r_indices, eSign *r_coords_sign)
{
	PolyFill pf;

	/* localize */
	unsigned int *indices = r_indices;
	eSign *coords_sign = r_coords_sign;

	unsigned int i;

	/* assign all polyfill members here */
	pf.indices = r_indices;
	pf.coords = coords;
	pf.coords_tot = coords_tot;
	pf.coords_sign = r_coords_sign;
#ifdef USE_CONVEX_SKIP
	pf.coords_tot_concave = 0;
#endif
	pf.tris = r_tris;
	pf.tris_tot = 0;

	if ((coords_tot < 3) ||
	    cross_poly_v2((int)coords_tot, (float(*)[2])coords) > 0.0f)
	{
		for (i = 0; i < coords_tot; i++) {
			indices[i] = i;
		}
	}
	else {
		/* reversed */
		unsigned int n = coords_tot - 1;
		for (i = 0; i < coords_tot; i++) {
			indices[i] = (n - i);
		}
	}

	for (i = 0; i < coords_tot; i++) {
		coords_sign[i] = pf_coord_sign_calc(&pf, i);
#ifdef USE_CONVEX_SKIP
		if (coords_sign[i] != CONVEX) {
			pf.coords_tot_concave += 1;
		}
#endif
	}

	pf_triangulate(&pf);
}
Ejemplo n.º 2
0
static void polyfill_calc(PolyFill *pf)
{
#ifdef USE_KDTREE
#  ifdef USE_CONVEX_SKIP
  if (pf->coords_tot_concave)
#  endif
  {
    kdtree2d_new(&pf->kdtree, pf->coords_tot_concave, pf->coords);
    kdtree2d_init(&pf->kdtree, pf->coords_tot, pf->indices);
    kdtree2d_balance(&pf->kdtree);
    kdtree2d_init_mapping(&pf->kdtree);
  }
#endif

  pf_triangulate(pf);
}