mirror of https://github.com/CGAL/cgal
Add a hole filter to the p-w-h strategies
When the bounding box of the other polygon's outer boundary does not fit into the bounding box of a hole, the hole is irrelevant.
This commit is contained in:
parent
382a9c4cfc
commit
90836bcbe3
|
|
@ -0,0 +1,57 @@
|
||||||
|
#ifndef CGAL_MINKOWSKI_SUM_HOLE_FILTER_2_H
|
||||||
|
#define CGAL_MINKOWSKI_SUM_HOLE_FILTER_2_H
|
||||||
|
|
||||||
|
#include <CGAL/basic.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
template <class Kernel_, class Container_>
|
||||||
|
class Hole_filter_2
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef Kernel_ Kernel;
|
||||||
|
typedef Container_ Container;
|
||||||
|
|
||||||
|
typedef CGAL::Polygon_with_holes_2<Kernel, Container> Polygon_with_holes_2;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void operator()(const Polygon_with_holes_2 &pgn1, const Polygon_with_holes_2 &pgn2,
|
||||||
|
Polygon_with_holes_2 &filtered_pgn1) const
|
||||||
|
{
|
||||||
|
filtered_pgn1 = pgn1;
|
||||||
|
|
||||||
|
Bbox_2 boundary_bbox;
|
||||||
|
typename Polygon_with_holes_2::Hole_iterator it;
|
||||||
|
|
||||||
|
std::vector<typename Polygon_with_holes_2::Hole_iterator> to_erase;
|
||||||
|
boundary_bbox = pgn2.outer_boundary().bbox();
|
||||||
|
|
||||||
|
it = filtered_pgn1.holes_begin();
|
||||||
|
while (it != filtered_pgn1.holes_end())
|
||||||
|
{
|
||||||
|
Bbox_2 hole_bbox = (*it).bbox();
|
||||||
|
|
||||||
|
if (hole_bbox.ymax()-hole_bbox.ymin() < boundary_bbox.ymax()-boundary_bbox.ymin() ||
|
||||||
|
hole_bbox.xmax()-hole_bbox.xmin() < boundary_bbox.xmax()-boundary_bbox.xmin())
|
||||||
|
{
|
||||||
|
to_erase.push_back(it);
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
typename std::vector<typename Polygon_with_holes_2::Hole_iterator>::iterator it2 = to_erase.begin();
|
||||||
|
while (it2 != to_erase.end())
|
||||||
|
{
|
||||||
|
filtered_pgn1.erase_hole(*it2);
|
||||||
|
++it2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace CGAL
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include <CGAL/basic.h>
|
#include <CGAL/basic.h>
|
||||||
#include <CGAL/Polygon_with_holes_2.h>
|
#include <CGAL/Polygon_with_holes_2.h>
|
||||||
|
|
||||||
|
#include <CGAL/Minkowski_sum_2/Hole_filter_2.h>
|
||||||
#include <CGAL/Minkowski_sum_2/Minkowski_sum_by_reduced_convolution_2.h>
|
#include <CGAL/Minkowski_sum_2/Minkowski_sum_by_reduced_convolution_2.h>
|
||||||
#include <CGAL/Minkowski_sum_2/Minkowski_sum_conv_2.h>
|
#include <CGAL/Minkowski_sum_2/Minkowski_sum_conv_2.h>
|
||||||
#include <CGAL/Minkowski_sum_2/Minkowski_sum_decomp_2.h>
|
#include <CGAL/Minkowski_sum_2/Minkowski_sum_decomp_2.h>
|
||||||
|
|
@ -79,11 +80,19 @@ minkowski_sum_reduced_convolution_2(const Polygon_with_holes_2<Kernel_, Containe
|
||||||
typedef Kernel_ Kernel;
|
typedef Kernel_ Kernel;
|
||||||
typedef Container_ Container;
|
typedef Container_ Container;
|
||||||
|
|
||||||
|
Hole_filter_2<Kernel, Container> hole_filter;
|
||||||
|
|
||||||
|
Polygon_with_holes_2<Kernel,Container> filtered_pgn1;
|
||||||
|
Polygon_with_holes_2<Kernel,Container> filtered_pgn2;
|
||||||
|
|
||||||
|
hole_filter(pgn1, pgn2, filtered_pgn1);
|
||||||
|
hole_filter(pgn2, pgn1, filtered_pgn2);
|
||||||
|
|
||||||
Minkowski_sum_by_reduced_convolution_2<Kernel, Container> mink_sum;
|
Minkowski_sum_by_reduced_convolution_2<Kernel, Container> mink_sum;
|
||||||
Polygon_2<Kernel,Container> sum_bound;
|
Polygon_2<Kernel,Container> sum_bound;
|
||||||
std::list<Polygon_2<Kernel,Container> > sum_holes;
|
std::list<Polygon_2<Kernel,Container> > sum_holes;
|
||||||
|
|
||||||
mink_sum (pgn1, pgn2, sum_bound, std::back_inserter(sum_holes));
|
mink_sum (filtered_pgn1, filtered_pgn2, sum_bound, std::back_inserter(sum_holes));
|
||||||
|
|
||||||
return (Polygon_with_holes_2<Kernel,Container> (sum_bound,
|
return (Polygon_with_holes_2<Kernel,Container> (sum_bound,
|
||||||
sum_holes.begin(),
|
sum_holes.begin(),
|
||||||
|
|
@ -252,7 +261,16 @@ minkowski_sum_2(const Polygon_with_holes_2<Kernel_, Container_>& pgn1,
|
||||||
{
|
{
|
||||||
typename Minkowski_sum_by_decomposition_2<DecompositionStrategy_,
|
typename Minkowski_sum_by_decomposition_2<DecompositionStrategy_,
|
||||||
Container_>::Traits_2 traits;
|
Container_>::Traits_2 traits;
|
||||||
return minkowski_sum_2(pgn1, pgn2, decomposition_strategy, traits);
|
|
||||||
|
Hole_filter_2<Kernel_, Container_> hole_filter;
|
||||||
|
|
||||||
|
Polygon_with_holes_2<Kernel_,Container_> filtered_pgn1;
|
||||||
|
Polygon_with_holes_2<Kernel_,Container_> filtered_pgn2;
|
||||||
|
|
||||||
|
hole_filter(pgn1, pgn2, filtered_pgn1);
|
||||||
|
hole_filter(pgn2, pgn1, filtered_pgn2);
|
||||||
|
|
||||||
|
return minkowski_sum_2(filtered_pgn1, filtered_pgn2, decomposition_strategy, traits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -282,7 +300,16 @@ minkowski_sum_2(const Polygon_with_holes_2<Kernel_, Container_>& pgn1,
|
||||||
|
|
||||||
Minkowski_sum_by_decomposition_2<Decomposition_strategy, Container>
|
Minkowski_sum_by_decomposition_2<Decomposition_strategy, Container>
|
||||||
mink_sum(decomposition_strategy, traits);
|
mink_sum(decomposition_strategy, traits);
|
||||||
Polygon_with_holes_2<Kernel, Container> sum = mink_sum(pgn1, pgn2);
|
|
||||||
|
Hole_filter_2<Kernel_, Container_> hole_filter;
|
||||||
|
|
||||||
|
Polygon_with_holes_2<Kernel_,Container_> filtered_pgn1;
|
||||||
|
Polygon_with_holes_2<Kernel_,Container_> filtered_pgn2;
|
||||||
|
|
||||||
|
hole_filter(pgn1, pgn2, filtered_pgn1);
|
||||||
|
hole_filter(pgn2, pgn1, filtered_pgn2);
|
||||||
|
|
||||||
|
Polygon_with_holes_2<Kernel, Container> sum = mink_sum(filtered_pgn1, filtered_pgn2);
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,6 +332,9 @@ minkowski_sum_2(const Polygon_2<Kernel_, Container_>& pgn1,
|
||||||
{
|
{
|
||||||
typename Minkowski_sum_by_decomposition_2<DecompositionStrategy_,
|
typename Minkowski_sum_by_decomposition_2<DecompositionStrategy_,
|
||||||
Container_>::Traits_2 traits;
|
Container_>::Traits_2 traits;
|
||||||
|
|
||||||
|
// TODO: Apply Hole_filter_2
|
||||||
|
|
||||||
return minkowski_sum_2(pgn1, pgn2, decomposition_strategy, traits);
|
return minkowski_sum_2(pgn1, pgn2, decomposition_strategy, traits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -335,6 +365,9 @@ minkowski_sum_2(const Polygon_2<Kernel_, Container_>& pgn1,
|
||||||
|
|
||||||
Minkowski_sum_by_decomposition_2<Decomposition_strategy, Container>
|
Minkowski_sum_by_decomposition_2<Decomposition_strategy, Container>
|
||||||
mink_sum(decomposition_strategy, traits);
|
mink_sum(decomposition_strategy, traits);
|
||||||
|
|
||||||
|
// TODO: Apply Hole_filter_2
|
||||||
|
|
||||||
Polygon_with_holes_2<Kernel, Container> sum = mink_sum(pgn1, pgn2);
|
Polygon_with_holes_2<Kernel, Container> sum = mink_sum(pgn1, pgn2);
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue