mirror of https://github.com/CGAL/cgal
Big changes.
- brio_sort is now called spatial_sort. - global functions now have the same names in 2D and 3D.
This commit is contained in:
parent
d6748af3a3
commit
4e28b57a64
|
|
@ -1445,13 +1445,15 @@ Spatial_searching/demo/Spatial_searching/spatial_searching.vcproj -text
|
|||
Spatial_searching/doc_tex/Spatial_searching/Fig1.gif -text svneol=unset#unset
|
||||
Spatial_searching/doc_tex/Spatial_searching/Fig1.ps -text
|
||||
Spatial_sorting/description.txt -text
|
||||
Spatial_sorting/include/CGAL/BRIO_sort.h -text
|
||||
Spatial_sorting/include/CGAL/Hilbert_sort_2.h -text
|
||||
Spatial_sorting/include/CGAL/Hilbert_sort_3.h -text
|
||||
Spatial_sorting/include/CGAL/Hilbert_sort_base.h -text
|
||||
Spatial_sorting/include/CGAL/Multiscale_sort.h -text
|
||||
Spatial_sorting/include/CGAL/hilbert_sort.h -text
|
||||
Spatial_sorting/include/CGAL/spatial_sort.h -text
|
||||
Spatial_sorting/maintainer -text
|
||||
Spatial_sorting/test/Spatial_sorting/test_brio.C -text
|
||||
Spatial_sorting/test/Spatial_sorting/test_hilbert.C -text
|
||||
Spatial_sorting/test/Spatial_sorting/test_multiscale.C -text
|
||||
Straight_skeleton_2/demo/Straight_skeleton_2/data/alley_0.poly -text
|
||||
Straight_skeleton_2/demo/Straight_skeleton_2/data/alley_1.poly -text
|
||||
Straight_skeleton_2/demo/Straight_skeleton_2/data/alley_2.poly -text
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
#ifndef CGAL_BRIO_SORT_H
|
||||
#define CGAL_BRIO_SORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
#include <CGAL/Hilbert_sort_2.h>
|
||||
#include <CGAL/Hilbert_sort_3.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
template <class Sort, class RandomAccessIterator>
|
||||
class BRIO_sort
|
||||
{
|
||||
Sort sort;
|
||||
int threshold;
|
||||
int ratio;
|
||||
public:
|
||||
BRIO_sort (int _ratio = 8, int _threshold = 64, const Sort &_sort = Sort())
|
||||
: sort (_sort), threshold (_threshold), ratio (_ratio)
|
||||
{}
|
||||
|
||||
void operator() (RandomAccessIterator begin, RandomAccessIterator end) const
|
||||
{
|
||||
RandomAccessIterator middle = begin;
|
||||
if (end - begin >= threshold) {
|
||||
middle = begin + (end - begin) / ratio;
|
||||
this->operator() (begin, middle);
|
||||
}
|
||||
sort (middle, end);
|
||||
}
|
||||
};
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void brio_sort_2 (RandomAccessIterator begin, RandomAccessIterator end, Kernel k)
|
||||
{
|
||||
typedef Hilbert_sort_2<Kernel, RandomAccessIterator> Sort;
|
||||
(BRIO_sort<Sort,RandomAccessIterator> (4, 16, Sort (k))) (begin, end);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void brio_sort_2 (RandomAccessIterator begin, RandomAccessIterator end)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
typedef CGAL::Kernel_traits<value_type> KTraits;
|
||||
typedef typename KTraits::Kernel Kernel;
|
||||
|
||||
brio_sort_2 (begin, end, Kernel ());
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void brio_sort_3 (RandomAccessIterator begin, RandomAccessIterator end, Kernel k)
|
||||
{
|
||||
typedef Hilbert_sort_3<Kernel, RandomAccessIterator> Sort;
|
||||
(BRIO_sort<Sort,RandomAccessIterator> (8, 64, Sort (k))) (begin, end);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void brio_sort_3 (RandomAccessIterator begin, RandomAccessIterator end)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
typedef CGAL::Kernel_traits<value_type> KTraits;
|
||||
typedef typename KTraits::Kernel Kernel;
|
||||
|
||||
brio_sort_3 (begin, end, Kernel ());
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
||||
#endif//CGAL_BRIO_SORT_H
|
||||
|
|
@ -10,7 +10,6 @@ CGAL_BEGIN_NAMESPACE
|
|||
namespace CGALi {
|
||||
template <class K, int x, bool up> struct Hilbert_cmp_2;
|
||||
|
||||
|
||||
template <class K, int x>
|
||||
struct Hilbert_cmp_2<K,x,true>
|
||||
: public std::binary_function<typename K::Point_2,
|
||||
|
|
@ -52,13 +51,12 @@ namespace CGALi {
|
|||
return k.less_y_2_object() (p, q);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
template <class K, class RandomAccessIterator>
|
||||
template <class K>
|
||||
class Hilbert_sort_2
|
||||
{
|
||||
public:
|
||||
typedef RandomAccessIterator Iterator;
|
||||
typedef K Kernel;
|
||||
typedef typename Kernel::Point_2 Point;
|
||||
|
||||
|
|
@ -71,17 +69,17 @@ private:
|
|||
public:
|
||||
Hilbert_sort_2 (const Kernel &_k = Kernel()) : k(_k) {}
|
||||
|
||||
template <int x, bool upx, bool upy>
|
||||
void sort (Iterator begin, Iterator end) const
|
||||
template <int x, bool upx, bool upy, class RandomAccessIterator>
|
||||
void sort (RandomAccessIterator begin, RandomAccessIterator end) const
|
||||
{
|
||||
const int y = (x + 1) % 2;
|
||||
if (end - begin <= 8) return;
|
||||
|
||||
Iterator m0 = begin, m4 = end;
|
||||
RandomAccessIterator m0 = begin, m4 = end;
|
||||
|
||||
Iterator m2 = CGALi::hilbert_split (m0, m4, Cmp< x, upx> (k));
|
||||
Iterator m1 = CGALi::hilbert_split (m0, m2, Cmp< y, upy> (k));
|
||||
Iterator m3 = CGALi::hilbert_split (m2, m4, Cmp< y, !upy> (k));
|
||||
RandomAccessIterator m2 = CGALi::hilbert_split (m0, m4, Cmp< x, upx> (k));
|
||||
RandomAccessIterator m1 = CGALi::hilbert_split (m0, m2, Cmp< y, upy> (k));
|
||||
RandomAccessIterator m3 = CGALi::hilbert_split (m2, m4, Cmp< y, !upy> (k));
|
||||
|
||||
if (end - begin <= 8*4) return;
|
||||
|
||||
|
|
@ -91,30 +89,13 @@ public:
|
|||
sort<y,!upy,!upx> (m3, m4);
|
||||
}
|
||||
|
||||
void operator() (Iterator begin, Iterator end) const
|
||||
template <class RandomAccessIterator>
|
||||
void operator() (RandomAccessIterator begin, RandomAccessIterator end) const
|
||||
{
|
||||
sort <0, false, false> (begin, end);
|
||||
}
|
||||
};
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void hilbert_sort_2 (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
Kernel k)
|
||||
{
|
||||
(Hilbert_sort_2<Kernel,RandomAccessIterator> (k)) (begin, end);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void hilbert_sort_2 (RandomAccessIterator begin, RandomAccessIterator end)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
typedef CGAL::Kernel_traits<value_type> KTraits;
|
||||
typedef typename KTraits::Kernel Kernel;
|
||||
|
||||
hilbert_sort_2 (begin, end, Kernel());
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif//CGAL_HILBERT_SORT_2_H
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ CGAL_BEGIN_NAMESPACE
|
|||
namespace CGALi {
|
||||
template <class K, int x, bool up> struct Hilbert_cmp_3;
|
||||
|
||||
|
||||
template <class K, int x>
|
||||
struct Hilbert_cmp_3<K,x,true>
|
||||
: public std::binary_function<typename K::Point_3,
|
||||
|
|
@ -66,14 +65,12 @@ namespace CGALi {
|
|||
return k.less_z_3_object() (p, q);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template <class K, class RandomAccessIterator>
|
||||
template <class K>
|
||||
class Hilbert_sort_3
|
||||
{
|
||||
public:
|
||||
typedef RandomAccessIterator Iterator;
|
||||
typedef K Kernel;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
|
||||
|
|
@ -86,21 +83,21 @@ private:
|
|||
public:
|
||||
Hilbert_sort_3 (const Kernel &_k = Kernel()) : k(_k) {}
|
||||
|
||||
template <int x, bool upx, bool upy, bool upz>
|
||||
void sort (Iterator begin, Iterator end) const
|
||||
template <int x, bool upx, bool upy, bool upz, class RandomAccessIterator>
|
||||
void sort (RandomAccessIterator begin, RandomAccessIterator end) const
|
||||
{
|
||||
const int y = (x + 1) % 3, z = (x + 2) % 3;
|
||||
if (end - begin <= 8) return;
|
||||
|
||||
Iterator m0 = begin, m8 = end;
|
||||
RandomAccessIterator m0 = begin, m8 = end;
|
||||
|
||||
Iterator m4 = CGALi::hilbert_split (m0, m8, Cmp< x, upx> (k));
|
||||
Iterator m2 = CGALi::hilbert_split (m0, m4, Cmp< y, upy> (k));
|
||||
Iterator m1 = CGALi::hilbert_split (m0, m2, Cmp< z, upz> (k));
|
||||
Iterator m3 = CGALi::hilbert_split (m2, m4, Cmp< z, !upz> (k));
|
||||
Iterator m6 = CGALi::hilbert_split (m4, m8, Cmp< y, !upy> (k));
|
||||
Iterator m5 = CGALi::hilbert_split (m4, m6, Cmp< z, upz> (k));
|
||||
Iterator m7 = CGALi::hilbert_split (m6, m8, Cmp< z, !upz> (k));
|
||||
RandomAccessIterator m4 = CGALi::hilbert_split (m0, m8, Cmp< x, upx> (k));
|
||||
RandomAccessIterator m2 = CGALi::hilbert_split (m0, m4, Cmp< y, upy> (k));
|
||||
RandomAccessIterator m1 = CGALi::hilbert_split (m0, m2, Cmp< z, upz> (k));
|
||||
RandomAccessIterator m3 = CGALi::hilbert_split (m2, m4, Cmp< z, !upz> (k));
|
||||
RandomAccessIterator m6 = CGALi::hilbert_split (m4, m8, Cmp< y, !upy> (k));
|
||||
RandomAccessIterator m5 = CGALi::hilbert_split (m4, m6, Cmp< z, upz> (k));
|
||||
RandomAccessIterator m7 = CGALi::hilbert_split (m6, m8, Cmp< z, !upz> (k));
|
||||
|
||||
if (end - begin <= 8*8) return;
|
||||
|
||||
|
|
@ -114,30 +111,13 @@ public:
|
|||
sort<z,!upz,!upx, upy> (m7, m8);
|
||||
}
|
||||
|
||||
void operator() (Iterator begin, Iterator end) const
|
||||
template <class RandomAccessIterator>
|
||||
void operator() (RandomAccessIterator begin, RandomAccessIterator end) const
|
||||
{
|
||||
sort <0, false, false, false> (begin, end);
|
||||
}
|
||||
};
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void hilbert_sort_3 (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
Kernel k)
|
||||
{
|
||||
(Hilbert_sort_3<Kernel,RandomAccessIterator> (k)) (begin, end);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void hilbert_sort_3 (RandomAccessIterator begin, RandomAccessIterator end)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
typedef CGAL::Kernel_traits<value_type> KTraits;
|
||||
typedef typename KTraits::Kernel Kernel;
|
||||
|
||||
return hilbert_sort_3 (begin, end, Kernel());
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif//CGAL_HILBERT_SORT_3_H
|
||||
|
|
|
|||
|
|
@ -19,9 +19,8 @@ namespace CGALi {
|
|||
std::nth_element (begin, middle, end, cmp);
|
||||
return middle;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
||||
#endif//CGAL_HILBERT_SORT_BASE_H
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef CGAL_MULTISCALE_SORT_H
|
||||
#define CGAL_MULTISCALE_SORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
template <class Sort>
|
||||
class Multiscale_sort
|
||||
{
|
||||
Sort sort;
|
||||
int threshold;
|
||||
int ratio;
|
||||
|
||||
public:
|
||||
Multiscale_sort (int _ratio = 8, int _threshold = 64, const Sort &_sort = Sort())
|
||||
: sort (_sort), threshold (_threshold), ratio (_ratio)
|
||||
{}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void operator() (RandomAccessIterator begin, RandomAccessIterator end) const
|
||||
{
|
||||
RandomAccessIterator middle = begin;
|
||||
if (end - begin >= threshold) {
|
||||
middle = begin + (end - begin) / ratio;
|
||||
this->operator() (begin, middle);
|
||||
}
|
||||
sort (middle, end);
|
||||
}
|
||||
};
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif//CGAL_MULTISCALE_SORT_H
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef CGAL_HILBERT_SORT_H
|
||||
#define CGAL_HILBERT_SORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
#include <CGAL/Hilbert_sort_2.h>
|
||||
#include <CGAL/Hilbert_sort_3.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
namespace CGALi {
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
const Kernel &k, typename Kernel::Point_2 *)
|
||||
{
|
||||
(Hilbert_sort_2<Kernel> (k)) (begin, end);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
const Kernel &k, typename Kernel::Point_3 *)
|
||||
{
|
||||
(Hilbert_sort_3<Kernel> (k)) (begin, end);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
const Kernel &k)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
|
||||
CGALi::hilbert_sort (begin, end, k, static_cast<value_type *> (0));
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
typedef CGAL::Kernel_traits<value_type> KTraits;
|
||||
typedef typename KTraits::Kernel Kernel;
|
||||
|
||||
hilbert_sort (begin, end, Kernel());
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif//CGAL_HILBERT_SORT_H
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef CGAL_SPATIAL_SORT_H
|
||||
#define CGAL_SPATIAL_SORT_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
#include <CGAL/Hilbert_sort_2.h>
|
||||
#include <CGAL/Hilbert_sort_3.h>
|
||||
|
||||
#include <CGAL/Multiscale_sort.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
namespace CGALi {
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
const Kernel &k, typename Kernel::Point_2 *)
|
||||
{
|
||||
typedef Hilbert_sort_2<Kernel> Sort;
|
||||
(Multiscale_sort<Sort> (4, 16, Sort (k))) (begin, end);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
const Kernel &k, typename Kernel::Point_3 *)
|
||||
{
|
||||
typedef Hilbert_sort_3<Kernel> Sort;
|
||||
(Multiscale_sort<Sort> (8, 64, Sort (k))) (begin, end);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator, class Kernel>
|
||||
void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end,
|
||||
const Kernel &k)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
|
||||
CGALi::spatial_sort (begin, end, k, static_cast<value_type *> (0));
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator>
|
||||
void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end)
|
||||
{
|
||||
typedef std::iterator_traits<RandomAccessIterator> ITraits;
|
||||
typedef typename ITraits::value_type value_type;
|
||||
typedef CGAL::Kernel_traits<value_type> KTraits;
|
||||
typedef typename KTraits::Kernel Kernel;
|
||||
|
||||
spatial_sort (begin, end, Kernel());
|
||||
}
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif//CGAL_SPATIAL_SORT_H
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#include <CGAL/basic.h>
|
||||
|
||||
#include <CGAL/Hilbert_sort_2.h>
|
||||
#include <CGAL/Hilbert_sort_3.h>
|
||||
#include <CGAL/hilbert_sort.h>
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
|
|
@ -45,7 +44,7 @@ int main ()
|
|||
|
||||
std::cout << " Sorting points... " << std::flush;
|
||||
|
||||
CGAL::hilbert_sort_2 (v.begin(), v.end());
|
||||
CGAL::hilbert_sort (v.begin(), v.end());
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ int main ()
|
|||
|
||||
std::cout << " Sorting points... " << std::flush;
|
||||
|
||||
CGAL::hilbert_sort_3 (v.begin(), v.end());
|
||||
CGAL::hilbert_sort (v.begin(), v.end());
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <CGAL/basic.h>
|
||||
|
||||
#include <CGAL/BRIO_sort.h>
|
||||
#include <CGAL/spatial_sort.h>
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ int main ()
|
|||
const int nb_points_2 = 50000, nb_points_3 = 50000;
|
||||
CGAL::Random random (42);
|
||||
|
||||
std::cout << "Testing BRIO + Hilbert sort." << std::endl;
|
||||
std::cout << "Testing Multiscale<Hilbert> sort." << std::endl;
|
||||
|
||||
{
|
||||
std::cout << "Testing 2D: Generating points... " << std::flush;
|
||||
|
|
@ -44,7 +44,7 @@ int main ()
|
|||
|
||||
std::cout << " Sorting points... " << std::flush;
|
||||
|
||||
CGAL::brio_sort_2 (v.begin(), v.end());
|
||||
CGAL::spatial_sort (v.begin(), v.end());
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ int main ()
|
|||
|
||||
std::cout << " Sorting points... " << std::flush;
|
||||
|
||||
CGAL::brio_sort_3 (v.begin(), v.end());
|
||||
CGAL::spatial_sort (v.begin(), v.end());
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
|
||||
Loading…
Reference in New Issue