mirror of https://github.com/CGAL/cgal
Benchmark program for Minkowski sum
This commit is contained in:
parent
32fb5ecc07
commit
0bd5a1fe1b
|
|
@ -2585,6 +2585,8 @@ Minkowski_sum_2/benchmark/Minkowski_sum_2/data/random.dat -text
|
|||
Minkowski_sum_2/benchmark/Minkowski_sum_2/data/random2.dat -text
|
||||
Minkowski_sum_2/benchmark/Minkowski_sum_2/data/star.dat -text
|
||||
Minkowski_sum_2/benchmark/Minkowski_sum_2/sum_by_decomposition.cpp -text
|
||||
Minkowski_sum_2/benchmark/print_utils.h -text
|
||||
Minkowski_sum_2/benchmark/sum_by_decomposition.cpp -text
|
||||
Minkowski_sum_2/doc_tex/Minkowski_sum_2/fig/Minkowski_sum_2.png -text
|
||||
Minkowski_sum_2/doc_tex/Minkowski_sum_2/fig/approx_offset.fig -text svneol=unset#application/octet-stream
|
||||
Minkowski_sum_2/doc_tex/Minkowski_sum_2/fig/approx_offset.gif -text svneol=unset#image/gif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef _PRINT_UTILS_H_
|
||||
#define _PRINT_UTILS_H_
|
||||
|
||||
#include <CGAL/Polygon_with_holes_2.h>
|
||||
#include <iostream>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pretty-print a CGAL polygon.
|
||||
//
|
||||
template<class Kernel, class Container>
|
||||
void print_polygon (const CGAL::Polygon_2<Kernel, Container>& P)
|
||||
{
|
||||
typename CGAL::Polygon_2<Kernel, Container>::Vertex_const_iterator vit;
|
||||
|
||||
std::cout << "[ " << P.size() << " vertices:";
|
||||
for (vit = P.vertices_begin(); vit != P.vertices_end(); ++vit)
|
||||
std::cout << " (" << *vit << ')';
|
||||
std::cout << " ]" << std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pretty-print a polygon with holes.
|
||||
//
|
||||
template<class Kernel, class Container>
|
||||
void print_polygon_with_holes
|
||||
(const CGAL::Polygon_with_holes_2<Kernel, Container>& pwh)
|
||||
{
|
||||
if (! pwh.is_unbounded())
|
||||
{
|
||||
std::cout << "{ Outer boundary = ";
|
||||
print_polygon (pwh.outer_boundary());
|
||||
}
|
||||
else
|
||||
std::cout << "{ Unbounded polygon." << std::endl;
|
||||
|
||||
typename CGAL::Polygon_with_holes_2<Kernel,Container>::
|
||||
Hole_const_iterator hit;
|
||||
unsigned int k = 1;
|
||||
|
||||
std::cout << " " << pwh.number_of_holes() << " holes:" << std::endl;
|
||||
for (hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit, ++k)
|
||||
{
|
||||
std::cout << " Hole #" << k << " = ";
|
||||
print_polygon (*hit);
|
||||
}
|
||||
std::cout << " }" << std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
//! \file examples/Minkowski_sum_2/sum_by_decomposition.cpp
|
||||
// Computing the Minkowski sum of two non-convex polygons read from a file
|
||||
// using the small-side angle-bisector decomposition strategy.
|
||||
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/minkowski_sum_2.h>
|
||||
#include <CGAL/Small_side_angle_bisector_decomposition_2.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <CGAL/Timer.h>
|
||||
#include "print_utils.h"
|
||||
|
||||
struct Kernel : public CGAL::Exact_predicates_exact_constructions_kernel {};
|
||||
|
||||
typedef Kernel::Point_2 Point_2;
|
||||
typedef CGAL::Polygon_2<Kernel> Polygon_2;
|
||||
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes_2;
|
||||
|
||||
int main ()
|
||||
{
|
||||
CGAL::Timer t_mink_sum;
|
||||
// Open the input file.
|
||||
std::ifstream in_file ("data/random2.dat");
|
||||
|
||||
if (! in_file.is_open())
|
||||
{
|
||||
std::cerr << "Failed to open the input file." << std::endl;
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Read the two polygons from the file and compute their Minkowski sum.
|
||||
Polygon_2 P, Q;
|
||||
|
||||
in_file >> P >> Q;
|
||||
in_file.close();
|
||||
|
||||
|
||||
// Compute the Minkowski sum using the decomposition approach.
|
||||
CGAL::Small_side_angle_bisector_decomposition_2<Kernel> ssab_decomp;
|
||||
|
||||
t_mink_sum.start();
|
||||
|
||||
Polygon_with_holes_2 sum = minkowski_sum_2 (P, Q, ssab_decomp);
|
||||
|
||||
t_mink_sum.stop();
|
||||
|
||||
std::cout << "Done! Time:" << t_mink_sum.time() << " seconds\n P (+) Q = "; print_polygon_with_holes (sum);
|
||||
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in New Issue