mirror of https://github.com/CGAL/cgal
added the testing of minkowski sum using vertical decomposition
This commit is contained in:
parent
99f663b8bd
commit
ec54a3dfa5
|
|
@ -1,4 +1,4 @@
|
||||||
rfsohg
|
rfsohgv
|
||||||
data/rooms_part1.dat data/rooms_part2.dat
|
data/rooms_part1.dat data/rooms_part2.dat
|
||||||
data/comb_part1.dat data/comb_part2.dat
|
data/comb_part1.dat data/comb_part2.dat
|
||||||
data/knife_part1.dat data/knife_part2.dat
|
data/knife_part1.dat data/knife_part2.dat
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <CGAL/minkowski_sum_2.h>
|
#include <CGAL/minkowski_sum_2.h>
|
||||||
#include <CGAL/Small_side_angle_bisector_decomposition_2.h>
|
#include <CGAL/Small_side_angle_bisector_decomposition_2.h>
|
||||||
|
#include <CGAL/Polygon_vertical_decomposition_2.h>
|
||||||
#include <CGAL/Polygon_convex_decomposition_2.h>
|
#include <CGAL/Polygon_convex_decomposition_2.h>
|
||||||
#include <CGAL/Boolean_set_operations_2.h>
|
#include <CGAL/Boolean_set_operations_2.h>
|
||||||
#include <CGAL/Timer.h>
|
#include <CGAL/Timer.h>
|
||||||
|
|
@ -23,74 +24,78 @@ bool are_equal(const Polygon_with_holes_2& ph1,
|
||||||
return sym_diff.empty();
|
return sym_diff.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
REDUCED_CONVOLUTION,
|
REDUCED_CONVOLUTION,
|
||||||
FULL_CONVOLUTION,
|
FULL_CONVOLUTION,
|
||||||
SSAB_DECOMP,
|
SSAB_DECOMP,
|
||||||
OPT_DECOMP,
|
OPT_DECOMP,
|
||||||
HM_DECOMP,
|
HM_DECOMP,
|
||||||
GREENE_DECOMP
|
GREENE_DECOMP,
|
||||||
|
VERTICAL_DECOMP
|
||||||
} Strategy;
|
} Strategy;
|
||||||
|
|
||||||
static const char *strategy_names[] =
|
static const char* strategy_names[] = {
|
||||||
{
|
|
||||||
"reduced convolution",
|
"reduced convolution",
|
||||||
"full convolution",
|
"full convolution",
|
||||||
"small-side angle-bisector decomposition",
|
"small-side angle-bisector decomposition",
|
||||||
"optimal convex decomposition",
|
"optimal convex decomposition",
|
||||||
"Hertel-Mehlhorn decomposition",
|
"Hertel-Mehlhorn decomposition",
|
||||||
"Greene decomosition"
|
"Greene decomosition",
|
||||||
|
"Vertical decomosition"
|
||||||
};
|
};
|
||||||
|
|
||||||
Polygon_with_holes_2 compute_minkowski_sum_2(Polygon_2 &p, Polygon_2 &q, Strategy strategy)
|
Polygon_with_holes_2 compute_minkowski_sum_2(Polygon_2& p, Polygon_2& q,
|
||||||
{
|
Strategy strategy)
|
||||||
switch (strategy)
|
|
||||||
{
|
{
|
||||||
|
switch (strategy) {
|
||||||
case REDUCED_CONVOLUTION:
|
case REDUCED_CONVOLUTION:
|
||||||
{
|
|
||||||
return minkowski_sum_reduced_convolution_2(p, q);
|
return minkowski_sum_reduced_convolution_2(p, q);
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FULL_CONVOLUTION:
|
case FULL_CONVOLUTION:
|
||||||
{
|
|
||||||
return minkowski_sum_full_convolution_2(p, q);
|
return minkowski_sum_full_convolution_2(p, q);
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SSAB_DECOMP:
|
case SSAB_DECOMP:
|
||||||
{
|
{
|
||||||
CGAL::Small_side_angle_bisector_decomposition_2<Kernel> decomp;
|
CGAL::Small_side_angle_bisector_decomposition_2<Kernel> decomp;
|
||||||
return minkowski_sum_2(p, q, decomp);
|
return minkowski_sum_2(p, q, decomp);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case OPT_DECOMP:
|
case OPT_DECOMP:
|
||||||
{
|
{
|
||||||
CGAL::Optimal_convex_decomposition_2<Kernel> decomp;
|
CGAL::Optimal_convex_decomposition_2<Kernel> decomp;
|
||||||
return minkowski_sum_2(p, q, decomp);
|
return minkowski_sum_2(p, q, decomp);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case HM_DECOMP:
|
case HM_DECOMP:
|
||||||
{
|
{
|
||||||
CGAL::Hertel_Mehlhorn_convex_decomposition_2<Kernel> decomp;
|
CGAL::Hertel_Mehlhorn_convex_decomposition_2<Kernel> decomp;
|
||||||
return minkowski_sum_2(p, q, decomp);
|
return minkowski_sum_2(p, q, decomp);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case GREENE_DECOMP:
|
case GREENE_DECOMP:
|
||||||
{
|
{
|
||||||
CGAL::Greene_convex_decomposition_2<Kernel> decomp;
|
CGAL::Greene_convex_decomposition_2<Kernel> decomp;
|
||||||
return minkowski_sum_2(p, q, decomp);
|
return minkowski_sum_2(p, q, decomp);
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
case VERTICAL_DECOMP:
|
||||||
|
{
|
||||||
|
CGAL::Polygon_vertical_decomposition_2<Kernel> decomp;
|
||||||
|
return minkowski_sum_2(p, q, decomp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2) {
|
||||||
{
|
std::cerr << "Usage: " << argv[0] << " [method flag] [polygon files]..."
|
||||||
std::cerr << "Usage: " << argv[0] << " [method flag] [polygon files]..." << std::endl;
|
<< std::endl;
|
||||||
std::cerr << "For the method flag, use a subset of the letters 'rfsohg'." << std::endl;
|
std::cerr << "For the method flag, use a subset of the letters 'rfsohg'."
|
||||||
std::cerr << "The program will compute the Minkowski sum of the first and second polygon, of the third and fourth, and so on." << std::endl;
|
<< std::endl;
|
||||||
|
std::cerr << "The program will compute the Minkowski sum of the first "
|
||||||
|
<< "and second polygon, of the third and fourth, and so on."
|
||||||
|
<< std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,8 +103,7 @@ int main (int argc, char **argv)
|
||||||
CGAL::Timer timer;
|
CGAL::Timer timer;
|
||||||
|
|
||||||
std::list<Strategy> strategies;
|
std::list<Strategy> strategies;
|
||||||
for (int i = 0; i < strlen(argv[1]); i++)
|
for (int i = 0; i < strlen(argv[1]); ++i) {
|
||||||
{
|
|
||||||
switch (argv[1][i]) {
|
switch (argv[1][i]) {
|
||||||
case 'r':
|
case 'r':
|
||||||
strategies.push_back(REDUCED_CONVOLUTION);
|
strategies.push_back(REDUCED_CONVOLUTION);
|
||||||
|
|
@ -119,6 +123,9 @@ int main (int argc, char **argv)
|
||||||
case 'g':
|
case 'g':
|
||||||
strategies.push_back(GREENE_DECOMP);
|
strategies.push_back(GREENE_DECOMP);
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
strategies.push_back(VERTICAL_DECOMP);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Unknown flag '" << argv[1][i] << "'" << std::endl;
|
std::cerr << "Unknown flag '" << argv[1][i] << "'" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -126,17 +133,15 @@ int main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 2;
|
int i = 2;
|
||||||
while (i+1 < argc)
|
while (i+1 < argc) {
|
||||||
{
|
|
||||||
std::cout << "Testing " << argv[i] << " + " << argv[i+1] << std::endl;
|
std::cout << "Testing " << argv[i] << " + " << argv[i+1] << std::endl;
|
||||||
read_polygon(argv[i], p);
|
read_polygon(argv[i], p);
|
||||||
read_polygon(argv[i+1], q);
|
read_polygon(argv[i+1], q);
|
||||||
|
|
||||||
bool compare = false;
|
bool compare = false;
|
||||||
Polygon_with_holes_2 reference;
|
Polygon_with_holes_2 reference;
|
||||||
|
std::list<Strategy>::iterator it;
|
||||||
for (std::list<Strategy>::iterator it = strategies.begin(); it != strategies.end(); it++)
|
for (it = strategies.begin(); it != strategies.end(); ++it) {
|
||||||
{
|
|
||||||
std::cout << "Using " << strategy_names[*it] << ": ";
|
std::cout << "Using " << strategy_names[*it] << ": ";
|
||||||
timer.reset();
|
timer.reset();
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
@ -144,20 +149,14 @@ int main (int argc, char **argv)
|
||||||
timer.stop();
|
timer.stop();
|
||||||
std::cout << timer.time() << " s " << std::flush;
|
std::cout << timer.time() << " s " << std::flush;
|
||||||
|
|
||||||
if (compare)
|
if (compare) {
|
||||||
{
|
if (are_equal(reference, result)) std::cout << "(OK)";
|
||||||
if (are_equal(reference, result))
|
else {
|
||||||
{
|
|
||||||
std::cout << "(OK)";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "(ERROR: different result)";
|
std::cout << "(ERROR: different result)";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
compare = true;
|
compare = true;
|
||||||
reference = result;
|
reference = result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue