virtual void go() {
        release();
        param *p = param::instance();
        update_values(p);

        Iso_rectangle_2 bbox = get_bbox(p);
        std::string ndvi_file = p->get<boost::filesystem::path>("ndvi").string();
        std::string  dsm_file = p->get<boost::filesystem::path>("dsm" ).string();
        clip_bbox(bbox,ndvi_file);
        clip_bbox(bbox,dsm_file );

        gradient_functor gf(p->get<double>("sigmaD"));
        oriented_gradient_view grad_view(dsm_file,  bbox, gf);
        oriented_ndvi_view     ndvi_view(ndvi_file, bbox);

        m_confg_visitor->add_layer(ndvi_file);
        m_confg_visitor->add_layer(dsm_file);
        set_bbox(p,bbox);
        wxPoint p0(wxCoord(bbox.min().x()),wxCoord(bbox.min().y()));
        wxPoint p1(wxCoord(bbox.max().x()),wxCoord(bbox.max().y()));
        m_confg_visitor->set_bbox(wxRect(p0,p1));

        init_visitor        (p,*m_visitor);
        create_configuration(p,grad_view,ndvi_view,m_config);
        create_sampler      (p,m_sampler);
        create_schedule     (p,m_schedule);
        create_end_test     (p,m_end_test);

        m_thread = new boost::thread(
                simulated_annealing::optimize<configuration,sampler,schedule,end_test,visitor>,
                boost::ref(*m_config), boost::ref(*m_sampler),
                boost::ref(*m_schedule), boost::ref(*m_end_test),
                boost::ref(*m_visitor) );
    }
Beispiel #2
0
int main()
{
  Iso_rectangle_2 bounding_box(Point_2(0, 0), Point_2(10, 10));

  Largest_empty_iso_rect_2 leir(bounding_box);
  leir.insert(Point_2(6,1));
  leir.insert(Point_2(1,8));
  leir.insert(Point_2(9,5));
  leir.insert(Point_2(5,9));

  std::cout << "The input bounding box is " << bounding_box << std::endl;

  std::cout << "The input point set is:" << std::endl;
  for(Largest_empty_iso_rect_2::const_iterator it = leir.begin();
      it != leir.end();
      ++it){
    const Point_2& p = *it;
    std::cout << "   " << p << std::endl;
  }

  Iso_rectangle_2 b = leir.get_largest_empty_iso_rectangle();

  std::cout << std::endl << "The largest empty iso rectangle is " <<
               b << std::endl;
  std::cout << "Its area is " << b.area() << std::endl;

  return 0;
}
void
MainWindow::on_actionInsertRandomPoints_triggered()
{
  QRectF rect = CGAL::Qt::viewportsBbox(&scene);
  CGAL::Qt::Converter<K> convert;  
  Iso_rectangle_2 isor = convert(rect);
  CGAL::Random_points_in_iso_rectangle_2<Point_2> pg(isor.min(), isor.max());
  bool ok = false;
  const int number_of_points = 
    QInputDialog::getInteger(this, 
                             tr("Number of random points"),
                             tr("Enter number of random points"),
			     100,
			     0,
			     std::numeric_limits<int>::max(),
			     1,
			     &ok);

  if(!ok) {
    return;
  }

  // wait cursor
  QApplication::setOverrideCursor(Qt::WaitCursor);
  std::vector<Point_2> points;
  points.reserve(number_of_points);
  for(int i = 0; i < number_of_points; ++i){
    points.push_back(*pg++);
  }
  dt.insert(points.begin(), points.end());
  // default cursor
  QApplication::restoreOverrideCursor();
  emit(changed());
}
    //[building_footprint_rectangle_gilviewer_go
    virtual void process()
    {
        OnInit();
        release();
        update_values(m_param);

        Iso_rectangle_2 bbox = get_bbox(m_param);
        std::string  dsm_file = m_param->get<boost::filesystem::path>("dsm"  ).string();
        std::string mask_file = m_param->get<boost::filesystem::path>("mask" ).string();
        clip_bbox(bbox,dsm_file );

        gradient_functor gf(m_param->get<double>("sigmaD"));
        oriented_gradient_image grad_image(dsm_file,  bbox, gf);
        m_grad = grad_image.img();

        load_image(dsm_file );
        load_image(mask_file);

        set_bbox(m_param,bbox);
        wxPoint p0(wxCoord(bbox.min().x()),wxCoord(bbox.min().y()));
        wxPoint p1(wxCoord(bbox.max().x()),wxCoord(bbox.max().y()));
        m_confg_visitor->set_bbox(wxRect(p0,p1));

        init_visitor        (m_param,m_visitor);
        create_configuration(m_param,grad_image,m_config);
        //<-
        //    estimate_initial_temperature(m_param,100,*m_config);
        //->
        create_sampler      (m_param,m_sampler);
        create_schedule     (m_param,m_schedule);
        create_end_test     (m_param,m_end_test);

        //    std::cout << "Salamon initial schedule : " << salamon_initial_schedule(m_sampler->density(),*m_config,1000) << std::endl;
        //    m_config->clear();

        any_sampler *sampler = new any_sampler(*m_sampler);
        Engine& e = rjmcmc::random();

        m_thread = new boost::thread(
                simulated_annealing::optimize<Engine,configuration,any_sampler,schedule,end_test,any_composite_visitor>,
                e, boost::ref(*m_config), boost::ref(*sampler),
                boost::ref(*m_schedule),   boost::ref(*m_end_test),
                boost::ref(m_visitor) );
    }
Beispiel #5
0
  void
  on_actionGenerate_triggered()
  {
    QRectF rect = CGAL::Qt::viewportsBbox(&scene);
    CGAL::Qt::Converter<K> convert;  
    Iso_rectangle_2 isor = convert(rect);
    Point_2 center = CGAL::midpoint(isor[0], isor[2]);
    Vector_2 offset = center - CGAL::ORIGIN;
    double w = isor.xmax() - isor.xmin();
    double h = isor.ymax() - isor.ymin();
    double radius = (w<h) ? w/2 : h/2;

    G pg(radius);
    bool ok = false;
    const int number_of_points = 
      QInputDialog::getInteger(this, 
                               tr("Number of random points"),
                               tr("Enter number of random points"),
                               100,
                               0,
                               (std::numeric_limits<int>::max)(),
                               1,
                               &ok);

    if(!ok) {
      return;
    }

    // wait cursor
    QApplication::setOverrideCursor(Qt::WaitCursor);

    points.reserve(points.size() + number_of_points);
    for(int i = 0; i < number_of_points; ++i){
      points.push_back(*pg + offset);
      ++pg;
    }
    // default cursor
    QApplication::restoreOverrideCursor();
    Q_EMIT( changed());
  }
void
MainWindow::on_actionInsertRandomPoints_triggered()
{
  QRectF rect = CGAL::Qt::viewportsBbox(&scene);
  CGAL::Qt::Converter<K> convert;  
  Iso_rectangle_2 isor = convert(rect);
  double width = isor.xmax() - isor.xmin();
  
  CGAL::Random_points_in_iso_rectangle_2<Point_2> pg(isor.min(), isor.max());
  bool ok = false;
  const int number_of_points = 
    QInputDialog::getInteger(this, 
                             tr("Number of random points"),
                             tr("Enter number of random points"),
			     100,
			     0,
			     std::numeric_limits<int>::max(),
			     1,
			     &ok);

  if(!ok) {
    return;
  }

  // wait cursor
  QApplication::setOverrideCursor(Qt::WaitCursor);
  std::vector<Apollonius_site_2> points;
  points.reserve(number_of_points);
  boost::rand48 rng;
  boost::uniform_real<> dist(0.005*width, 0.05*width);
  boost::variate_generator<boost::rand48&, boost::uniform_real<> > radius(rng,dist);

  for(int i = 0; i < number_of_points; ++i){
    points.push_back(Apollonius_site_2(*pg++,radius()));
  }
      ag.insert(points.begin(), points.end());
  // default cursor
  QApplication::restoreOverrideCursor();
  emit(changed());
}
Beispiel #7
0
SiteList createArtificialSites(SiteList& sites, Iso_rectangle_2 crect)
{
  SiteList artificialSites;
  // add artificial sites
  SiteList::iterator itr;
  for (itr = sites.begin(); itr != sites.end(); ++itr) {
    Site_2 site = *itr;
    Point_2 point = site.point();
    double weight = site.weight();
    Point_2 apoint1(2 * crect.xmin() - point.x(), point.y());
    Site_2 asite1(apoint1, weight);
    Point_2 apoint2(2 * crect.xmax() - point.x(), point.y());
    Site_2 asite2(apoint2, weight);
    Point_2 apoint3(point.x(), 2 * crect.ymin() - point.y());
    Site_2 asite3(apoint3, weight);
    Point_2 apoint4(point.x(), 2 * crect.ymax() - point.y());
    Site_2 asite4(apoint4, weight);
    artificialSites.push_back(asite1);
    artificialSites.push_back(asite2);
    artificialSites.push_back(asite3);
    artificialSites.push_back(asite4);
  }
  return artificialSites;
}
Beispiel #8
0
/*
 * create a rectangle based on the specifed one, but enlarge it by amount
 */
Iso_rectangle_2 extend(Iso_rectangle_2 rect, double amount)
{
  Iso_rectangle_2 r(rect.xmin()-amount, rect.ymin()-amount,
      rect.xmax()+amount, rect.ymax()+amount);
  return r;
}
Beispiel #9
0
int main(int argc , char* argv[])
{
  if (argc < 7) {
    std::cerr << "usage: test <input file> <output folder> "
      "<format (wkt | geojson | sql)> <weight city> <weight town> <weight village>" << std::endl;
    exit(1);
  }

  char* input = argv[1];
  char* outdir = argv[2];
  char* format = argv[3];

  char* swc = argv[4];
  char* swt = argv[5];
  char* swv = argv[6];

  std::ifstream ifs(input);
  assert( ifs );

  double wc, wt, wv;
  std::istringstream stmc, stmt, stmv;
  stmc.str(swc);
  stmc >> wc;
  stmt.str(swt);
  stmt >> wt;
  stmv.str(swv);
  stmv >> wv;

  std::cerr << "using weights: city: " << wc << ", town: " << wt << ", village: " << wv << std::endl;

  /*
   * prepare data
   */

  // we use a ScalingFactor(SF) here to stretch input values at the
  // beginning, and divide by SF in the end. This is used because the
  // point-generation of the hyperbola class is using some arbitrary
  // internal decision thresholds to decide how many points to generate for
  // a certain part of the curve. Rule of thumb is: the higher SF the more
  // detail is used in approximation of the hyperbolas.
  double SF = 4000;

  // read in sites from input file
  SiteList sites = readSites(ifs, SF, wc, wt, wv);

  printSites(sites);

  // calculate bounding box of all input sites (and extend it a little).
  // Extension is important, because we later add artificial sites which are
  // actually mirrored on the bounds of this rectangle. If we did not extend
  // some points would lie on the boundary of the bounding box and so would
  // their artificial clones. This would complicate the whole stuff a lot :)
  Iso_rectangle_2 crect = extend(boundingBox(sites), 0.1*SF);
  std::cerr << "rect: " << crect << std::endl;

  // a number of artificial sites
  SiteList artificialSites = createArtificialSites(sites, crect);

  /*
   * create Apollonius graph
   */

  Apollonius_graph ag;

  SiteList::iterator itr;
  // add all original sites to the apollonius graph
  for (itr = sites.begin(); itr != sites.end(); ++itr) {
    Site_2 site = *itr;
    ag.insert(site);
  }
  // add all artificial sites to the apollonius graph
  for (itr = artificialSites.begin(); itr != artificialSites.end(); ++itr) {
    Site_2 site = *itr;
    ag.insert(site);
  }

  // validate the Apollonius graph
  assert( ag.is_valid(true, 1) );
  std::cerr << std::endl;

  /*
   * create polygons from cells
   */

  // we want an identifier for each vertex within the iteration.
  // this is a loop iteration counter
  int vertexIndex = 0;

  // for each vertex in the apollonius graph (this are the sites)
  for (All_vertices_iterator viter = ag.all_vertices_begin ();
      viter != ag.all_vertices_end(); ++viter) {
    // get the corresponding site
    Site_2 site = viter->site();
    Point_2 point = site.point();
    // ignore artifical sites, detect them by their position
    if (!CGAL::do_intersect(crect, point)) {
      continue;
    }
    std::cerr << "vertex " << ++vertexIndex << std::endl;

    // we than circulate all incident edges. By obtaining the respective
    // dual of each edge, we get access to the objects forming the boundary
    // of each voronoi cell in a proper order.
    Edge_circulator ecirc = ag.incident_edges(viter), done(ecirc);
    // this is where we store the polylines
    std::vector<PointList> polylines;
    // for each incident edge
    do {
      // the program may fail in certain situations without this test.
      // acutally !is_infinite(edge) is a precondition in ag.dual(edge).
      if (ag.is_infinite(*ecirc)) {
        continue;
      }
      // NOTE: for this to work, we had to make public the dual function in ApolloniusGraph
      // change line 542 in "Apollonius_graph_2.h" from "private:" to "public:"
      Object_2 o = ag.dual(*ecirc);
      handleDual(o, crect, polylines);
    } while(++ecirc != done);

    PointList polygon = buildPolygon(site, polylines);
    for (int i = 0; i < polygon.size(); i++) {
      Point_2& p = polygon.at(i);
      p = Point_2(p.x()/SF, p.y()/SF);
    }
    if(std::string(format) == "geojson") {
      writeGeoJSON(site, polygon, outdir);
    } else if(std::string(format) == "sql") {
      writeSQL(site, polygon, outdir);
    } else {
      writeWKT(site, polygon, outdir);
    }

    // check each point
    for (int i = 0; i < polygon.size(); i++) {
      Point_2 p = polygon.at(i);
      if (p.x() > crect.xmax()/SF || p.x() < crect.xmin()/SF || p.y() > crect.ymax()/SF || p.y() < crect.ymin()/SF) {
        std::cerr << "out of bounds" << std::endl;
      }
    }
  }
}