File: scale_estimation_2d_example.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (51 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/estimate_scale.h>
#include <CGAL/Random.h>

#include <vector>
#include <fstream>

// Types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_2 Point_2;

int main (int, char**)
{
  std::vector<Point_2> samples;
  samples.reserve (100000);

  // Generate circle with gradually variable noise
  //  - noise-free for points with x close to (-1)
  //  - noisy for points with x close to (+1)
  for (std::size_t i = 0; i < 100000; ++ i)
    {
      FT theta = CGAL::get_default_random().get_double(0, 2. * CGAL_PI);
      FT noise = 0.5 * (std::cos(theta) + 1.) * CGAL::get_default_random().get_double(0., 0.2);
      int mult = (CGAL::get_default_random().get_bool() ? 1 : -1);
      samples.push_back (Point_2 (std::cos(theta) * (1. + mult * noise * noise),
                                  std::sin(theta) * (1. + mult * noise * noise)));
    }

  // Search for local scales on 3 different locations
  std::vector<Point_2> queries;
  queries.reserve (3);
  queries.push_back (Point_2 (-1., 0.));
  queries.push_back (Point_2 (0., 1.));
  queries.push_back (Point_2 (1., 0.));

  std::vector<std::size_t> k_scales;
  CGAL::estimate_local_k_neighbor_scales (samples,
                                          queries,
                                          std::back_inserter (k_scales));

  // Display results
  std::cerr << "K-Scales found:" << std::endl
            << " - On noise-free region: " << k_scales[0] << std::endl // Should be small
            << " - On moderately noisy region: " << k_scales[1] << std::endl // Should be higher
            << " - On very noisy region: " << k_scales[2] << std::endl; // Should be even higher

  return EXIT_SUCCESS;
}