Subject: CGAL users discussion list
List archive
- From: "Sebastien Loriot (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] About Bezier curves in Arrangement
- Date: Thu, 27 Jan 2011 09:39:21 +0100
stzpz wrote:
Hello,Actually, there is no bug here.
I am willing to get the point location of a Bezier curves Arrangement, so I
use Arr_Bezier_curve_traits_2 along with Arr_curve_data_traits_2 to
construct the arrangement with auxiliary data (curve number) attached with
each Bezier curve. And then I perform the point location function to get the
outer connected boundaries of the point. Everything is fine except that the
auxiliary data in the returning boundaries are incorrect.
I use outer_ccb() to get the outer boundaries of the face, then use
curve().supporting_curve() to get the original bezier curves with auxiliary
data. The data in Bezier curves are correct. However, the auxiliary data
corresponding with them are in correct. Here is the code:
// =================== CODE BEGIN =====================
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_algebraic_number_traits.h>
#include <CGAL/Arr_Bezier_curve_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Arr_curve_data_traits_2.h>
#include <CGAL/Arr_walk_along_line_point_location.h>
#include <CGAL/to_rational.h>
#include <list>
using namespace std;
typedef CGAL::CORE_algebraic_number_traits Nt_traits;
typedef Nt_traits::Rational NT;
typedef Nt_traits::Rational Rational;
typedef Nt_traits::Algebraic Algebraic;
typedef CGAL::Cartesian<Rational> Rat_kernel;
typedef CGAL::Cartesian<Algebraic> Alg_kernel;
typedef Rat_kernel::Point_2 Rat_point_2;
typedef CGAL::Arr_Bezier_curve_traits_2<Rat_kernel, Alg_kernel, Nt_traits>
Traits_org_2;
typedef Traits_org_2::Curve_2 Bezier_curve_2;
typedef unsigned int CurveNumber;
typedef CGAL::Arr_curve_data_traits_2<Traits_org_2, CurveNumber> Traits_2;
typedef Traits_2::Curve_2 Bezier_curve_num_2;
typedef Traits_2::Point_2
Point_2;
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
typedef CGAL::Arr_walk_along_line_point_location<Arrangement_2> Naive_pl;
#define TORAT(x) (CGAL::to_rational<Rational>((x)))
void point_loc(Arrangement_2 *arr) {
Naive_pl pl(*arr);
// this point is inside the face
Point_2 p(TORAT(50), TORAT(40));
CGAL::Object obj = pl.locate(p);
Arrangement_2::Face_const_handle f;
if (CGAL::assign(f, obj)) {
if(!f->is_unbounded()) {
Arrangement_2::Ccb_halfedge_const_circulator bound_circ =
f->outer_ccb();
// first sub curve
Bezier_curve_num_2 curr_curve_num =
bound_circ->curve().supporting_curve();
Bezier_curve_2 curr_curve = curr_curve_num;
// ================ the result is INCORRECT of the next line
===================
CurveNumber curve_num = curr_curve_num.data();
cout<<"current curve num: "<<curve_num<<endl;
//
==================================================================
}
}
}
int main (int argc, char *argv[]) {
const char *filename = (argc > 1) ? argv[1] : "test5.dat";
std::ifstream in_file (filename);
int n_curves;
std::list<Bezier_curve_num_2> curves;
Bezier_curve_2 B;
int k;
in_file >> n_curves;
for (k = 0; k < n_curves; k++) {
in_file >> B;
Bezier_curve_num_2 bb(B, k);
curves.push_back (bb);
}
Arrangement_2 arr;
insert (arr, curves.begin(), curves.end());
Arrangement_2::Edge_iterator eit;
for(eit = arr.edges_begin(); eit != arr.edges_end(); ++eit) {
// ============= this result is CORRECT ==============
int num = eit->curve().data();
std::cout<<"Current curve number:"<<num<<std::endl;
// =============================================
}
point_loc(&arr);
return 0;
}
// =================== CODE END =====================
The data file test5.dat is in below
=================== DATA BEGIN =====================
3
2 0 0 100 100
2 20 80 100 0
2 -10 14 120 40
=================== DATA END ======================
Could anybody help me to find out how to get the correct auxiliary data in
the returning boundaries constructed by point location algorithm?
Basically, Traits_2::X_monotone_curve_2 is a pair
(Traits_org_2::X_monotone_curve_2,CurveNumber)
No information is stored to get back to Traits_2::Curve_2 used
to create the X monotone curve. However, the information hold by
the Curve_2 is always copied to the X_monotone_curve_2.
Thus replacing
CurveNumber curve_num = curr_curve_num.data();
by
CurveNumber curve_num = bound_circ->curve().data();
will do what you want.
At this line:
Bezier_curve_num_2 curr_curve_num = bound_circ->curve().supporting_curve();
the constructor of Bezier_curve_num_2 is implicitly called with no data
(we should probably had an explicit keyword to that constructor).
(looking at the doc here:
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Arrangement_on_surface_2_ref/Class_Arr_curve_data_traits_2.html#Cross_link_anchor_1223
you will see no constructor of X_monotone_curve_2 from Curve_2).
There indeed seems to have a bug here.
Besides, it seems that Arr_Bezier_curves_traits_2 cannot handle some special
case of curves like horizontal line segments. For example, using the code
above and another data file below,
=================== DATA BEGIN =====================
3
2 0 0 100 0
2 30 -20 30 80
2 100 -15 -20 75
=================== DATA END ======================
the program will terminate with assertion fails in line 770 of
Bezier_curve_2.h when inserting bezier curves into arrangement. Is it a bug
and how to fix it?
The fix will be posted here.
In the meantime, translating your data by 1 in the (0,1) direction
makes it work (the problem comes in the case the polynomial for y
coordinates is 0).
S.
Does anyone know how to solve them? Thanks very much!
Sincerely yours,
Stzpz
- [cgal-discuss] About Bezier curves in Arrangement, stzpz, 01/26/2011
- Re: [cgal-discuss] About Bezier curves in Arrangement, Sebastien Loriot (GeometryFactory), 01/27/2011
- [cgal-discuss] Re: About Bezier curves in Arrangement, stzpz, 01/28/2011
- Re: [cgal-discuss] About Bezier curves in Arrangement, Sebastien Loriot (GeometryFactory), 01/27/2011
Archive powered by MHonArc 2.6.16.