filter the predicates in Convex_hull_traits_3 if requested

This commit is contained in:
Sébastien Loriot 2015-01-07 09:20:47 +01:00
parent 6b9945c271
commit b7caf33fbd
5 changed files with 261 additions and 16 deletions

View File

@ -27,6 +27,8 @@
#include <CGAL/Projection_traits_xz_3.h>
#include <CGAL/Projection_traits_yz_3.h>
#include <list>
#include <CGAL/Filtered_predicate.h>
#include <CGAL/Cartesian_converter.h>
namespace CGAL {
template < class R_ >
@ -53,18 +55,40 @@ public:
};
template <class From, class To>
struct Point_triple_converter{
// Point_triple_less_signed_distance_to_plane_3 is only working with a Cartesian Kernel
// so I hardcoded the converter type
CGAL::Cartesian_converter<From, To> base;
Point_triple<To>
operator()(const Point_triple<From>& t) const{
return Point_triple<To>(
base(t.p()),
base(t.q()),
base(t.r()) );
}
typename To::Point_3
operator()(const typename From::Point_3& t) const{
return base(t);
}
};
template <class K>
class Point_triple_has_on_positive_side_3 {
public:
typedef typename K::Point_3 Point_3;
typedef typename K::Plane_3 Plane_3;
typedef Point_triple<K> Plane_3;
bool
operator()( const Plane_3& pl, const Point_3& p) const
{
typename K::Orientation_3 o;
return ( o(pl.p(), pl.q(), pl.r(), p) == CGAL::POSITIVE );
}
typedef bool result_type;
};
template <class K, class OldK>
class Point_triple_construct_orthogonal_vector_3
@ -103,12 +127,12 @@ public:
}
};
template <typename K, typename OldK>
template <typename K>
class Point_triple_less_signed_distance_to_plane_3
{
public:
typedef typename K::Point_3 Point_3;
typedef typename K::Plane_3 Plane_3;
typedef Point_triple<K> Plane_3;
typedef bool result_type;
@ -135,14 +159,39 @@ struct GT3_for_CH3 {
typedef typename GT::Point_3 Point_2;
};
template <class R_, class Has_filtered_predicates_tag /* = Tag_false */>
struct Convex_hull_traits_base_3 {
typedef Point_triple_has_on_positive_side_3<R_> Has_on_positive_side_3;
typedef Point_triple_less_signed_distance_to_plane_3<R_>
Less_signed_distance_to_plane_3;
};
template <class R_>
class Convex_hull_traits_3
struct Convex_hull_traits_base_3<R_, Tag_true>{
typedef Filtered_predicate<
Point_triple_has_on_positive_side_3< typename R_::Exact_kernel_rt >,
Point_triple_has_on_positive_side_3< typename R_::Approximate_kernel >,
Point_triple_converter<R_,typename R_::Exact_kernel_rt>,
Point_triple_converter<R_,typename R_::Approximate_kernel>
> Has_on_positive_side_3;
typedef Filtered_predicate<
Point_triple_less_signed_distance_to_plane_3< typename R_::Exact_kernel_rt >,
Point_triple_less_signed_distance_to_plane_3< typename R_::Approximate_kernel >,
Point_triple_converter<R_,typename R_::Exact_kernel_rt>,
Point_triple_converter<R_,typename R_::Approximate_kernel>
> Less_signed_distance_to_plane_3;
};
template <class R_, class Has_filtered_predicates_tag = Tag_false>
class Convex_hull_traits_3 :
public Convex_hull_traits_base_3<R_, Has_filtered_predicates_tag>
{
public:
typedef R_ R;
typedef Convex_hull_traits_3<R> Self;
typedef Convex_hull_traits_3<R, Has_filtered_predicates_tag> Self;
typedef typename R::Point_3 Point_3;
typedef typename R::Segment_3 Segment_3;
typedef typename R::Triangle_3 Triangle_3;
@ -172,10 +221,12 @@ class Convex_hull_traits_3
typedef typename R::Collinear_3 Collinear_3;
typedef typename R::Coplanar_3 Coplanar_3;
typedef typename R::Less_distance_to_point_3 Less_distance_to_point_3;
typedef Point_triple_has_on_positive_side_3<Self> Has_on_positive_side_3;
typedef Point_triple_less_signed_distance_to_plane_3<Self, R>
Less_signed_distance_to_plane_3;
typedef typename Convex_hull_traits_base_3<R_, Has_filtered_predicates_tag>
::Has_on_positive_side_3 Has_on_positive_side_3;
typedef typename Convex_hull_traits_base_3<R_, Has_filtered_predicates_tag>
::Less_signed_distance_to_plane_3 Less_signed_distance_to_plane_3;
// required for degenerate case of all points coplanar
typedef CGAL::Projection_traits_xy_3<R> Traits_xy_3;

View File

@ -69,7 +69,7 @@ struct Default_traits_for_Chull_3{
//FT is a floating point type and Kernel is a filtered kernel
template <class Point_3>
struct Default_traits_for_Chull_3<Point_3,boost::true_type,Tag_true>{
typedef Convex_hull_traits_3< typename Kernel_traits<Point_3>::Kernel > type;
typedef Convex_hull_traits_3< typename Kernel_traits<Point_3>::Kernel, Tag_true > type;
};
template <class Traits>
@ -77,9 +77,9 @@ struct Default_polyhedron_for_Chull_3{
typedef CGAL::Polyhedron_3<Traits> type;
};
template <class K>
struct Default_polyhedron_for_Chull_3<Convex_hull_traits_3<K> >{
typedef typename Convex_hull_traits_3<K>::Polyhedron_3 type;
template <class K,class Tag>
struct Default_polyhedron_for_Chull_3<Convex_hull_traits_3<K, Tag> >{
typedef typename Convex_hull_traits_3<K, Tag>::Polyhedron_3 type;
};
//utility class to select the right version of internal predicate Is_on_positive_side_of_plane_3
@ -129,10 +129,10 @@ public:
//interval arithmetic (the protector must be created before using this predicate)
//and in case of failure, exact arithmetic is used.
template <class Kernel>
class Is_on_positive_side_of_plane_3<Convex_hull_traits_3<Kernel>,Tag_true>{
class Is_on_positive_side_of_plane_3<Convex_hull_traits_3<Kernel, Tag_true>,Tag_true>{
typedef Simple_cartesian<CGAL::internal::Exact_field_selector<double>::Type> PK;
typedef Simple_cartesian<Interval_nt_advanced > CK;
typedef Convex_hull_traits_3<Kernel> Traits;
typedef Convex_hull_traits_3<Kernel, Tag_true> Traits;
typedef typename Traits::Point_3 Point_3;
Cartesian_converter<Kernel,CK> to_CK;

View File

@ -0,0 +1,24 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_3.h>
#include <fstream>
#include <cassert>
typedef CGAL::Epick K;
int main()
{
K::Point_3 p;
std::set<K::Point_3> pointset;
std::ifstream input("convex_hull_traits_3_fp_bug.xyz");
assert(input);
while ( input >> p )
pointset.insert(p);
CGAL::Polyhedron_3<K> r;
CGAL::convex_hull_3(pointset.begin(), pointset.end(), r);
assert(r.size_of_vertices()==82);
return 0;
}

View File

@ -0,0 +1,170 @@
21.015921990298082278 -9.6968661252791008565 17.385898562432661407
21.015921990298082278 9.4292289939816065214 11.538464467977924244
21.245998787904895266 9.1447008983105675384 10.607815001220002316
21.245998787904895266 -0.41834666131978626158 13.531532048447369121
21.245998787904895266 -9.9813942209501398395 16.455249095674737703
16.150059612458484537 -10.033205852946363024 17.385898562432661407
16.150059612458484537 9.0928892663143443542 11.538464467977924244
16.380136410065297525 8.8083611706433053712 10.607815001220002316
16.380136410065297525 -0.75468638898704798468 13.531532048447369121
16.380136410065297525 -10.317733948617402007 16.455249095674737703
15.17688713689056712 -10.100473798479814747 17.165875026644524581
15.17688713689056712 9.0256213207808926313 11.318440932189787418
15.406963934497380109 8.7410932251098536483 10.38779146543186549
15.406963934497380109 -0.82195433452049937451 13.311508512659232295
15.406963934497380109 -10.38500189415085373 16.235225559886600877
14.152135476691794835 -10.17119106380654614 16.934569274178546294
14.152135476691794835 8.954904055454161238 11.087135179723812684
14.367990727181227939 8.6694249043464353122 10.153374950800477805
14.367990727181227939 -0.89362265528391870983 13.077091998027846387
14.367990727181227939 -10.456670214914272066 16.000809045255213192
13.110820024653460081 -10.233961476664669377 16.729256504918232906
13.110820024653460081 8.8921336425960380012 10.881822410463495743
13.309600712109528331 8.6055965081559246954 9.9446016739871083701
13.309600712109528331 -0.95745105147442877147 12.868318721214476952
13.309600712109528331 -10.520498611104782682 15.792035768441845534
12.078282570414469177 -10.294222837947037519 16.532150473574372285
12.078282570414469177 8.8318722813136698591 10.684716379119635121
12.262745467026753943 8.5445178276236166681 9.7448223118344454718
12.262745467026753943 -1.0185297320067365767 12.668539359061812277
12.262745467026753943 -10.58157729163709071 15.592256406289180859
11.031163105767490151 -10.348029755406946251 16.356155976708063093
11.031163105767490151 8.7780653638537611272 10.508721882253327706
11.198443837973723447 8.4898133798050405829 9.5658921254443249893
11.198443837973723447 -1.0732341798253119958 12.489609172671691795
11.198443837973723447 -10.636281739455666795 15.413326219899060376
9.9920867282612331195 -10.397762464907449598 16.193487613614035325
9.9920867282612331195 8.7283326543532577801 10.346053519159298162
10.144967804693861169 8.4393978978853763095 9.4009905143952519069
10.144967804693861169 -1.1236496617449773794 12.324707561622618712
10.144967804693861169 -10.686697221375331068 15.248424608849987294
8.9400347163076823165 -10.442561786292975157 16.046955635953878527
8.9400347163076823165 8.6835333329677322212 10.199521541499144917
9.0756439452541037838 8.3938624405481636614 9.2520507445299653426
9.0756439452541037838 -1.1691851190821893614 12.175767791757333924
9.0756439452541037838 -10.732232678712543716 15.09948483898470073
7.8956741722639147696 -10.481705796269976005 15.918921348422623296
7.8956741722639147696 8.6443893229907313724 10.071487253967887909
8.0168163367886453585 8.3541708868691326728 9.1222255222471790859
8.0168163367886453585 -1.2088766727612223484 12.045942569474547668
8.0168163367886453585 -10.771924232391574705 14.969659616701914473
6.839564786514664263 -10.51746028460065574 15.801973686643666639
6.839564786514664263 8.6086348346600516379 9.9545395921889312518
6.9433634354009168277 8.3178424250433771192 9.0034004777589125013
6.9433634354009168277 -1.2452051345869770138 11.927117524986281083
6.9433634354009168277 -10.808252694217330259 14.850834572213647888
5.7911812064893624097 -10.545968319665455226 15.708728105504132344
5.7911812064893624097 8.5801267995952521517 9.861294011049396957
5.8804599030361934808 8.2889226275126546284 8.9088080822795312486
5.8804599030361934808 -1.2741249321176979503 11.83252512950689983
5.8804599030361934808 -10.837172491748052749 14.756242176734266636
4.7318927519149163174 -10.572647626142034127 15.621464026055862817
4.7318927519149163174 8.5534474931186732505 9.77402993160112743
4.8037743563616075448 8.2618321038161273151 8.8201989719106297372
4.8037743563616075448 -1.3012154558142254857 11.743916019137996543
4.8037743563616075448 -10.864263015444580063 14.667633066365365124
3.6807521204854736219 -10.590485240237288878 15.563119819284901624
3.6807521204854736219 8.5356098790234185003 9.7156857248301662366
3.7380754567641063524 8.2437189311402967462 8.7609534536348423472
3.7380754567641063524 -1.3193286284900567207 11.684670500862209153
3.7380754567641063524 -10.882376188120410632 14.608387548089577734
2.6191654551378640292 -10.608065925320802947 15.505615989444741842
2.6191654551378640292 8.518029193939904431 9.6581818949900064553
2.659056271348898548 8.2258902040489321195 8.7026383149438082398
2.659056271348898548 -1.3371573555814209033 11.626355362171176822
2.659056271348898548 -10.900204915211775258 14.550072409398543627
1.5571301313920737908 -10.615277603175528043 15.482027654049947074
1.5571301313920737908 8.5108175160851793351 9.634593559595211687
1.5798452641030620303 8.2185212496694965978 8.6785355512163384617
1.5798452641030620303 -1.3445263099608570911 11.602252598443705267
1.5798452641030620303 -10.90757386959121078 14.525969645671073849
0.5035077216434232783 -10.622159719563320834 15.459517265642222839
0.5035077216434232783 8.5039353996973865435 9.6120831711874892278
0.5113668014119475691 8.2115727243029539295 8.6558079488265811108
0.5113668014119475691 -1.3514748353273995374 11.579524996053947916
0.5113668014119475691 -10.914522394957753448 14.503242043281314722
-0.55969246949480999653 -10.620097256783905593 15.466263277424799227
-0.55969246949480999653 8.5059978624768017852 9.6188291829700638402
-0.56928712712562057341 8.2136396155613287107 8.6625684455111535698
-0.56928712712562057341 -1.3494079440690252003 11.586285492738520375
-0.56928712712562057341 -10.912455503699378667 14.510002539965888957
-1.6125195715995086498 -10.616272236324949318 15.478774355608731383
-1.6125195715995086498 8.5098228829357580594 9.6313402611539977727
-1.6367003391161654147 8.2175366669705987022 8.6753151263175354302
-1.6367003391161654147 -1.3455108926597549868 11.599032173544902236
-1.6367003391161654147 -10.908558452290108676 14.522749220772269041
-2.6750035922459902693 -10.605089410934800398 15.515351729318147989
-2.6750035922459902693 8.5210057083259069799 9.6679176348634126015
-2.7166291222015424012 8.2288874074141755699 8.7124417254191364179
-2.7166291222015424012 -1.334160152216178119 11.636158772646505
-2.7166291222015424012 -10.897207711846531808 14.559875819873871805
-3.7267390106727740218 -10.590568334550255258 15.562848030033741509
-3.7267390106727740218 8.5355267847104521195 9.7154139355790061217
-3.7829348904509538798 8.2436170965810333655 8.7606203678000085233
-3.7829348904509538798 -1.3194304630493196573 11.684337415027377105
-3.7829348904509538798 -10.882478022679674012 14.60805446225474391
-4.7876230981018181865 -10.570275178726245002 15.629223951898024936
-4.7876230981018181865 8.5558199405344623756 9.7817898574432895487
-4.8612365692795815875 8.2642414847358942609 8.828079701800975343
-4.8612365692795815875 -1.2988060748944600942 11.751796749028343925
-4.8612365692795815875 -10.861853634524813117 14.67551379625571073
-5.8369967953404051642 -10.545075590745145888 15.711648090230719177
-5.8369967953404051642 8.5810195285155614897 9.8642139957759837898
-5.9251502312697619246 8.2897860538008281139 8.9116322224150632536
-5.9251502312697619246 -1.2732615058295262411 11.835349269642431835
-5.9251502312697619246 -10.836309065459879264 14.759066316869798641
-6.895398463720493254 -10.515689075464781155 15.807767050683622756
-6.895398463720493254 8.6104060437959262231 9.9603329562288873689
-7.0009241527878049993 8.3196667739247160966 9.0093676540744773718
-7.0009241527878049993 -1.2433807857056371482 11.933084701301844177
-7.0009241527878049993 -10.806428345335991281 14.856801748529212759
-7.9411432512251920457 -10.47984140089607763 15.925019510913235976
-7.9411432512251920457 8.6462537183646297478 10.077585416458500589
-8.0611639241462889061 8.355995453894500713 9.1281934120797192378
-8.0611639241462889061 -1.2070521057358516437 12.05191045930708782
-8.0611639241462889061 -10.770099665366206665 14.975627506534454625
-8.9961818731247724656 -10.441385424593725872 16.050803341698156146
-8.9961818731247724656 8.6847096946669815054 10.203369247243418982
-9.1335113425972984658 8.3951080877002439706 9.2561250727790511661
-9.1335113425972984658 -1.1679394719301097183 12.179842120006419748
-9.1335113425972984658 -10.730987031560463407 15.103559167233786553
-10.037034938423907704 -10.394932932465536624 16.202742597210743725
-10.037034938423907704 8.7311621867951707543 10.355308502756006561
-10.188799857367065727 8.4421771354154273581 9.4100809907477991345
-10.188799857367065727 -1.120870424214927441 12.33379803797516594
-10.188799857367065727 -10.68391798384528002 15.257515085202534522
-11.087832325460665217 -10.347438306258311513 16.358090519704578725
-11.087832325460665217 8.7786568130023958645 10.510656425249845114
-11.25682453492664159 8.4904901774226715361 9.5681058307041340072
-11.25682453492664159 -1.0725573822076825969 12.491822877931500813
-11.25682453492664159 -10.635604941838035842 15.415539925158867618
-12.130826484007744881 -10.28998208592428476 16.546021348432333298
-12.130826484007744881 8.8361130333364226175 10.698587253977599687
-12.316465776491348549 8.5488233456115647613 9.7589050266192529648
-12.316465776491348549 -1.0142242140187893717 12.68262207384661977
-12.316465776491348549 -10.577271773649142617 15.606339121073986576
-13.167274479509028851 -10.232609601207819594 16.733678290296118973
-13.167274479509028851 8.8934855180528877838 10.886244195841383586
-13.36775592988668393 8.6070496903803430655 9.9493548188709652891
-13.36775592988668393 -0.9559978692500109565 12.873071866098332094
-13.36775592988668393 -10.519045428880364312 15.796788913325700676
-14.205661711313787521 -10.165804085335658158 16.952189286815759317
-14.205661711313787521 8.96029103392504922 11.104755192361025706
-14.423211305781006075 8.6749218454890240082 10.171354635130359867
-14.423211305781006075 -0.88812571414133034686 13.095071682357726672
-14.423211305781006075 -10.45117327377168337 16.018788729585093478
-15.232758954180525279 -10.098059861404790283 17.173770659047207232
-15.232758954180525279 9.0280352578559170951 11.326336564592470069
-15.464523864863501501 8.7436243006743357142 10.396070240569519783
-15.464523864863501501 -0.81942325895601786367 13.319787287796886588
-15.464523864863501501 -10.382470818586371664 16.24350433502425517
-16.263941232543412951 -10.022378056180794914 17.421314689835732281
-16.263941232543412951 9.1037170630799124638 11.573880595380996894
-16.512649129623643063 8.8205321051208152028 10.647624334125161738
-16.512649129623643063 -0.74251545450953948535 13.571341381352528543
-16.512649129623643063 -10.305563014139892175 16.495058428579895349
-17.249434174697078959 -9.946811825017595865 17.668480694904857842
-17.249434174697078959 9.1792832942431115129 11.821046600450122455
-17.503165223042536525 8.8964795095546467252 10.896037100784631946
-17.503165223042536525 -0.66656805007570774091 13.819754148011998751
-17.503165223042536525 -10.229615609706060653 16.743471195239365557

View File

@ -25,7 +25,7 @@ int main()
CGAL_static_assertion( (boost::is_same<SCD,Default_traits_for_Chull_3<SCD::Point_3>::type>::value) );
CGAL_static_assertion( (boost::is_same<SCR,Default_traits_for_Chull_3<SCR::Point_3>::type>::value) );
CGAL_static_assertion( (boost::is_same<EPEC,Default_traits_for_Chull_3<EPEC::Point_3>::type>::value) );
CGAL_static_assertion( (boost::is_same<CGAL::Convex_hull_traits_3<EPIC>,Default_traits_for_Chull_3<EPIC::Point_3>::type>::value) );
CGAL_static_assertion( (boost::is_same<Is_on_positive_side_of_plane_3<CGAL::Convex_hull_traits_3<EPIC> >::Protector,CGAL::Protect_FPU_rounding<true> >::value) );
CGAL_static_assertion( (boost::is_same<CGAL::Convex_hull_traits_3<EPIC, CGAL::Tag_true>,Default_traits_for_Chull_3<EPIC::Point_3>::type>::value) );
CGAL_static_assertion( (boost::is_same<Is_on_positive_side_of_plane_3<CGAL::Convex_hull_traits_3<EPIC, CGAL::Tag_true> >::Protector,CGAL::Protect_FPU_rounding<true> >::value) );
return 0;
}