Enhanced test

This commit is contained in:
Efi Fogel 2023-05-28 17:26:04 +03:00
parent b781d6a2f8
commit f247756bfb
5 changed files with 211 additions and 208 deletions

View File

@ -7,7 +7,6 @@ project(Surface_sweep_2_Tests)
find_package(CGAL REQUIRED COMPONENTS Core)
set(CGAL_SEGMENT_TRAITS 1)
set(CGAL_SEGMENT_LEDA_TRAITS 2)
set(CGAL_POLYLINE_TRAITS 11)
set(CGAL_CONIC_TRAITS 21)
@ -38,16 +37,18 @@ function(compile_and_run_sweep name source_file point_location traits data_set)
file(
GLOB files
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/${data_set}/*")
"${CMAKE_CURRENT_SOURCE_DIR}/${data_set}/*.txt")
foreach(file ${files})
# message("test ${source_file} ${file}")
# message("test ${source_file} ${file}")
string(MAKE_C_IDENTIFIER "${name} ${file}" test_name)
# message(" --> ${test_name}")
# message(" --> ${test_name}")
cgal_add_test(${name} TEST_NAME ${test_name} ARGUMENTS ${file})
endforeach()
endfunction()
compile_and_run_sweep(test_sweep test_sweep.cpp ${NAIVE} ${CGAL_SEGMENT_TRAITS}
"DATA/segments_tight")
compile_and_run_sweep(test_sweep_conic test_sweep_conic.cpp ${NAIVE}
${CGAL_CONIC_TRAITS} "DATA/conics")
# compile_and_run_sweep(test_sweep test_sweep.cpp ${NAIVE} ${CGAL_SEGMENT_TRAITS}
# "DATA/segments_tight")
# compile_and_run_sweep(test_sweep_conic test_sweep_conic.cpp ${NAIVE}
# ${CGAL_CONIC_TRAITS} "DATA/conics")
compile_and_run_sweep(test_sweep_polyline test_sweep.cpp ${NAIVE}
${CGAL_POLYLINE_TRAITS} "DATA/polylines")

View File

@ -1,47 +1,44 @@
#ifndef _COMPARE_CURVE_LIST_H
#define _COMPARE_CURVE_LIST_H
#ifndef _COMPARE_CURVES_H
#define _COMPARE_CURVES_H
#include <list>
#include <algorithm>
template <class Traits>
class Equal_pred
{
template <typename Traits>
class Equal_pred {
public:
typedef typename Traits::Point_2 Point_2;
typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2;
using Point_2 = typename Traits::Point_2;
using X_monotone_curve_2 = typename Traits::X_monotone_curve_2;
Equal_pred(const Traits& traits) : m_traits(traits) {}
bool operator()(const Point_2& p1, const Point_2& p2)
{
return(Traits().equal_2_object()(p1, p2));
}
{ return(m_traits.equal_2_object()(p1, p2)); }
bool operator()(const X_monotone_curve_2& c1, const X_monotone_curve_2& c2)
{
return(Traits().equal_2_object()(c1, c2));
}
{ return(m_traits.equal_2_object()(c1, c2)); }
private:
const Traits& m_traits;
};
template <class List, class Traits>
bool compare_lists(const List& list1, const List& list2, Traits& /*tr*/)
{
typedef typename List::const_iterator Iter;
Iter begin1 = list1.begin();
Iter end1 = list1.end();
Iter begin2 = list2.begin();
if(! (list1.size() == list2.size()))
{
std::cout << "The lists are not of the same lengths ("
template <typename List, typename Traits>
bool compare_lists(const List& list1, const List& list2, Traits& traits) {
if(! (list1.size() == list2.size())) {
std::cerr << "Error: The lists are not of the same lengths ("
<< list1.size() << "," << list2.size() << ")\n";
return false;
}
Equal_pred<Traits> eq;
return std::equal(begin1, end1, begin2, eq);
Equal_pred<Traits> eq(traits);
auto rc = std::equal(list1.begin(), list1.end(), list2.begin(), eq);
if (! rc) {
std::cerr << "Error: The curves do not match\n";
return false;
}
return true;
}

View File

@ -78,12 +78,11 @@ compile()
compile_and_run()
{
echo "---$1---"
# running general test
if compile $1 $2 $3 ; then
echo " compilation of $1 succeeded" >> $ERRORFILE
echo " compilation of $1 succeeded" >> $ERRORFILE
SUBCURVES=""
run $1 $2 $3 $4
SUBCURVES="subcurves"
@ -93,14 +92,13 @@ compile_and_run()
fi
eval "2>&1 ${MAKE_CMD} CGAL_MAKEFILE=$CGAL_MAKEFILE clean > /dev/null "
}
clean_tests()
{
if [ "${TEST_WITH_CMAKE}" != "FALSE" ]; then
#
# The clean target generated by CMake under cygwin
# The clean target generated by CMake under cygwin
# always fails for some reason
#
if ! ( uname | grep -q "CYGWIN" ) ; then
@ -117,7 +115,7 @@ compile_and_run_sweep()
# running general test
if compile $1 $2 $3 ; then
echo " compilation of $1 succeeded" >> $ERRORFILE
echo " compilation of $1 succeeded" >> $ERRORFILE
run $1 $2 $3 $4
else
echo " ERROR: compilation of $1 failed" >> $ERRORFILE
@ -134,7 +132,7 @@ run()
for DATAFILE in ${datafiles}
do
if [ -d $DATAFILE ]; then
echo "$DATEFILE is a directory"
echo "$DATEFILE is a directory"
continue
fi
@ -158,7 +156,6 @@ run()
echo " ERROR: could not execute $1 $DATAFILE $SUBCURVES" >> $ERRORFILE
fi
done
}
run_io()
@ -178,20 +175,20 @@ run_io()
for DATAFILE in ${datafiles}
do
if [ -d $DATAFILE ]; then
echo "$DATEFILE is a directory"
echo "$DATEFILE is a directory"
continue
fi
IOFILE="${iofiles}`basename ${DATAFILE}`_${SUFFIO}"
echo $IOFILE
if [ -f $1 ] ; then
rm -f arr.txt
DATANAME=`basename $DATAFILE`
IONAME=`basename $IOFILE`
IONAME=`basename $IOFILE`
OUTPUTFILE=ProgramOutput.$3.$1.$DATANAME.$PLATFORM.$2
rm -f $OUTPUTFILE
@ -246,6 +243,7 @@ TRAP=1 # Trapezoidal decomposition
NAIVE=2
WALK=3
#run the test for new sweep
#run the test for new sweep
(compile_and_run_sweep test_sweep $NAIVE $CGAL_SEGMENT_TRAITS "DATA/segments_tight")
(compile_and_run_sweep test_sweep_conic $NAIVE $CGAL_CONIC_TRAITS "DATA/conics")
(compile_and_run_sweep test_sweep $NAIVE $CGAL_POLYLINE_TRAITS "DATA/polylines

View File

@ -1,4 +1,3 @@
#! /bin/bash
./cgal_test_base -cmake

View File

@ -1,6 +1,5 @@
// examples/Pm_with_intersections/example4
// ---------------------------------------
#include <CGAL/config.h>
#include <algorithm>
#include <list>
#include <iostream>
@ -8,10 +7,12 @@
#include <fstream>
#include <string>
#include <CGAL/config.h>
#define CGAL_SEGMENT_TRAITS 1
#define CGAL_SEGMENT_LEDA_TRAITS 2
#define CGAL_POLYLINE_TRAITS 11
#define CGAL_CONIC_TRAITS 21
#define CGAL_POLYCONIC_TRAITS 22
// Picking a default Traits class (this, with the
// PL flag enables the running of the test independently of cgal_make.)
@ -19,13 +20,12 @@
#define CGAL_ARR_TEST_TRAITS CGAL_SEGMENT_TRAITS
#endif
// Making sure test doesn't fail if LEDA is not installed
#if ! defined(CGAL_USE_LEDA) && \
(CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_LEDA_TRAITS || \
CGAL_ARR_TEST_TRAITS == CGAL_CONIC_TRAITS )
// Making sure test doesn't fail if CORE is not installed
#if ! defined(CGAL_USE_CORE) && \
((CGAL_ARR_TEST_TRAITS == CGAL_CONIC_TRAITS) || \
(CGAL_ARR_TEST_TRAITS == CGAL_POLYCONIC_TRAITS))
int main()
{
int main() {
std::cout << "A try to run test with LEDA traits but LEDA is not installed.";
std::cout << std::endl;
std::cout << "Test is not performed.";
@ -33,11 +33,12 @@ int main()
return 0;
}
#elif ! defined(CGAL_USE_GMP) && \
(CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_TRAITS)
int main()
{
#elif ! defined(CGAL_USE_GMP) && \
((CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_TRAITS) || \
(CGAL_ARR_TEST_TRAITS == CGAL_POLYLINE_TRAITS))
int main() {
std::cout << "A try to run test with GMP number type but GMP is not installed.";
std::cout << std::endl;
std::cout << "Test is not performed.";
@ -48,117 +49,123 @@ int main()
#else
// Choose traits
#if CGAL_ARR_TEST_TRAITS==CGAL_SEGMENT_TRAITS
#include <CGAL/Cartesian.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Quotient.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Arr_segment_traits_2.h>
#include<CGAL/Gmpq.h>
#elif CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_LEDA_TRAITS
#include <CGAL/leda_rational.h>
#include <CGAL/Pm_segment_traits_leda_kernel_2.h>
#include <CGAL/Arr_leda_segment_traits_2.h>
#elif CGAL_ARR_TEST_TRAITS == CGAL_POLYLINE_TRAITS
#include <CGAL/Gmpq.h>
#include <CGAL/Cartesian.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Quotient.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
#elif CGAL_ARR_TEST_TRAITS == CGAL_CONIC_TRAITS
#include <CGAL/Cartesian.h>
#include <CGAL/leda_real.h>
#include <CGAL/Arr_conic_traits_2.h>
#elif CGAL_ARR_TEST_TRAITS == CGAL_POLYCONIC_TRAITS
#include <CGAL/Cartesian.h>
#include <CGAL/Arr_conic_traits_2.h>
#include <CGAL/Arr_polycurve_traits_2.h>
#else
#error No traits defined for test
#endif
#include <list>
#include <string>
#include <CGAL/Surface_sweep_2_algorithms.h>
#include "CompareCurveList.h"
#if CGAL_ARR_TEST_TRAITS==CGAL_SEGMENT_TRAITS
#include <CGAL/Surface_sweep_2_algorithms.h>
#include "Compare_curves.h"
#if CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_TRAITS
typedef CGAL::Gmpq NT;
typedef CGAL::Cartesian<NT> Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel> Traits;
#elif CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_LEDA_TRAITS
typedef leda_rational NT;
typedef CGAL::Pm_segment_traits_leda_kernel_2 Kernel;
typedef CGAL::Arr_leda_segment_traits_2<Kernel> Traits;
#elif CGAL_ARR_TEST_TRAITS == CGAL_POLYLINE_TRAITS
typedef CGAL::Quotient<MP_Float> NT;
typedef CGAL::Gmpq NT;
typedef CGAL::Cartesian<NT> Kernel;
typedef CGAL::Arr_segment_cached_traits_2<Kernel> Seg_traits;
typedef CGAL::Arr_segment_traits_2<Kernel> Seg_traits;
typedef CGAL::Arr_polyline_traits_2<Seg_traits> Traits;
#elif CGAL_ARR_TEST_TRAITS == CGAL_CONIC_TRAITS
typedef leda_real NT;
typedef CGAL::Cartesian<NT> Kernel;
typedef CGAL::Arr_conic_traits_2<Kernel> Traits;
typedef CGAL::Arr_conic_traits_2<xxx> Traits;
#elif CGAL_ARR_TEST_TRAITS == CGAL_POLYCURVE_TRAITS
typedef CGAL::Arr_conic_traits_2<xxx> Conic_traits;
typedef CGAL::Arr_polycurve_traits_2<Conic_traits> Traits;
#endif
typedef Traits::Point_2 Point_2;
typedef Traits::X_monotone_curve_2 X_monotone_curve_2;
typedef Traits::Point_2 Point_2;
typedef Traits::Curve_2 Curve_2;
typedef Traits::X_monotone_curve_2 X_monotone_curve_2;
typedef std::list<Point_2> PointList;
typedef PointList::iterator PointListIter;
typedef std::list<Point_2> Points;
typedef std::list<Curve_2> Curves;
typedef std::list<X_monotone_curve_2> X_monotone_curves;
typedef std::list<X_monotone_curve_2> CurveList;
typedef CurveList::iterator CurveListIter;
bool read_curves(std::ifstream& inp, Curves& curves, const Traits& traits);
bool read_xcurves(std::ifstream& inp, X_monotone_curves& xcurves,
const Traits& traits);
bool read_points(std::ifstream& inp, Points& points, const Traits& traits);
bool curves_identical(X_monotone_curves& list1, X_monotone_curves& list2);
bool points_identical(Points& list1, Points& list2);
void ReadCurveList(std::ifstream &inp, CurveList &clist);
void ReadCurveListRational(std::ifstream &inp, CurveList &clist);
void ReadPointList(std::ifstream &inp, PointList &plist);
bool IsCurveListIdentical(CurveList &list1, CurveList &list2);
bool IsPointListIdentical(PointList &list1, PointList &list2);
// istream modifier skips chars until end of line.
std::istream& skip_until_eol(std::istream& in) {
if (in.eof()) return in;
char c;
while (in.get(c) && (c != '\n'));
return in;
}
int main(int argc, char * argv[])
{
// istream modifier that checks for OFF comments and removes them.
std::istream& skip_comment(std::istream& in) {
char c;
while ((in >> c) && (c == '#')) in >> skip_until_eol;
in.putback(c);
return in;
}
if ( argc != 2 )
{
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cout << "Specify a file name " << std::endl;
return -1;
}
std::ifstream inp(argv[1]);
if (!inp.is_open()) {
std::cerr << "Cannot open file " << argv[1] << "!" << std::endl;
if (! inp.is_open()) {
std::cerr << "Error: Cannot open file " << argv[1] << "!" << std::endl;
return -1;
}
CurveList curves;
ReadCurveList(inp, curves);
Traits tr;
Curves curves;
if (! read_curves(inp, curves, tr)) return -1;
// get subcurves w/o overlapping
CurveList curves_no_overlap_list_out;
CGAL::compute_subcurves(curves.begin(),
curves.end(),
std::back_inserter(curves_no_overlap_list_out));
X_monotone_curves curves_no_overlap_out;
CGAL::compute_subcurves(curves.begin(), curves.end(),
std::back_inserter(curves_no_overlap_out),
false, tr);
// get subcurves w/ overlapping
CurveList curves_with_overlap_list_out;
CGAL::compute_subcurves(curves.begin(),
curves.end(),
std::back_inserter(curves_with_overlap_list_out),
true);
X_monotone_curves curves_with_overlap_out;
CGAL::compute_subcurves(curves.begin(), curves.end(),
std::back_inserter(curves_with_overlap_out),
true, tr);
/*std::copy(curves_no_overlap_list_out.begin(),
curves_no_overlap_list_out.end(),
/*std::copy(curves_no_overlap_out.begin(),
curves_no_overlap_out.end(),
std::ostream_iterator<X_monotone_curve_2>(std::cout, "\n"));
std::cout<<"\n\n*******************\n\n";
std::copy(curves_with_overlap_list_out.begin(),
curves_with_overlap_list_out.end(),
std::copy(curves_with_overlap_out.begin(),
curves_with_overlap_out.end(),
std::ostream_iterator<X_monotone_curve_2>(std::cout, "\n"));
return 0;*/
@ -166,134 +173,135 @@ int main(int argc, char * argv[])
// get intersection points (with endpoints)
PointList points_with_ends_list_out;
CGAL::compute_intersection_points(curves.begin(),
curves.end(),
std::back_inserter(points_with_ends_list_out),
true);
Points points_with_ends_out;
CGAL::compute_intersection_points(curves.begin(), curves.end(),
std::back_inserter(points_with_ends_out),
true, tr);
// get intersection points w/o end points
PointList points_without_ends_list_out;
CGAL::compute_intersection_points(curves.begin(),
curves.end(),
std::back_inserter(points_without_ends_list_out),
false);
std::cout << points_without_ends_list_out.size()
<< " points_without_ends_list_out(size)\n";
Points points_without_ends_out;
CGAL::compute_intersection_points(curves.begin(), curves.end(),
std::back_inserter(points_without_ends_out),
false, tr);
std::cout << points_without_ends_out.size()
<< " points_without_ends_out(size)\n";
// check the do_curves_intersecting method
bool do_intersect_out =
CGAL::do_curves_intersect(curves.begin(), curves.end());
// read curves and points from file
CurveList curves_no_overlap_list;
ReadCurveListRational(inp, curves_no_overlap_list);
X_monotone_curves curves_no_overlap;
if (! read_xcurves(inp, curves_no_overlap, tr)) return -1;
PointList points_with_ends_list;
ReadPointList(inp, points_with_ends_list);
Points points_with_ends;
if (! read_points(inp, points_with_ends, tr)) return -1;
PointList points_without_ends_list;
ReadPointList(inp, points_without_ends_list);
Points points_without_ends;
if (! read_points(inp, points_without_ends, tr)) return -1;
int num_faces;
inp >> num_faces;
X_monotone_curves curves_with_overlap;
if (! read_xcurves(inp, curves_with_overlap, tr)) return -1;
CurveList curves_with_overlap_list;
ReadCurveListRational(inp, curves_with_overlap_list);
if ( !compare_lists(curves_no_overlap_list_out,
curves_no_overlap_list, tr) )
if (! compare_lists(curves_no_overlap_out, curves_no_overlap, tr))
return -1;
if ( !compare_lists(curves_with_overlap_list_out,
curves_with_overlap_list, tr) )
if (! compare_lists(curves_with_overlap_out, curves_with_overlap, tr))
return -1;
if ( !compare_lists(points_with_ends_list_out,
points_with_ends_list, tr))
if (! compare_lists(points_with_ends_out, points_with_ends, tr))
return -1;
if ( !compare_lists(points_without_ends_list_out,
points_without_ends_list, tr))
if (! compare_lists(points_without_ends_out, points_without_ends, tr))
return -1;
bool do_intersect = false;
if((points_without_ends_list.size() != 0) ||
(curves_no_overlap_list_out.size() !=
curves_with_overlap_list_out.size()))
if ((points_without_ends.size() != 0) ||
(curves_no_overlap_out.size() != curves_with_overlap_out.size()))
do_intersect = true;
if (do_intersect_out != do_intersect)
if (do_intersect_out != do_intersect) {
std::cerr << "Error: do_intersect()\n";
return -1;
}
std::cout<<"OK\n";
std::cout << "OK\n";
return 0;
}
void ReadCurveList(std::ifstream& inp, CurveList& clist)
{
int count;
inp >> count;
//std::cout << "ReadCurveList " << count << "\n";
#if CGAL_ARR_TEST_TRAITS == CGAL_SEGMENT_TRAITS
for (int i = 0; i < count; i++) {
bool read_curves(std::ifstream& inp, Curves& curves, const Traits&) {
int count;
inp >> skip_comment >> count;
std::cout << "read_curves " << count << "\n";
for (int i = 0; i < count; ++i) {
NT x0, y0, x1, y1;
int ix0, iy0, ix1, iy1;
inp >> ix0 >> iy0 >> ix1 >> iy1;
x0 = ix0; y0 = iy0; x1 = ix1; y1 = iy1;
inp >> skip_comment >> x0 >> y0 >> x1 >> y1;
Point_2 p1(x0, y0);
Point_2 p2(x1, y1);
X_monotone_curve_2 curve(p1, p2);
clist.push_back(curve);
//std::cout << curve << "\n";
}
}
void ReadCurveListRational(std::ifstream& inp, CurveList& clist)
{
int count;
inp >> count;
std::cout << "ReadCurveListRational " << count << "\n";
char ch;
for (int i = 0; i < count; i++) {
int a, b;
inp >> a >> ch >> b;
NT x0(a,b);
inp >> a >> ch >> b;
NT y0(a,b);
Point_2 p1(x0, y0);
inp >> a >> ch >> b;
NT x1(a,b);
inp >> a >> ch >> b;
NT y1(a,b);
Point_2 p2(x1, y1);
X_monotone_curve_2 curve(p1, p2);
clist.push_back(curve);
Curve_2 curve(p1, p2);
curves.push_back(curve);
std::cout << curve << "\n";
}
return true;
}
void ReadPointList(std::ifstream &inp, PointList &plist)
{
bool read_xcurves(std::ifstream& inp, X_monotone_curves& xcurves,
const Traits& traits)
{ return read_curves(inp, xcurves, traits); }
#elif CGAL_ARR_TEST_TRAITS == CGAL_POLYLINE_TRAITS
template <typename Curves_, typename Ctr>
bool read_curves_(std::ifstream& inp, Curves_& curves, const Traits& traits,
const Ctr& ctr) {
int count;
inp >> count;
inp >> skip_comment >> count;
std::cout << "read_curves " << count << "\n";
for (int i = 0; i < count; ++i) {
Points points;
auto rc = read_points(inp, points, traits);
if (! rc) return false;
auto cv = ctr(points.begin(), points.end());
std::cout << cv << "\n";
curves.push_back(cv);
}
return true;
}
bool read_curves(std::ifstream& inp, Curves& curves, const Traits& traits) {
auto ctr_cv = traits.construct_curve_2_object();
return read_curves_(inp, curves, traits, ctr_cv);
}
bool read_xcurves(std::ifstream& inp, X_monotone_curves& xcurves,
const Traits& traits) {
auto ctr_xcv = traits.construct_x_monotone_curve_2_object();
return read_curves_(inp, xcurves, traits, ctr_xcv);
}
#else
#error No traits defined for test
#endif
bool read_points(std::ifstream& inp, Points& points, const Traits&) {
int count;
inp >> skip_comment >> count;
char ch;
std::cout << "ReadPointList " << count << "\n";
std::cout << "read_points " << count << "\n";
for (int i = 0; i < count; i++) {
int a, b;
inp >> a >> ch >> b;
NT x0(a,b);
inp >> a >> ch >> b;
NT y0(a,b);
Point_2 p(x0, y0);
plist.push_back(p);
NT x, y;
inp >> skip_comment >> x >> y;
Point_2 p(x, y);
points.push_back(p);
std::cout << p << "\n";
}
return true;
}
#endif