コード例 #1
0
ファイル: TriangleMesh.cpp プロジェクト: iautodidact/Slic3r
void TriangleMesh::rotate(double angle, Point* center)
{
    this->translate(-center->x, -center->y, 0);
    stl_rotate_z(&(this->stl), (float)angle);
    this->translate(+center->x, +center->y, 0);
}
コード例 #2
0
ファイル: admesh.c プロジェクト: 2bright/admesh
int
main(int argc, char **argv) {
  stl_file stl_in;
  float    tolerance = 0;
  float    increment = 0;
  float    x_trans;
  float    y_trans;
  float    z_trans;
  float    scale_factor = 0;
  float    rotate_x_angle = 0;
  float    rotate_y_angle = 0;
  float    rotate_z_angle = 0;
  int      c;
  char     *program_name;
  char     *binary_name = NULL;
  char     *ascii_name = NULL;
  char     *merge_name = NULL;
  char     *off_name = NULL;
  char     *dxf_name = NULL;
  char     *vrml_name = NULL;
  int      fixall_flag = 1;	       /* Default behavior is to fix all. */
  int      exact_flag = 0;	       /* All checks turned off by default. */
  int      tolerance_flag = 0;	       /* Is tolerance specified on cmdline */
  int      nearby_flag = 0;
  int      remove_unconnected_flag = 0;
  int      fill_holes_flag = 0;
  int      normal_directions_flag = 0;
  int      normal_values_flag = 0;
  int      reverse_all_flag = 0;
  int      write_binary_stl_flag = 0;
  int      write_ascii_stl_flag = 0;
  int      generate_shared_vertices_flag = 0;
  int      write_off_flag = 0;
  int      write_dxf_flag = 0;
  int      write_vrml_flag = 0;
  int      translate_flag = 0;
  int      scale_flag = 0;
  int      rotate_x_flag = 0;
  int      rotate_y_flag = 0;
  int      rotate_z_flag = 0;
  int      mirror_xy_flag = 0;
  int      mirror_yz_flag = 0;
  int      mirror_xz_flag = 0;
  int      merge_flag = 0;
  int      help_flag = 0;
  int      version_flag = 0;

  int      iterations = 2;	       /* Default number of iterations. */
  int      increment_flag = 0;
  char     *input_file = NULL;

  int ret = 0;

  enum {rotate_x = 1000, rotate_y, rotate_z, merge, help, version,
        mirror_xy, mirror_yz, mirror_xz, scale, translate, reverse_all,
        off_file, dxf_file, vrml_file
       };

  struct option long_options[] = {
    {"exact",              no_argument,       NULL, 'e'},
    {"nearby",             no_argument,       NULL, 'n'},
    {"tolerance",          required_argument, NULL, 't'},
    {"iterations",         required_argument, NULL, 'i'},
    {"increment",          required_argument, NULL, 'm'},
    {"remove-unconnected", no_argument,       NULL, 'u'},
    {"fill-holes",         no_argument,       NULL, 'f'},
    {"normal-directions",  no_argument,       NULL, 'd'},
    {"normal-values",      no_argument,       NULL, 'v'},
    {"no-check",           no_argument,       NULL, 'c'},
    {"reverse-all",        no_argument,       NULL, reverse_all},
    {"write-binary-stl",   required_argument, NULL, 'b'},
    {"write-ascii-stl",    required_argument, NULL, 'a'},
    {"write-off",          required_argument, NULL, off_file},
    {"write-dxf",          required_argument, NULL, dxf_file},
    {"write-vrml",         required_argument, NULL, vrml_file},
    {"translate",          required_argument, NULL, translate},
    {"scale",              required_argument, NULL, scale},
    {"x-rotate",           required_argument, NULL, rotate_x},
    {"y-rotate",           required_argument, NULL, rotate_y},
    {"z-rotate",           required_argument, NULL, rotate_z},
    {"xy-mirror",          no_argument,       NULL, mirror_xy},
    {"yz-mirror",          no_argument,       NULL, mirror_yz},
    {"xz-mirror",          no_argument,       NULL, mirror_xz},
    {"merge",              required_argument, NULL, merge},
    {"help",               no_argument,       NULL, help},
    {"version",            no_argument,       NULL, version},
    {NULL, 0, NULL, 0}
  };

  program_name = argv[0];
  while((c = getopt_long(argc, argv, "et:i:m:nufdcvb:a:",
                         long_options, (int *) 0)) != EOF) {
    switch(c) {
    case 0:		       /* If *flag is not null */
      break;
    case 'e':
      exact_flag = 1;
      fixall_flag = 0;
      break;
    case 'n':
      nearby_flag = 1;
      fixall_flag = 0;
      break;
    case 't':
      tolerance_flag = 1;
      tolerance = atof(optarg);
      break;
    case 'i':
      iterations = atoi(optarg);
      break;
    case 'm':
      increment_flag = 1;
      increment = atof(optarg);
      break;
    case 'u':
      remove_unconnected_flag = 1;
      fixall_flag = 0;
      break;
    case 'f':
      fill_holes_flag = 1;
      fixall_flag = 0;
      break;
    case 'd':
      normal_directions_flag = 1;
      fixall_flag = 0;
      break;
    case 'v':
      normal_values_flag = 1;
      fixall_flag = 0;
      break;
    case 'c':
      fixall_flag = 0;
      break;
    case reverse_all:
      reverse_all_flag = 1;
      fixall_flag = 0;
      break;
    case 'b':
      write_binary_stl_flag = 1;
      binary_name = optarg;	       /* I'm not sure if this is safe. */
      break;
    case 'a':
      write_ascii_stl_flag = 1;
      ascii_name = optarg;	       /* I'm not sure if this is safe. */
      break;
    case off_file:
      generate_shared_vertices_flag = 1;
      write_off_flag = 1;
      off_name = optarg;
      break;
    case vrml_file:
      generate_shared_vertices_flag = 1;
      write_vrml_flag = 1;
      vrml_name = optarg;
      break;
    case dxf_file:
      write_dxf_flag = 1;
      dxf_name = optarg;
      break;
    case translate:
      translate_flag = 1;
      sscanf(optarg, "%f,%f,%f", &x_trans, &y_trans, &z_trans);
      break;
    case scale:
      scale_flag = 1;
      scale_factor = atof(optarg);
      break;
    case rotate_x:
      rotate_x_flag = 1;
      rotate_x_angle = atof(optarg);
      break;
    case rotate_y:
      rotate_y_flag = 1;
      rotate_y_angle = atof(optarg);
      break;
    case rotate_z:
      rotate_z_flag = 1;
      rotate_z_angle = atof(optarg);
      break;
    case mirror_xy:
      mirror_xy_flag = 1;
      break;
    case mirror_yz:
      mirror_yz_flag = 1;
      break;
    case mirror_xz:
      mirror_xz_flag = 1;
      break;
    case merge:
      merge_flag = 1;
      merge_name = optarg;
      break;
    case help:
      help_flag = 1;
      break;
    case version:
      version_flag = 1;
      break;
    default:
      usage(1, program_name);
      return 1;
    }
  }

  if(help_flag) {
    usage(0, program_name);
    return 0;
  }
  if(version_flag) {
    printf("ADMesh - version " VERSION "\n");
    return 0;
  }

  if(optind == argc) {
    printf("No input file name given.\n");
    usage(1, program_name);
    return 1;
  } else {
    input_file = argv[optind];
  }

  printf("\
ADMesh version " VERSION ", Copyright (C) 1995, 1996 Anthony D. Martin\n\
ADMesh comes with NO WARRANTY.  This is free software, and you are welcome to\n\
redistribute it under certain conditions.  See the file COPYING for details.\n");


  printf("Opening %s\n", input_file);
  stl_open(&stl_in, input_file);
  stl_exit_on_error(&stl_in);

  if(rotate_x_flag) {
    printf("Rotating about the x axis by %f degrees...\n", rotate_x_angle);
    stl_rotate_x(&stl_in, rotate_x_angle);
  }
  if(rotate_y_flag) {
    printf("Rotating about the y axis by %f degrees...\n", rotate_y_angle);
    stl_rotate_y(&stl_in, rotate_y_angle);
  }
  if(rotate_z_flag) {
    printf("Rotating about the z axis by %f degrees...\n", rotate_z_angle);
    stl_rotate_z(&stl_in, rotate_z_angle);
  }
  if(mirror_xy_flag) {
    printf("Mirroring about the xy plane...\n");
    stl_mirror_xy(&stl_in);
  }
  if(mirror_yz_flag) {
    printf("Mirroring about the yz plane...\n");
    stl_mirror_yz(&stl_in);
  }
  if(mirror_xz_flag) {
    printf("Mirroring about the xz plane...\n");
    stl_mirror_xz(&stl_in);
  }

  if(scale_flag) {
    printf("Scaling by factor %f...\n", scale_factor);
    stl_scale(&stl_in, scale_factor);
  }
  if(translate_flag) {
    printf("Translating to %f, %f, %f ...\n", x_trans, y_trans, z_trans);
    stl_translate(&stl_in, x_trans, y_trans, z_trans);
  }
  if(merge_flag) {
    printf("Merging %s with %s\n", input_file, merge_name);
    /* Open the file and add the contents to stl_in: */
    stl_open_merge(&stl_in, merge_name);
  }

  stl_repair(&stl_in,
             fixall_flag,
             exact_flag,
             tolerance_flag,
             tolerance,
             increment_flag,
             increment,
             nearby_flag,
             iterations,
             remove_unconnected_flag,
             fill_holes_flag,
             normal_directions_flag,
             normal_values_flag,
             reverse_all_flag,
             1);


  if(generate_shared_vertices_flag) {
    printf("Generating shared vertices...\n");
    stl_generate_shared_vertices(&stl_in);
  }

  if(write_off_flag) {
    printf("Writing OFF file %s\n", off_name);
    stl_write_off(&stl_in, off_name);
    if (stl_in.error) {
      stl_clear_error(&stl_in);
      ret = 1;
    }
  }

  if(write_dxf_flag) {
    printf("Writing DXF file %s\n", dxf_name);
    stl_write_dxf(&stl_in, dxf_name, "Created by ADMesh version " VERSION);
    if (stl_in.error) {
      stl_clear_error(&stl_in);
      ret = 1;
    }
  }

  if(write_vrml_flag) {
    printf("Writing VRML file %s\n", vrml_name);
    stl_write_vrml(&stl_in, vrml_name);
    if (stl_in.error) {
      stl_clear_error(&stl_in);
      ret = 1;
    }
  }

  if(write_ascii_stl_flag) {
    printf("Writing ascii file %s\n", ascii_name);
    stl_write_ascii(&stl_in, ascii_name,
                    "Processed by ADMesh version " VERSION);
    if (stl_in.error) {
      stl_clear_error(&stl_in);
      ret = 1;
    }
  }

  if(write_binary_stl_flag) {
    printf("Writing binary file %s\n", binary_name);
    stl_write_binary(&stl_in, binary_name,
                     "Processed by ADMesh version " VERSION);
    if (stl_in.error) {
      stl_clear_error(&stl_in);
      ret = 1;
    }
  }

  stl_stats_out(&stl_in, stdout, input_file);

  stl_close(&stl_in);

  if (ret)
    fprintf(stderr, "Some part of the procedure failed, see the above log for more information about what happened.\n");

  return ret;
}