std::vector<Point> poisson_sample(double height, double width, int new_points_count, double octaves, double persistence, double scale, double low, double high, double seed) {
  double cellsize = high / sqrt(2.0);
  Grid<Point> grid(ceil(height / cellsize), ceil(width / cellsize));
  RandomQueue<Point> processing_list;
  std::vector<Point> output_list;
  Point p, q;
  double min_dist;

  Point first(random_real(height), random_real(width));
  processing_list.push(first);
  output_list.push_back(first);

  grid.add(image_to_grid(first, cellsize), first);

  while (!processing_list.empty()) {
    p = processing_list.pop();
    for (int i = 0; i < new_points_count; ++i) {
      q = generateRandomPointAround(p, min_dist);
      min_dist = scaled_octave_noise(octaves, persistence, scale, low, high, q.x, q.y, seed);
      if (in_rectangle(height, width, q) && !in_neighborhood(grid, q, min_dist, cellsize, height, width)) {
        processing_list.push(q);
        output_list.push_back(q);
        grid.add(image_to_grid(q, cellsize), q);
      }
    }
  }

  return output_list;
}
Example #2
0
gr_selections
box_rep::graphical_select (SI x1, SI y1, SI x2, SI y2) {
  gr_selections res;
  if (in_rectangle (x1, y1, x2, y2)) {
    gr_selection gs;
    gs->type= "box";
    gs->dist= graphical_distance (x1, y1);
    SI dist= (SI)norm (point (x2-x1, y2-y1));
    gs->cp << find_tree_path (x1, y1, dist);
    // FIXME: as above, check whether this is correct or not
    gs->pts= array<point> (0);
    gs->c= curve ();
    res << gs;
  }
  return res;
}