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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
// Copyright (c) 2004 Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Box_intersection_d/include/CGAL/Box_intersection_d/Box_traits_d.h $
// $Id: Box_traits_d.h 37866 2007-04-03 12:34:18Z ameyer $
//
//
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
// Andreas Meyer <ameyer@mpi-sb.mpg.de>
#ifndef CGAL_BOX_INTERSECTION_D_BOX_TRAITS_D_H
#define CGAL_BOX_INTERSECTION_D_BOX_TRAITS_D_H
#include <CGAL/basic.h>
#include <functional>
CGAL_BEGIN_NAMESPACE
namespace Box_intersection_d {
enum Setting { COMPLETE, BIPARTITE };
enum Topology { HALF_OPEN, CLOSED };
template<class BoxHandle>
struct Box_traits_d {
typedef const BoxHandle& Box_parameter;
typedef typename BoxHandle::NT NT;
typedef typename BoxHandle::ID ID;
static NT min_coord(Box_parameter b, int dim) { return b.min_coord( dim);}
static NT max_coord(Box_parameter b, int dim) { return b.max_coord( dim);}
static ID id(Box_parameter b) { return b.id();}
static int dimension() { return BoxHandle::dimension();}
};
// box pointer traits
template<class Box_>
struct Box_traits_d<Box_*> {
typedef const Box_* Box_parameter;
typedef typename Box_::NT NT;
typedef typename Box_::ID ID;
static NT min_coord(Box_parameter b, int dim) { return b->min_coord(dim);}
static NT max_coord(Box_parameter b, int dim) { return b->max_coord(dim);}
static ID id(Box_parameter b) { return b->id();}
static int dimension() { return Box_::dimension();}
};
// box pointer traits
template<class Box_>
struct Box_traits_d<const Box_*> {
typedef const Box_* Box_parameter;
typedef typename Box_::NT NT;
typedef typename Box_::ID ID;
static NT min_coord(Box_parameter b, int dim) { return b->min_coord(dim);}
static NT max_coord(Box_parameter b, int dim) { return b->max_coord(dim);}
static ID id(Box_parameter b) { return b->id();}
static int dimension() { return Box_::dimension();}
};
template< class BoxTraits, bool closed >
struct Predicate_traits_d : public BoxTraits {
typedef typename BoxTraits::Box_parameter Box_parameter;
typedef typename BoxTraits::NT NT;
template<bool b> struct Bool_t {};
static bool hi_greater(NT hi, NT val, Bool_t<true> ) { return hi >= val;}
static bool hi_greater(NT hi, NT val, Bool_t<false> ){ return hi > val;}
static bool hi_greater (NT hi, NT val) {
return hi_greater(hi,val, Bool_t<closed>());
}
// compare dim a b = islolesslo a b dim
class Compare :
public std::binary_function<Box_parameter,Box_parameter,bool>
{
int dim;
public:
Compare(int dim) : dim(dim) {}
bool operator()(Box_parameter a, Box_parameter b) const {
return is_lo_less_lo(a,b,dim);
}
};
// loless val dim box = getlo box dim < val
class Lo_less : public std::unary_function<Box_parameter,bool> {
NT value;
int dim;
public:
Lo_less(NT value, int dim) : value(value), dim(dim) {}
bool operator() (Box_parameter box) const {
return BoxTraits::min_coord(box, dim) < value;
}
};
class Hi_greater : public std::unary_function<Box_parameter,bool> {
NT value;
int dim;
public:
Hi_greater(NT value, int dim) : value(value), dim(dim) {}
bool operator() (Box_parameter box) const {
return hi_greater( BoxTraits::max_coord(box, dim), value);
}
};
// spanning lo hi dim box = getlo box dim < lo && gethi box dim > hi
class Spanning : public std::unary_function<Box_parameter,bool> {
NT lo, hi;
int dim;
public:
Spanning(NT lo, NT hi, int dim) : lo(lo), hi(hi), dim(dim) {}
// returns true <=> box spans [lo,hi) in dimension dim
bool operator() (Box_parameter box) const {
return BoxTraits::min_coord(box,dim) < lo
&& BoxTraits::max_coord(box,dim) > hi;
}
};
static Compare compare_object(int dim) { return Compare(dim); }
static Lo_less lo_less_object(NT value, int dim) {
return Lo_less(value, dim);
}
static Hi_greater hi_greater_object(NT value, int dim) {
return Hi_greater( value, dim );
}
static Spanning spanning_object(NT lo, NT hi, int dim) {
return Spanning( lo, hi, dim );
}
static bool is_lo_less_lo(Box_parameter a, Box_parameter b, int dim) {
return BoxTraits::min_coord(a,dim) < BoxTraits::min_coord(b,dim) ||
( BoxTraits::min_coord(a,dim) == BoxTraits::min_coord(b,dim) &&
BoxTraits::id(a) < BoxTraits::id(b) );
}
static bool is_lo_less_hi(Box_parameter a, Box_parameter b, int dim) {
return hi_greater( BoxTraits::max_coord(b,dim),
BoxTraits::min_coord(a,dim));
}
static bool does_intersect (Box_parameter a, Box_parameter b, int dim) {
return is_lo_less_hi(a,b,dim) && is_lo_less_hi(b,a,dim);
}
static bool contains_lo_point(Box_parameter a, Box_parameter b, int dim) {
return is_lo_less_lo(a,b,dim) && is_lo_less_hi(b,a,dim);
}
};
} // end namespace Box_intersection_d
CGAL_END_NAMESPACE
#endif
|