Example #1
0
int main() {

  const int N = 30;
  Tree tree;
  Random_points_iterator rpg;
  for(int i = 0; i < N; i++){
    tree.insert(*rpg++);
  }

  // fuzziness = 0

  // Note that a fuzziness of 0 does not imply that we can gather exactly all the
  // points within the disk: even with eps=0, the border is a fuzzy zone.
  Point_d center(0., 0.);
  Fuzzy_circle default_range(center, 0.5);

  std::list<Point_d> result;
  tree.search(std::back_inserter( result ), default_range);

  std::cout << "The points in the fuzzy circle centered at (0., 0.) ";
  std::cout << "with fuzzy radius (0.5, 0.5) are: " << std::endl;
  std::copy (result.begin(),result.end(),std::ostream_iterator<Point_d>(std::cout,"\n") );
  std::cout << std::endl;


  // approximate range searching using value 0.4 for fuzziness parameter
  // We do not write into a list but directly in the outpout stream

  std::cout << "The points in the fuzzy circle centered at (0., 0.) ";
  std::cout << "with fuzzy radius (0.1, 0.9) are: " << std::endl;
  Fuzzy_circle approximate_range(center, 0.5, 0.4);
  tree.search(std::ostream_iterator<Point_d>(std::cout,"\n"), approximate_range);

  return 0;
}
int
main() {
  const size_t N = 1000;

  std::list<Point_d> points;
  points.push_back(Point_d(0,0));

  Tree tree;
  Random_points_iterator rpg;

  //inserting N points one-by-one, thus the use of "reserve" is recommended, and we use it
  tree.reserve(N);

  //to test wether the tree.capacity() function works properly.
  if( tree.capacity() < N)
  {
    std::cerr << "ERROR: Something is wrong with allocating points memory." << std::endl;
    return -1;
  }

  for(size_t i = 0; i < N; i++)
  {
    tree.insert(*rpg++);
  }

  std::list<Point_d> result;

  // define range query
  Point_d p(0.2, 0.2);
  Point_d q(0.7, 0.7);

  // Searching an exact range
  // using default value 0.0 for epsilon fuzziness parameter
  // Fuzzy_box exact_range(r); replaced by
  Fuzzy_iso_box exact_range(p,q);
  std::cout << "tree.search(..)" << std::endl;
  //tree.report_all_points(std::ostream_iterator<Point>(std::cout,"\n"));
  tree.search( std::back_inserter( result ), exact_range);

  std::cout << "The points in the box [0.2,0.7]x[0.2,0.7] are: " << std::endl;
  std::copy (result.begin(), result.end(), std::ostream_iterator<Point_d>(std::cout,"\n") );
  std::cout << std::endl;

  result.clear();
  // Searching a fuzzy range
  // using value 0.1 for fuzziness paramater
  Fuzzy_iso_box approximate_range(p, q, 0.1);
  tree.search(std::back_inserter( result ), approximate_range);
  std::cout << "The points in the fuzzy box [<0.1-0.3>,<0.6-0.9>]x[<0.1-0.3>,<0.6-0.9>] are: "
            << std::endl;
  std::copy (result.begin(), result.end(), std::ostream_iterator<Point_d>(std::cout,"\n") );
  std::cout << std::endl;
  return 0;
}
int main() {

  const int N=1000;

  // generator for random data points in the square ( (-1,-1), (1,1) )
  Random rnd(0);
  Random_points_iterator rpit(1.0, rnd);

  // Insert also the N points in the tree
  Tree tree(N_Random_points_iterator(rpit,0),
			      N_Random_points_iterator(N));

  // define exact circular range query
  Point center(0.2, 0.2);
  Fuzzy_circle exact_range(center, 0.2);

  std::list<Point> result;
  tree.search(std::back_inserter( result ), exact_range);

  std::cout << "\nPoints in cirle with center " << center << " and radius 0.2" << std::endl;

  std::list<Point>::iterator it;
  for (it=result.begin(); (it != result.end()); ++it) {
    std::cout << *it << std::endl;
  }

  result.clear();
  // approximate range searching using value 0.1 for fuzziness parameter
  Fuzzy_circle approximate_range(center, 0.2, 0.1);

  tree.search(std::back_inserter( result ), approximate_range);

  std::cout << "\n\nPoints in cirle with center " << center << " and fuzzy radius [0.1,0.3]" << std::endl;

  for (it=result.begin(); (it != result.end()); ++it) {
    std::cout << *it << std::endl;
  }
  std::cout << "\ndone" << std::endl;
  return 0;
}
Example #4
0
int
main() {
  const int N = 1000;

  std::list<Point_d> points;
  points.push_back(Point_d(0,0));

  Tree tree;
  Random_points_iterator rpg;
  for(int i = 0; i < N; i++){
    tree.insert(*rpg++);
  }

  std::list<Point_d> result;

  // define range query
  Point_d p(0.2, 0.2);
  Point_d q(0.7, 0.7);

  // Searching an exact range
  // using default value 0.0 for epsilon fuzziness paramater
  Fuzzy_iso_box exact_range(p,q);
  tree.search( std::back_inserter( result ), exact_range);
  std::cout << "The points in the box [0.2, 0.7]^2 are: " << std::endl;
  std::copy (result.begin(), result.end(), std::ostream_iterator<Point_d>(std::cout,"\n") );
  std::cout << std::endl;

  result.clear();

  // Searching a fuzzy range
  // using value 0.1 for fuzziness paramater
  Fuzzy_iso_box approximate_range(p, q, 0.1);
  tree.search(std::back_inserter( result ), approximate_range);
  std::cout << "The points in the fuzzy box [[0.1, 0.3], [0.6, 0.9]]^2 are: " << std::endl;
  std::copy (result.begin(), result.end(), std::ostream_iterator<Point_d>(std::cout,"\n") );
  std::cout << std::endl;
  return 0;
}
Example #5
0
void run_with_fuzziness(std::list<Point> all_points,
                        const Point& p, const Point& q,
                        const FT fuzziness,
                        CGAL::Random& rnd)
{
  typedef CGAL::Fuzzy_iso_box<SearchTraits> Fuzzy_box;

  std::cout << "test with box: [" << p << " || " << q << "] and eps: " << fuzziness << "... ";

  // test the results of the approximate query
  Iso_rectangle inner_ic(p + fuzziness*Vector(1,1), q - fuzziness*Vector(1,1));
  Iso_rectangle outer_ic(p - fuzziness*Vector(1,1), q + fuzziness*Vector(1,1));

  // If the fuziness is greater than half of the largest dimension of the box,
  // then the inner box does not exist
  const FT max_box_edge_length = (std::max)(q[1] - p[1], q[0] - p[0]);
  const bool is_inner_c_empty = (fuzziness > 0.5 * max_box_edge_length);
  if(is_inner_c_empty)
    std::cout << " (empty inner box)... ";

  // Insert a bunch of points on the boundary of the inner approximation
  std::size_t N = all_points.size();

  if(!is_inner_c_empty)
  {
    for(std::size_t i=0, max=N/10; i<max; ++i)
    {
      double x = rnd.get_double(-1., 1.);
      all_points.push_back(Point(x, p.y() + fuzziness));
      all_points.push_back(Point(p.x() + fuzziness, x));
    }
  }

  // same for the outer boundary
  for(std::size_t i=0, max=N/10; i<max; ++i)
  {
    double x = rnd.get_double(-1., 1.);
    all_points.push_back(Point(x, q.y() + fuzziness));
    all_points.push_back(Point(q.x() + fuzziness, x));
  }

  // Insert also the N points in the tree
  CGAL::Kd_tree<SearchTraits> tree(
    boost::make_transform_iterator(all_points.begin(), Create_point_with_info<typename SearchTraits::Point_d>()),
    boost::make_transform_iterator(all_points.end(), Create_point_with_info<typename SearchTraits::Point_d>())
  );

  tree.search(CGAL::Emptyset_iterator(), Fuzzy_box(p,q)); //test compilation when Point != Traits::Point_d

  typename SearchTraits::Point_d pp(p);
  typename SearchTraits::Point_d qq(q);

  // approximate range searching
  std::list<typename SearchTraits::Point_d> result;
  Fuzzy_box approximate_range(pp, qq, fuzziness);
  tree.search(std::back_inserter(result), approximate_range);
  std::cout << result.size() << " hits... Verifying correctness...";

  for (typename std::list<typename SearchTraits::Point_d>::iterator pt=result.begin(); (pt != result.end()); ++pt)
  {
    // a point can only be reported if it is in the outer box
    bool is_correct = outer_ic.has_on_bounded_side(get_point(*pt)) || outer_ic.has_on_boundary(get_point(*pt));
    if(!is_correct)
      std::cout << get_point(*pt) << " should have not been reported" << std::endl;
    assert(is_correct);
    all_points.remove(get_point(*pt));
  }

  // nothing to test if the inner box is empty because everything is on the unbounded side
  if(!is_inner_c_empty)
  {
    for (std::list<Point>::iterator pt=all_points.begin(); (pt != all_points.end()); ++pt)
    {
      // all points that have not been reported must be outside the inner box
      bool is_correct = inner_ic.has_on_unbounded_side(*pt);
      if(!is_correct)
        std::cout << *pt << " should have been reported" << std::endl;

      assert(is_correct);
    }
  }

  std::cout << "done" << std::endl;
}