Exemplo n.º 1
0
Arquivo: oocs.c Projeto: Gilles86/afni
int main (int argc, char * argv[])
{
  GtsSurface * s;
  GtsBBox * bbox;
  gdouble delta;
  GtsPoint * p1, * p2, * p3;
  guint nt;
  GtsRange cluster_stats;
  GtsClusterGrid * cluster_grid;
  
  if (argc != 2) {
    fprintf (stderr, "usage: oocs DELTA < infile > outfile\n");
    return 1;
  }

  s = gts_surface_new (gts_surface_class (),
		       gts_face_class (),
		       gts_edge_class (),
		       gts_vertex_class ());

  bbox = gts_bbox_new (gts_bbox_class (), s, 0., 0., 0., 0., 0., 0.);
  scanf ("%u", &nt);
  scanf ("%lf %lf %lf", &bbox->x1, &bbox->y1, &bbox->z1);
  scanf ("%lf %lf %lf", &bbox->x2, &bbox->y2, &bbox->z2);
  delta = atof (argv[1])*sqrt (gts_bbox_diagonal2 (bbox));

  cluster_grid = gts_cluster_grid_new (gts_cluster_grid_class (), 
				       gts_cluster_class (), 
				       s, bbox, delta);

  p1 = gts_point_new (gts_point_class (), 0., 0., 0.);
  p2 = gts_point_new (gts_point_class (), 0., 0., 0.);
  p3 = gts_point_new (gts_point_class (), 0., 0., 0.);

  while (scanf ("%lf %lf %lf", &p1->x, &p1->y, &p1->z) == 3 &&
	 scanf ("%lf %lf %lf", &p2->x, &p2->y, &p2->z) == 3 &&
	 scanf ("%lf %lf %lf", &p3->x, &p3->y, &p3->z) == 3)
    gts_cluster_grid_add_triangle (cluster_grid, p1, p2, p3, NULL);
  cluster_stats = gts_cluster_grid_update (cluster_grid);

  gts_object_destroy (GTS_OBJECT (p1));
  gts_object_destroy (GTS_OBJECT (p2));
  gts_object_destroy (GTS_OBJECT (p3));
  gts_object_destroy (GTS_OBJECT (cluster_grid));

  fprintf (stderr, "Initial number of triangles: %u\n", nt);
  fprintf (stderr, "%d clusters of size: min: %g avg: %.1f|%.1f max: %g\n",
	   cluster_stats.n,
	   cluster_stats.min, 
	   cluster_stats.mean, cluster_stats.stddev, 
	   cluster_stats.max);
  gts_surface_print_stats (s, stderr);
  gts_surface_write (s, stdout);

  return 0;
}
Exemplo n.º 2
0
/**
 * gts_triangle_circumcircle_center:
 * @t: a #GtsTriangle.
 * @point_class: a #GtsPointClass.
 *
 * Returns: a new #GtsPoint, center of the circumscribing circle of @t or
 * %NULL if the circumscribing circle is not defined.
 */
GtsPoint * gts_triangle_circumcircle_center (GtsTriangle * t,
        GtsPointClass * point_class)
{
    GtsVertex * v1, * v2, * v3;
    gdouble xa, ya, xb, yb, xc, yc;
    gdouble xd, yd, xe, ye;
    gdouble xad, yad, xae, yae;
    gdouble det;

    g_return_val_if_fail (t != NULL, NULL);
    g_return_val_if_fail (point_class != NULL, NULL);

    gts_triangle_vertices (t, &v1, &v2, &v3);

    xa = GTS_POINT (v1)->x;
    ya = GTS_POINT (v1)->y;
    xb = GTS_POINT (v2)->x;
    yb = GTS_POINT (v2)->y;
    xc = GTS_POINT (v3)->x;
    yc = GTS_POINT (v3)->y;
    xd = (xa + xb)/2.;
    yd = (ya + yb)/2.;
    xe = (xa + xc)/2.;
    ye = (ya + yc)/2.;
    xad = xd - xa;
    yad = yd - ya;
    xae = xe - xa;
    yae = ye - ya;
    det = xad*yae - xae*yad;
    if (det == 0.)
        return NULL;
    return gts_point_new (point_class,
                          (yae*yad*(yd - ye) + xad*yae*xd - xae*yad*xe)/det,
                          -(xae*xad*(xd - xe) + yad*xae*yd - yae*xad*ye)/det,
                          0.);
}