mirror of https://github.com/CGAL/cgal
enhanced
This commit is contained in:
parent
8b87990e9d
commit
0bf96f10dc
|
|
@ -2216,6 +2216,7 @@ Minkowski_sum_2/test/Minkowski_sum_2/data/F.dat -text
|
||||||
Minkowski_sum_2/test/Minkowski_sum_2/data/G.dat -text
|
Minkowski_sum_2/test/Minkowski_sum_2/data/G.dat -text
|
||||||
Minkowski_sum_2/test/Minkowski_sum_2/data/comb_part1.dat -text
|
Minkowski_sum_2/test/Minkowski_sum_2/data/comb_part1.dat -text
|
||||||
Minkowski_sum_2/test/Minkowski_sum_2/data/comb_part2.dat -text
|
Minkowski_sum_2/test/Minkowski_sum_2/data/comb_part2.dat -text
|
||||||
|
Minkowski_sum_2/test/Minkowski_sum_2/data/deg_square.dat -text
|
||||||
Minkowski_sum_2/test/Minkowski_sum_2/data/fork_part1.dat -text
|
Minkowski_sum_2/test/Minkowski_sum_2/data/fork_part1.dat -text
|
||||||
Minkowski_sum_2/test/Minkowski_sum_2/data/fork_part2.dat -text
|
Minkowski_sum_2/test/Minkowski_sum_2/data/fork_part2.dat -text
|
||||||
Minkowski_sum_2/test/Minkowski_sum_2/data/knife_part1.dat -text
|
Minkowski_sum_2/test/Minkowski_sum_2/data/knife_part1.dat -text
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
5 0 0 4 0 4 4 2 4 0 4
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
./data/rooms_part1.dat 3/1 -sohg
|
./data/rooms_part1.dat 3/1 -sohg
|
||||||
./data/comb_part1.dat 1/1 -so
|
./data/comb_part1.dat 1/1 -so
|
||||||
|
./data/deg_square.dat 1/1 -sohg
|
||||||
|
|
|
||||||
|
|
@ -17,85 +17,71 @@
|
||||||
#include <CGAL/Small_side_angle_bisector_decomposition_2.h>
|
#include <CGAL/Small_side_angle_bisector_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 "read_polygon.h"
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cstring> // for std::strchr
|
#include <cstring> // for std::strchr
|
||||||
#include <cstdio> // for std::sscanf
|
|
||||||
|
|
||||||
|
#include "read_polygon.h"
|
||||||
|
|
||||||
// instead of
|
typedef CGAL::Cartesian<Rational> Kernel;
|
||||||
//typedef CGAL::Cartesian<Rational> Kernel;
|
typedef Kernel::Point_2 Point_2;
|
||||||
// workaround for VC++
|
typedef CGAL::Polygon_2<Kernel> Polygon_2;
|
||||||
struct Kernel : public CGAL::Cartesian<Rational> {};
|
|
||||||
|
|
||||||
typedef Kernel::Point_2 Point_2;
|
typedef CGAL::Gps_circle_segment_traits_2<Kernel> Gps_traits_2;
|
||||||
typedef CGAL::Polygon_2<Kernel> Polygon_2;
|
typedef Gps_traits_2::Polygon_2 Offset_polygon_2;
|
||||||
|
typedef Gps_traits_2::Polygon_with_holes_2 Offset_polygon_with_holes_2;
|
||||||
typedef CGAL::Gps_circle_segment_traits_2<Kernel> Gps_traits_2;
|
|
||||||
typedef Gps_traits_2::Polygon_2 Offset_polygon_2;
|
|
||||||
typedef Gps_traits_2::Polygon_with_holes_2 Offset_polygon_with_holes_2;
|
|
||||||
|
|
||||||
/*! Check if two polygons with holes are the same. */
|
/*! Check if two polygons with holes are the same. */
|
||||||
bool are_equal (const Offset_polygon_with_holes_2& ph1,
|
bool are_equal (const Offset_polygon_with_holes_2& ph1,
|
||||||
const Offset_polygon_with_holes_2& ph2)
|
const Offset_polygon_with_holes_2& ph2)
|
||||||
{
|
{
|
||||||
std::list<Offset_polygon_with_holes_2> sym_diff;
|
std::list<Offset_polygon_with_holes_2> sym_diff;
|
||||||
|
CGAL::symmetric_difference (ph1, ph2, std::back_inserter(sym_diff));
|
||||||
CGAL::symmetric_difference (ph1, ph2,
|
|
||||||
std::back_inserter(sym_diff));
|
|
||||||
|
|
||||||
return (sym_diff.empty());
|
return (sym_diff.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! The main program. */
|
/*! The main program. */
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
const double eps = 0.0001;
|
||||||
|
|
||||||
// Read the input file. Because of the structure of the *.cmd file
|
// Read the input file. Because of the structure of the *.cmd file
|
||||||
// (which is concatenated to the command line) we need to get all the
|
// (which is concatenated to the command line) we need to get all the
|
||||||
// inputs in one command line. This is the reason we read triplets/pairs of
|
// inputs in one command line. This is the reason we read triplets/pairs of
|
||||||
// arguments. Each triplet/double is one input for the program.
|
// arguments. Each triplet/double is one input for the program.
|
||||||
if (argc < 3)
|
if (argc < 3) {
|
||||||
{
|
|
||||||
std::cerr << "Usage (input is triplets of): <polygon> <radius> "
|
std::cerr << "Usage (input is triplets of): <polygon> <radius> "
|
||||||
"[decomposition flags]" <<
|
"[decomposition flags]" << std::endl;
|
||||||
std::endl;
|
return -1;
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the polygon from the input file.
|
unsigned int i = 1;
|
||||||
Polygon_2 pgn;
|
while (i < argc) {
|
||||||
|
// Read the polygon from the input file.
|
||||||
int i = 1;
|
Polygon_2 pgn;
|
||||||
while (i < argc)
|
const char* filename = argv[i];
|
||||||
{
|
if (! read_polygon (filename, pgn)) {
|
||||||
if (! read_polygon (argv[i], pgn))
|
std::cerr << "Failed to read: <" << filename << ">." << std::endl;
|
||||||
{
|
return -1;
|
||||||
std::cerr << "Failed to read: <" << argv[i] << ">." << std::endl;
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the offset radius.
|
// Read the offset radius.
|
||||||
int numer, denom;
|
Rational r;
|
||||||
|
std::istringstream iss (argv[i+1], std::istringstream::in);
|
||||||
|
iss >> r;
|
||||||
|
|
||||||
if (std::sscanf (argv[i+1], "%d/%d", &numer, &denom) != 2)
|
std::cout << "Testing " << filename << " and " << r << std::endl;
|
||||||
{
|
|
||||||
std::cerr << "Invalid radius: " << argv[2] << std::endl;
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Testing " << argv[i] << " and " << argv[i+1] << std::endl;
|
|
||||||
|
|
||||||
Rational r = Rational (numer, denom);
|
|
||||||
const double eps = 0.0001;
|
|
||||||
|
|
||||||
// Read the decomposition flags.
|
// Read the decomposition flags.
|
||||||
bool use_ssab = true;
|
bool use_ssab = true;
|
||||||
bool use_opt = true;
|
bool use_opt = true;
|
||||||
bool use_hm = true;
|
bool use_hm = true;
|
||||||
bool use_greene = true;
|
bool use_greene = true;
|
||||||
|
|
||||||
if (i+2 < argc && argv[i+2][0] == '-')
|
if (((i+2) < argc) && (argv[i+2][0] == '-')) {
|
||||||
{
|
|
||||||
use_ssab = (std::strchr (argv[i+2], 's') != NULL);
|
use_ssab = (std::strchr (argv[i+2], 's') != NULL);
|
||||||
use_opt = (std::strchr (argv[i+2], 'o') != NULL);
|
use_opt = (std::strchr (argv[i+2], 'o') != NULL);
|
||||||
use_hm = (std::strchr (argv[i+2], 'h') != NULL);
|
use_hm = (std::strchr (argv[i+2], 'h') != NULL);
|
||||||
|
|
@ -103,7 +89,7 @@ int main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the Minkowski sum using the convolution method.
|
// Compute the Minkowski sum using the convolution method.
|
||||||
Offset_polygon_with_holes_2 offset_conv;
|
Offset_polygon_with_holes_2 offset_conv;
|
||||||
|
|
||||||
std::cout << "Using the convolution method ... ";
|
std::cout << "Using the convolution method ... ";
|
||||||
offset_conv = approximated_offset_2 (pgn, r, eps);
|
offset_conv = approximated_offset_2 (pgn, r, eps);
|
||||||
|
|
@ -116,67 +102,44 @@ int main (int argc, char **argv)
|
||||||
CGAL::Greene_convex_decomposition_2<Kernel> greene_decomp;
|
CGAL::Greene_convex_decomposition_2<Kernel> greene_decomp;
|
||||||
Offset_polygon_with_holes_2 offset_decomp;
|
Offset_polygon_with_holes_2 offset_decomp;
|
||||||
|
|
||||||
if (use_ssab)
|
if (use_ssab) {
|
||||||
{
|
|
||||||
std::cout << "Using the small-side angle-bisector decomposition ... ";
|
std::cout << "Using the small-side angle-bisector decomposition ... ";
|
||||||
offset_decomp = approximated_offset_2 (pgn, r, eps, ssab_decomp);
|
offset_decomp = approximated_offset_2 (pgn, r, eps, ssab_decomp);
|
||||||
if (are_equal (offset_conv, offset_decomp))
|
if (are_equal (offset_conv, offset_decomp))
|
||||||
{
|
|
||||||
std::cout << "OK." << std::endl;
|
std::cout << "OK." << std::endl;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
std::cout << "ERROR (different result)." << std::endl;
|
std::cout << "ERROR (different result)." << std::endl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_opt)
|
if (use_opt) {
|
||||||
{
|
|
||||||
std::cout << "Using the optimal convex decomposition ... ";
|
std::cout << "Using the optimal convex decomposition ... ";
|
||||||
offset_decomp = approximated_offset_2 (pgn, r, eps, opt_decomp);
|
offset_decomp = approximated_offset_2 (pgn, r, eps, opt_decomp);
|
||||||
if (are_equal (offset_conv, offset_decomp))
|
if (are_equal (offset_conv, offset_decomp))
|
||||||
{
|
|
||||||
std::cout << "OK." << std::endl;
|
std::cout << "OK." << std::endl;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
std::cout << "ERROR (different result)." << std::endl;
|
std::cout << "ERROR (different result)." << std::endl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_hm)
|
if (use_hm) {
|
||||||
{
|
|
||||||
std::cout << "Using the Hertel--Mehlhorn decomposition ... ";
|
std::cout << "Using the Hertel--Mehlhorn decomposition ... ";
|
||||||
offset_decomp = approximated_offset_2 (pgn, r, eps, hm_approx_decomp);
|
offset_decomp = approximated_offset_2 (pgn, r, eps, hm_approx_decomp);
|
||||||
if (are_equal (offset_conv, offset_decomp))
|
if (are_equal (offset_conv, offset_decomp))
|
||||||
{
|
|
||||||
std::cout << "OK." << std::endl;
|
std::cout << "OK." << std::endl;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
std::cout << "ERROR (different result)." << std::endl;
|
std::cout << "ERROR (different result)." << std::endl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_greene)
|
if (use_greene) {
|
||||||
{
|
|
||||||
std::cout << "Using the Greene decomposition ... ";
|
std::cout << "Using the Greene decomposition ... ";
|
||||||
offset_decomp = approximated_offset_2 (pgn, r, eps, greene_decomp);
|
offset_decomp = approximated_offset_2 (pgn, r, eps, greene_decomp);
|
||||||
if (are_equal (offset_conv, offset_decomp))
|
if (are_equal (offset_conv, offset_decomp))
|
||||||
{
|
|
||||||
std::cout << "OK." << std::endl;
|
std::cout << "OK." << std::endl;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
std::cout << "ERROR (different result)." << std::endl;
|
std::cout << "ERROR (different result)." << std::endl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i+2 < argc && argv[i+2][0] == '-')
|
i += (((i+2) < argc) && (argv[i+2][0] == '-')) ? 3 : 2;
|
||||||
i += 3;
|
|
||||||
else
|
|
||||||
i += 2;
|
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue