CGAL 6.1 - Intersecting Sequences of dD Iso-oriented Boxes

Loading...
Searching...
No Matches
Box_intersection_d/box_d_do_intersect_polylines.cpp
#include <vector>
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/box_intersection_d.h>
template <typename Poly>
class Polylines_do_intersect
{
typedef typename Poly::const_iterator Iterator;
typedef typename std::iterator_traits<Iterator>::value_type Point_2;
typedef typename CGAL::Kernel_traits<Point_2>::Kernel::Segment_2 Segment_2;
typedef CGAL::Bbox_2 Bbox_2;
const Poly& pA, &pB;
struct Box : public CGAL::Box_intersection_d::Box_with_handle_d<double,2,Iterator> {
typedef CGAL::Box_intersection_d::Box_with_handle_d<double,2,Iterator> Base;
Box( const Bbox_2& b, Iterator it)
: Base(b,it)
{}
};
class FirstIntersection
{};
class Overlap {
const Poly& pA, &pB;
public:
Overlap(const Poly& pA, const Poly& pB)
: pA(pA), pB(pB)
{}
void operator()(const Box& a, const Box& b) {
Segment_2 sa(*(a.handle()), *(++(a.handle())));
Segment_2 sb(*(b.handle()), *(++(b.handle())));
if(CGAL::do_intersect(sa,sb)){
throw FirstIntersection();
}
}
};
public:
Polylines_do_intersect(const Poly& pA, const Poly& pB)
: pA(pA), pB(pB)
{}
bool operator()() const
{
std::vector<Box> bA, bB;
bA.reserve(pA.size() - 1 );
bB.reserve(pB.size() - 1 );
Iterator begin = pA.begin();
for(std::size_t j=0; j < pA.size()-1; j++){
Bbox_2 bb = pA[j].bbox() + pA[j+1].bbox();
bA.push_back(Box(bb, begin+j));
}
begin = pB.begin();
for(std::size_t j=0; j < pB.size()-1; j++){
Bbox_2 bb = pB[j].bbox() + pB[j+1].bbox();
bB.push_back(Box(bb, begin+j));
}
Overlap overlap(pA,pB);
try {
CGAL::box_intersection_d( bA.begin(), bA.end(), bB.begin(), bB.end(), overlap);
} catch(const FirstIntersection& ) {
return true;
}
return false;
}
};
template <typename Poly>
bool polylines_do_intersect(const Poly& pA,const Poly& pB)
{
Polylines_do_intersect<Poly> pdi(pA,pB);
return pdi();
}
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef std::vector<Point_2> CGAL_polyline;
int main()
{
CGAL_polyline pA = { Point_2(0,0), Point_2(1,0) };
CGAL_polyline pB = { Point_2(0,0), Point_2(0,1), Point_2(2,1) , Point_2(1,0)};
if(polylines_do_intersect(pA,pB)){
std::cout << "intersection" << std::endl;
} else {
std::cout << "no intersection" << std::endl;
}
return 0;
}
CGAL::Bbox_2
CGAL::Box_intersection_d::Box_with_handle_d
Box_with_handle_d is a generic iso-oriented bounding box in dimension that stores additionally a han...
Definition: Box_with_handle_d.h:66
CGAL::Exact_predicates_inexact_constructions_kernel
Iterator
CGAL::box_intersection_d
void box_intersection_d(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, Callback callback, std::ptrdiff_t cutoff=10, CGAL::Box_intersection_d::Topology topology=CGAL::Box_intersection_d::CLOSED, CGAL::Box_intersection_d::Setting setting=CGAL::Box_intersection_d::BIPARTITE)
Invocation of box intersection with default box traits Box_intersection_d::Box_traits_d<Box_handle>,...
CGAL::do_intersect
bool do_intersect(Type1< Kernel > obj1, Type2< Kernel > obj2)
CGAL::Kernel_traits