File: hilbert_sort.cpp

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (68 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download | duplicates (4)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2005-2009  INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Sebastien Loriot, Sylvain Pion

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/hilbert_sort.h>
#include <CGAL/CGAL_Ipelet_base.h>

// --------------------------------------------------------------------


namespace CGAL_hilbert_sort{

typedef CGAL::Exact_predicates_inexact_constructions_kernel               Kernel;

const std::string sublabel[] ={
  "Hilbert sorting curve", "Help"
};

const std::string helpmsg[] = {
  "Sort the points along a Hilbert curve"
};

struct hilbertsortIpelet
  : CGAL::Ipelet_base<Kernel,2>
{
  hilbertsortIpelet()
    : CGAL::Ipelet_base<Kernel,2>("Hilbert sort",sublabel, helpmsg) {}

  void protected_run(int);
};


void hilbertsortIpelet::protected_run(int fn)
{
  if (fn==2) {
    show_help();
    return;
  }



  std::vector<Point_2> pt_list;

  read_active_objects( CGAL::dispatch_or_drop_output<Point_2>( std::back_inserter(pt_list) ) );

  if (pt_list.empty()) {
    print_error_message("No mark selected");
    return;
  }

  if (fn==0) CGAL::hilbert_sort(pt_list.begin(), pt_list.end());
  else       CGAL::hilbert_sort(pt_list.begin(), pt_list.end(), CGAL::Hilbert_sort_middle_policy());

  draw_polyline_in_ipe(pt_list.begin(), pt_list.end());
}

}

CGAL_IPELET(CGAL_hilbert_sort::hilbertsortIpelet)