int main(void)
{
  print_triangle(1);
  print_char('-');
  print_char('\n');
  print_triangle(2);
  print_char('-');
  print_char('\n');
  print_triangle(3);
  print_char('-');
  print_char('\n');
  print_triangle(10);
  print_char('-');
  print_char('\n');
  return (0);
}
Ejemplo n.º 2
0
Archivo: t5.c Proyecto: CcPan/rimiedu
int exer5()
{
    printf("第5题:\n");
    print_triangle(5);
    print_triangle(8);
    print_triangle2(10);
    
    // Mr.wang's solution
    for (int i=0; i<5; i++)
    {
        if (i==0 || i== 4)
        {
            printf("*");
        }
        if (i==1 || i==3)
        {
            printf("**");
        }
        if (i==2)
        {
            printf("***");
        }
        printf("\n");
    }
    
    printf("-----------\n");
    // Mr.wang's solution 2
    for (int i=0; i<5; i++)
    {
        printf("*");
        if (i>=1 && i<=3)
        {
            printf("*");
        }
        if (i==2)
        {
            printf("*");
        }
         printf("\n");
    }
    return 0;
}
Ejemplo n.º 3
0
int main()
{
	ponto A, B, C, P;

	puts("pontos do triangulo: 'x,y'");
	scanf("%d,%d", &A.x, &A.y);
	scanf("%d,%d", &B.x, &B.y);
	scanf("%d,%d", &C.x, &C.y);
	print_triangle(A,B,C,P);
	return 0;
}
Ejemplo n.º 4
0
/* Write out all triangles in an object */
void print_object(object * obj, int level, dimeModel & model, const char * layername,
                  dimeBlock * block)
{
  int i;
  
  const dimeLayer * layer = model.getLayer(layername);

  for (i = 0; i < obj->npoly; i++) {
    print_triangle(&obj->poly[i], model, layer, block);  
  }
}
Ejemplo n.º 5
0
int main(int argc, char * const argv[])
{
  int N = 10, L = 10;
  int opt;
  int def = 0;
  while( (opt = getopt(argc, argv, opts)) != -1) {
    switch(opt) {
      case 'N':
        N = atoi(optarg);
        break;
      case 'L':
        L = atoi(optarg);
        break;
      case 't':
        def = atoi(optarg);
        break;
      case'h':
        print_usage();
        exit(EXIT_SUCCESS);
        break;
    }
  } 
  dots_init(N);
  fprintf(stderr, " N: %d L: %d t:%d\n", N,L,def);
  switch(def) {
    case 0:
      print_triangle(N, L, null_init, write_pr);
      break;
    case 1:
      print_triangle(N, L, null_init, writev_pr);
      break;
    case 2:
      print_triangle(N, L, null_init, printf_pr);
      break;
    case 3:
      print_triangle(N, L, printf_init, printf_pr);
      break;
  }
  return 0;
}
Ejemplo n.º 6
0
triangulation triangulate_cube(data_list * data,  char * tmp_triang_file, char * tmp_data_file) {
	printf("%s %s\n", tmp_triang_file, tmp_data_file);
  triangulation result = triangulation_init(data_list_dim(data));

  cube_points cube = gen_cube_points(result.dim);
  facet_acute_data parameters;
  parameters.cube = &cube;
  parameters.boundary_func = &triangle_boundary_cube;
  parameters.data = data;
  parameters.store_acute_ind = 1;
  parameters.acute_ind = malloc(sizeof(unsigned short) * cube.len);

  //This list holds all conform tetrahedrons for a given triangle, max size = cube.len
  ptetra tet_list = malloc(sizeof(tetra) * cube.len);
  unsigned short tet_list_len = 0;

  //Lists needed for the dynamic_remove loop
  tri_list check_list, check_list_new;

  check_list     = tri_list_init(result.dim, MEM_LIST_FALSE);
  check_list_new = tri_list_init(result.dim, MEM_LIST_FALSE);

  //Start triangle (0,0,0), (rand,0,0), (rand,rand,0)
  result.bound_len = 1;
  result.bound_tri = triangulation_start_facet(data);
  printf("Starting triangulation with facet:\n");
  print_triangle(result.bound_tri);
  /*
   * During this method we are going to operate data that is not thread-safe.
   * To avoid race conditions we need an array of locks. We use a lock for the
   * first two points of a triangle (so need 2d array of locks).
   */
  omp_lock_t ** locks = malloc(sizeof(omp_lock_t *) * cube.len);
  //Initalize the locks
  for (size_t i = 0; i < cube.len; i++){
    locks[i] = malloc(sizeof(omp_lock_t) * (cube.len - i));
    for (size_t j = 0; j < cube.len - i; j++)
      omp_init_lock(&locks[i][j]);
  }
  //While we have triangles on the boundary..
  while (result.bound_len > 0) {
    tri_list_empty(&check_list);
    tri_list_empty(&check_list_new);
    /*
     * We are going to add a tetrahedron on the boundary triangle.
     * To do so, we select a random triangle on the boundary. Then we generate all the
     * acute tetrahedra (above and below) with facets in our possible list.
     * From this list we remove all the tetrahedrons that intersect with our current triangulation.
     * Then we add a random tetrahedron to our triangulation, update the conform list and repeat.
     */
    int rand_bound = rand() % result.bound_len;
    printf("\n\nTotal amount of triangles left:%zu\nExpanding triangulation at boundary triangle: \n", data_list_count(data));
    print_triangle(result.bound_tri + rand_bound);

    //Calculate the conform tetrahedrons above and below
    if (!facet_conform(&result.bound_tri[rand_bound], &parameters))
    {
      printf("We have a triangle on the boundary that is not conform anymore.\n");
      printf("Whatthefuck? Breaking!\n");
      break;
    }

    tet_list_len = parameters.acute_ind_len;
    printf("Total amount of conform tetrahedrons found for this boundary: %hu\n", tet_list_len);
    //Form explicit list of the tetrahedrons
    for (unsigned short i = 0; i < tet_list_len; i++) 
    {
      copyArr3(tet_list[i].vertices[0], result.bound_tri[rand_bound].vertices[0]);
      copyArr3(tet_list[i].vertices[1], result.bound_tri[rand_bound].vertices[1]);
      copyArr3(tet_list[i].vertices[2], result.bound_tri[rand_bound].vertices[2]);
      copyArr3(tet_list[i].vertices[3], cube.points[parameters.acute_ind[i]]);
    }

    //Remove all the tetrahedrons that intersect with current triangulation.
    filter_tet_list_disjoint_triangulation(tet_list, &tet_list_len, &result);

    printf("Amount of tetrahedrons left after filtering: %hu\n\n",tet_list_len);
    if (tet_list_len == 0) {
      printf("Waarom is deze lijst nu al f*****g leeggefilterd?\n");
      printf("Dead end, helaas pindakaas. Got to %zu\n", result.tetra_len);
      break;
    }

    //Select random tetrahedron disjoint with the current triangulation
    int rand_tet = rand() % tet_list_len;
    /*
     * Add the above tetra to the triangulation.
     * This removes all the boundary triangles that are covered by this tetrahedron
     */
    printf("Adding the following tetra to the triangulation\n");
    print_tetra(tet_list + rand_tet);
    printf("\n\n");
    add_tet_triangulation(tet_list + rand_tet, &result);
    triangulation_print(&result);

    if (!result.bound_len) //If we have no boundaries left, we must be done!!
    {
      printf("No more boundaries left.. WE FINNISHED!??\n");
      break;
    }
    //Consistency check
    if (!triangulation_consistent(&result, &parameters))
    {
      printf("Triangulation not consistent after adding the tetrahedron. Breaking.\n");
      break;
    }
    /*
     * Calculate a list of all the triangles we are going to remove
     */
    double time_removed = omp_get_wtime();
    printf("Removing triangles not disjoint with new tetrahedron\n");
    size_t removed = filter_intersection_data_list_tet(data,  &check_list, tet_list + rand_tet, locks);
    printf("Removed %zu triangles that are not disjoint with the new tetrahedron\n", removed);
    printf("The check_list has size %zu\n", tri_list_count(&check_list));
    printf("Time took to removed triangles: %g seconds\n", omp_get_wtime()-time_removed);

    if (!triangulation_consistent(&result, &parameters)) {
      printf("After filtering the memory list we have a non consistent triangulation. Break\n");
      break;
    }
    //Do two iterations
    facets_conform_dynamic_remove(data, &result, 1, &check_list, &check_list_new, locks);

    if (!triangulation_consistent(&result, &parameters)) {
      printf("Triangulation not consistent anymore after conforming the data set.. Breaking\n");
      break;
    }

    /*mem_list_cube_compress(&data->mem_list);


      if (tmp_triang_file && tmp_data_file) {
      triangulation_to_file(&result, tmp_triang_file);
      data_list_to_file(data, tmp_data_file, MEM_LIST_SAVE_CLEAN);
      }
      */
  }
  for (size_t i = 0; i < cube.len; i++){
    for (size_t j = 0; j < cube.len - i; j++)
      omp_destroy_lock(&locks[i][j]);
    free(locks[i]);
  }

  free(locks);
  free(cube.points);
  free(parameters.acute_ind);
  free(tet_list);
  tri_list_free(&check_list);
  tri_list_free(&check_list_new);
  printf("Triangulation has length of %zu\n", result.tetra_len);
  return result;
}
int main (void)
{
    auto triangle = pascal_triagle(5);
    print_triangle(triangle);
    return 0;
}