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:
@@ -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
|
||||
Reference in New Issue
Block a user