Ejemplo n.º 1
0
int main() {

  std::cout.precision(17);

  Point_3 p;
  std::vector<Point_3> points;

  while(std::cin >> p){
    points.push_back(p);
  }

  CGAL::Bbox_3 bb = CGAL::bounding_box(points.begin(), points.end()).bbox();
  double dx = bb.xmax() - bb.xmin();
  double dy = bb.ymax() - bb.ymin();
  double dz = bb.zmax() - bb.zmin();
  
  for(int i = 0; i < points.size(); i++){
    double  rx  = CGAL::default_random.get_double();
    double  ry  = CGAL::default_random.get_double();
    double  rz  = CGAL::default_random.get_double();
    std::cout << bb.xmin() + dx * rx << " ";
    std::cout << bb.ymin() + dy * ry << " ";
    std::cout << bb.zmin() + dz * rz << std::endl;
  } 
  
  return 0;
}
Ejemplo n.º 2
0
Point Scene::random_point(const CGAL::Bbox_3& bbox)
{
    FT x = random_in(bbox.xmin(),bbox.xmax());
    FT y = random_in(bbox.ymin(),bbox.ymax());
    FT z = random_in(bbox.zmin(),bbox.zmax());
    return Point(x,y,z);
}
void random_points(char* fname, CGAL::Bbox_3 bbox, int n)
{
  std::cerr << "Write " << n << " points to file " << fname << std::endl;
  CGAL::Random rg;

  double grid_dx = bbox.xmax() - bbox.xmin();
  double grid_dy = bbox.ymax() - bbox.ymin();
  double grid_dz = bbox.zmax() - bbox.zmin();
  
  std::ofstream out(fname);
  out.precision(16);
  for(int i=0; i < n; i++){
    out << bbox.xmin() + rg.get_double()* grid_dx << " " 
        << bbox.ymin() + rg.get_double()* grid_dy << " "
        << bbox.zmin() + rg.get_double()* grid_dz << std::endl;
  }
  out.close();
}
typename K::Point_3 random_point_in(const CGAL::Bbox_3& bbox)
{
  typedef typename K::FT FT;
  FT x = (FT)random_in(bbox.xmin(),bbox.xmax());
  FT y = (FT)random_in(bbox.ymin(),bbox.ymax());
  FT z = (FT)random_in(bbox.zmin(),bbox.zmax());
  return typename K::Point_3(x,y,z);
}
Ejemplo n.º 5
0
void
Viewer::sceneChanged()
{
    CGAL::Bbox_3 bb = bbox();

    this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(),
                                        bb.ymin(),
                                        bb.zmin()),
                                        qglviewer::Vec(bb.xmax(),
                                                bb.ymax(),
                                                bb.zmax()));

    this->showEntireScene();
}
 Bbox bbox() const {
     if(isEmpty())
         return Bbox();
     else {
         CGAL::Bbox_3 result = c3t3().triangulation().finite_vertices_begin()->point().bbox();
         for(Tr::Finite_vertices_iterator
             vit = ++c3t3().triangulation().finite_vertices_begin(),
             end = c3t3().triangulation().finite_vertices_end();
             vit != end; ++vit)
         {
             result = result + vit->point().bbox();
         }
         return Bbox(result.xmin(), result.ymin(), result.zmin(),
                     result.xmax(), result.ymax(), result.zmax());
     }
 }
Ejemplo n.º 7
0
void Scene_c3t3_item::compute_bbox() const {
  if (isEmpty())
    _bbox = Bbox();
  else {
    CGAL::Bbox_3 result;
    for (Tr::Finite_vertices_iterator
           vit = ++c3t3().triangulation().finite_vertices_begin(),
           end = c3t3().triangulation().finite_vertices_end();
         vit != end; ++vit)
    {
      if(vit->in_dimension() == -1) continue;
      result = result + vit->point().bbox();
    }
    _bbox = Bbox(result.xmin(), result.ymin(), result.zmin(),
                 result.xmax(), result.ymax(), result.zmax());
  }
}
Ejemplo n.º 8
0
void Scene_c3t3_item::compute_bbox() const {
  if (isEmpty())
    _bbox = Bbox();
  else {
    CGAL::Bbox_3 result =
      c3t3().cells_in_complex_begin()->vertex(0)->point().bbox();
    for (C3t3::Cells_in_complex_iterator
      cit = ++c3t3().cells_in_complex_begin(),
      cend = c3t3().cells_in_complex_end();
      cit != cend; ++cit)
    {
      result = result + cit->vertex(0)->point().bbox();
      //only one vertex should be a satisfactory approximation
    }
    _bbox = Bbox(result.xmin(), result.ymin(), result.zmin(),
                 result.xmax(), result.ymax(), result.zmax());
  }
}
Ejemplo n.º 9
0
// main function with standard unix commandline arguments
// ------------------------------------------------------
int main( int argc, char **argv) {
    int n = 0; // number of filenames
    char *filename[1] = { NULL }; // stop compiler warning (too hard to rewrite the code to avoid it)
    bool help = false;
    for (int i = 1; i < argc; i++) { // check commandline options
        if ( strcmp( "-v", argv[i]) == 0)
            verbose = true;
        else if ( strcmp( "-unit", argv[i]) == 0)
            unitcube = true;
        else if ( (strcmp( "-h", argv[i]) == 0) ||
                  (strcmp( "-help", argv[i]) == 0))
            help = true;
        else if ( n < 1 ) {
            filename[ n++] = argv[i];
        } else {
	    n++;
            break;
	}
    }
    if ((n > 1) || help) {
        if ( ! help)
            cerr << "Error: in parameter list" << endl;
        cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
             << endl;
        cerr << "Usage: " << argv[0] << " [<options>] [<infile>]" << endl;
        cerr << "       computes the bbox of the coordinates of an OFF object."
             << endl;
        cerr << "       -unit     prints transformation to unit cube." << endl;
        cerr << "                 (can be used with 'off_transform')" << endl;
        cerr << "       -v      verbose." << endl;
        exit( ! help);
    }

    CGAL::Verbose_ostream verr( verbose);
    verr << argv[0] << ": verbosity on." << endl;

    const char*  name = "cin";
    istream*     p_in = &cin;
    ifstream     in;
    if ( n > 0) {
        in.open( filename[0]);
        p_in = &in;
        name = filename[0];
    }
    if ( ! * p_in) {
        cerr << argv[0] << ": error: cannot open file '"<< name
         << "' for reading." <<endl;
        exit( 1);
    }

    verr << "CGAL::File_scanner_OFF( " << name << ") ...." << endl;
    CGAL::File_scanner_OFF scanner( * p_in);
    if ( ! * p_in) {
        cerr << argv[0] << ": error: file '"<< name
         << "' is not in OFF format." << endl;
        std::abort();
    }
    if ( scanner.size_of_vertices() <= 0) {
        cerr << argv[0] << ": error: file '"<< name
         << "' has no vertices." << endl;
        std::abort();
    }
    size_t  v = scanner.size_of_vertices();
    CGAL::Bbox_3 bbox;
    double x, y, z;
    scanner.scan_vertex( x, y, z);
    bbox = CGAL::Bbox_3( x,y,z, x,y,z);
    v--;
    while (v--) {
        scanner.scan_vertex( x, y, z);
        bbox = bbox + CGAL::Bbox_3( x,y,z, x,y,z);
        scanner.skip_to_next_vertex( scanner.size_of_vertices() - v - 1);
    }
    verr << ".... done." << scanner.size_of_vertices() << " points read."
         << endl;

    if ( !in) {
        cerr << argv[0] << " read error: while reading file '"<< name << "'."
             << endl;
        exit( 1);
    }
    if ( ! unitcube) {
        cout << bbox.xmin() << "  " << bbox.ymin() << "  " << bbox.zmin()
             << '\n';
        cout << bbox.xmax() << "  " << bbox.ymax() << "  " << bbox.zmax()
             << endl;
    } else {
        double s = DBL_MAX;
        double d = bbox.xmax() - bbox.xmin();
        if ( d > 0 && 2/d < s)
            s = 2/d;
        d = bbox.ymax() - bbox.ymin();
        if ( d > 0 && 2/d < s)
            s = 2/d;
        d = bbox.zmax() - bbox.zmin();
        if ( d > 0 && 2/d < s)
            s = 2/d;
        if ( s == DBL_MAX)
            s = 1;
        cout << "-trans  " << (-(bbox.xmin() + bbox.xmax())/2)
             << "  "       << (-(bbox.ymin() + bbox.ymax())/2)
             << "  "       << (-(bbox.zmin() + bbox.zmax())/2)
             << "  -scale  " << s << endl;
    }
    return 0;
}