* Permissios of the files changed

* Trim functionality added to conic and circular_arc traits.
 * Examples for conic_polycurve and circular_arc_polycurve added.
This commit is contained in:
Waqar Khan 2014-05-24 21:55:36 +02:00
parent ae79550a0d
commit 52c6d3044d
20 changed files with 254 additions and 81 deletions

View File

@ -136,14 +136,13 @@ int main ()
std::cout << "Opposite of X-monotone Polycurve 1: " << opposite_x_monotone_polycurve_1 << std::endl;
//Waqar: fix this once the intersect functor for circular arc polycurve is fixed.
// Polycurve_circ_arc_arrangment polycurve_arrangment(&traits);
// insert(polycurve_arrangment, polycurve_1);
// insert(polycurve_arrangment, polycurve_2);
// insert(polycurve_arrangment, x_polycurve_1);
// insert(polycurve_arrangment, x_polycurve_2);
Polycurve_circ_arc_arrangment polycurve_arrangment(&traits);
insert(polycurve_arrangment, polycurve_1);
//insert(polycurve_arrangment, polycurve_2);
//insert(polycurve_arrangment, x_polycurve_1);
//insert(polycurve_arrangment, x_polycurve_2);
// std::cout << "Arrangment Statistics: " << std::endl;
// print_arrangement (polycurve_arrangment);
print_arrangement (polycurve_arrangment);
return 0;

View File

@ -32,6 +32,7 @@
#include <fstream>
namespace CGAL {
/*! \class
@ -58,6 +59,8 @@ public:
typedef Tag_true Has_left_category;
typedef Tag_true Has_merge_category;
typedef Tag_false Has_do_intersect_category;
typedef Tag_false Has_construct_x_monotone_curve_from_two_points_category;
//typedef boost::false_type Has_construct_x_monotone_curve_from_two_points_category;
typedef Arr_oblivious_side_tag Left_side_category;
typedef Arr_oblivious_side_tag Bottom_side_category;
@ -695,6 +698,36 @@ public:
return Construct_opposite_2();
}
class Trim_2
{
/*!\brief
* Returns a trimmed version of an arc
*
* \param cv The arc
* \param p the new first endpoint
* \param q the new second endpoint
* \return The trimmed arc
*
* \pre p != q
* \pre both points must be interior and must lie on \c cv
*/
public:
X_monotone_curve_2 operator()(const X_monotone_curve_2& xcv,
const Point_2& src,
const Point_2 tgt)const
{
return (xcv.trim(src, tgt));
}
};
//get a Trim_2 functor object
Trim_2 trim_2_object() const
{
return Trim_2();
}
};
} //namespace CGAL

View File

@ -73,6 +73,8 @@ public:
typedef Tag_true Has_left_category;
typedef Tag_true Has_merge_category;
typedef Tag_false Has_do_intersect_category;
//typedef boost::true_type Has_line_segment_constructor;
typedef Tag_true Has_construct_x_monotone_curve_from_two_points_category;
typedef Arr_oblivious_side_tag Left_side_category;
typedef Arr_oblivious_side_tag Bottom_side_category;
@ -814,9 +816,38 @@ public:
{
return Construct_opposite_2();
}
class Trim_2
{
/*!\brief
* Returns a trimmed version of an arc
*
* \param cv The arc
* \param p the new first endpoint
* \param q the new second endpoint
* \return The trimmed arc
*
* \pre p != q
* \pre both points must be interior and must lie on \c cv
*/
public:
X_monotone_curve_2 operator()(const X_monotone_curve_2& xcv,
const Point_2& src,
const Point_2 tgt)const
{
return (xcv.trim(src, tgt));
}
};
//get a Trim_2 functor object
Trim_2 trim_2_object() const
{
return Trim_2();
}
//@}
};
} //namespace CGAL
#endif

View File

@ -796,7 +796,8 @@ public:
_first(),
_second(),
_third(),
_source(), _target(),
_source(),
_target(),
_info (0)
{}
@ -869,50 +870,6 @@ public:
_info = (_info | IS_DIRECTED_RIGHT_MASK);
}
// waqar
// Adding an almost duplicate constructor as the original one is cause conflict when used with
// polycurve_circular_arcs
/*!
* Construct a segment arc from two kernel points
* \param source the source point.
* \ param target the target point.
* \pre source and target are not equal.
*/
//bad idea
// _X_monotone_circle_segment_2 (const Point_2& source,
// const Point_2& target) :
// _source(source.x(), source.y()),
// _target(target.x(), target.y()),
// _info (0)
// {
// //std:: cout << source.x();
// typename Kernel::Point_2 kernel_source (source.x(), source.y());
// typename Kernel::Point_2 kernel_target; //(target.x(), target.y());
// // Line_2 line(kernel_source, kernel_target);
// // _first = line.a();
// // _second = line.b();
// // _third = line.c();
// // // Check if the segment is directed left or right:
// // Comparison_result res = CGAL::compare (kernel_source.x(), kernel_target.x());
// // if (res == EQUAL)
// // {
// // CGAL_precondition (CGAL::sign(_second) == ZERO);
// // // We have a vertical segment - compare the points by their
// // // y-coordinates:
// // _info = (_info | IS_VERTICAL_SEGMENT_MASK);
// // res = CGAL::compare (kernel_source.y(), kernel_target.y());
// // }
// // CGAL_precondition (res != EQUAL);
// // if (res == SMALLER)
// // _info = (_info | IS_DIRECTED_RIGHT_MASK);
// }
//end of duplicate contructor
/*!
* Construct a circular arc.
* \param line The supporting line.
@ -2478,6 +2435,57 @@ protected:
++oi;
}
//waqar
/*
* check if the point lies on the circular arc.
*
* I could have skipped this function and used circ_point_position() instead
* but I think the implementation of that function is wrong as it is not squaring the radius
* in order to check whether the point satisfies the circle equation.
*/
Comparison_result contain_point(const Point_2& p) const
{
Comparison_result res = CGAL::compare (CGAL::square (p.x() - x0()),
CGAL::square(sqr_r()) - CGAL::square (p.y() - y0()));
return res;
}
/*!
* Trim the arc given its new endpoints.
* \param ps The new source point.
* \param pt The new target point.
* \return The new trimmed arc.
* \pre Both ps and pt lies on the arc and must conform with the current
* direction of the arc.
*/
Self trim (const Point_2& ps,
const Point_2& pt) const
{
Self arc = *this;
Kernel ker;
// Make sure that both ps and pt lie on the arc.
CGAL_precondition (this->contain_point (ps) == EQUAL);
CGAL_precondition (this->contain_point (pt) == EQUAL );
//make sure ps and pt are not the same
CGAL_precondition(CGAL::compare(ps.x(), pt.x()) != EQUAL &&
CGAL::compare(ps.y(), pt.y()) != EQUAL);
// Make sure that the endpoints conform with the direction of the arc.
Point_2 source = ps;
Point_2 target = pt;
if( this->is_directed_right() && (ps.x() > pt.x()) )
{
//since the direction of the arc should not be changed. we will interchange the source and the target.
source = pt;
target = ps;
}
arc._source = source;
arc._target = target;
return (arc);
}
//@}
};

View File

@ -30,6 +30,7 @@
#include <iterator>
#include <boost/type_traits/is_same.hpp>
#include <boost/utility/enable_if.hpp>
#include <CGAL/basic.h>
#include <CGAL/tags.h>
@ -55,6 +56,8 @@ namespace CGAL {
typedef typename Segment_traits_2::Top_side_category Top_side_category;
typedef typename Segment_traits_2::Right_side_category Right_side_category;
typedef typename Segment_traits_2::Has_construct_x_monotone_curve_from_two_points_category Has_construct_x_monotone_curve_from_two_points_category;
typedef typename Arr_are_all_sides_oblivious_tag
<Left_side_category, Bottom_side_category,
Top_side_category, Right_side_category>::result
@ -1117,6 +1120,9 @@ namespace CGAL {
/* Append a point `p` to an existing polyline `cv` at the back. */
void operator()(Curve_2& cv, const Point_2& p) const
{
//waqar
//CGAL_static_assertion_msg((Has_construct_x_monotone_curve_from_two_points_category()), "X_monotone_curve_2 does not support construction from two points!");
//typename boost::enable_if_c< Has_construct_x_monotone_curve_from_two_points_category::value >::type* = 0
typedef typename Curve_2::Segments_size_type size_type;
size_type num_seg = cv.number_of_segments();
CGAL_precondition(num_seg > 0);
@ -1153,6 +1159,8 @@ namespace CGAL {
/* Append a point `p` to an existing polyline `xcv` at the back. */
void operator()(X_monotone_curve_2& xcv, const Point_2& p) const
{
//waqar
//CGAL_static_assertion_msg((Has_construct_x_monotone_curve_from_two_points_category()), "X_monotone_curve_2 does not support construction from two points!");
typedef typename X_monotone_curve_2::Segments_size_type size_type;
size_type num_seg = xcv.number_of_segments();
CGAL_precondition(num_seg > 0);
@ -1269,6 +1277,9 @@ namespace CGAL {
/* Append a point `p` to an existing polyline `cv` at the front. */
void operator()(Curve_2& cv, const Point_2& p) const
{
//waqar
//CGAL_static_assertion_msg((Has_construct_x_monotone_curve_from_two_points_category()), "X_monotone_curve_2 does not support construction from two points!");
CGAL_precondition_code
(
typedef typename Curve_2::Segments_size_type size_type;
@ -1300,6 +1311,9 @@ namespace CGAL {
/* Append a point `p` to an existing polyline `xcv` at the front. */
void operator()(const X_monotone_curve_2& xcv, Point_2& p) const
{
//waqar
//CGAL_static_assertion_msg((Has_construct_x_monotone_curve_from_two_points_category()), "X_monotone_curve_2 does not support construction from two points!");
const Segment_traits_2* seg_traits = m_poly_traits.segment_traits_2();
CGAL_precondition_code
(
@ -1545,10 +1559,16 @@ namespace CGAL {
* \return The past-the-end iterator.
*/
template <typename OutputIterator>
OutputIterator operator()(const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2,
OutputIterator oi) const
OutputIterator
//waqar
//typename boost::enable_if_c<Has_line_segment_constructor::value, OutputIterator>::type
operator()(const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2,
OutputIterator oi) const
//typename boost::enable_if_c< Has_line_segment_constructor::value >::type* = 0) const
{
//waqar
//CGAL_static_assertion_msg((Has_line_segment_constructor::value), "X_monotone_curve_2 does not support construction from Line_segment!");
const Segment_traits_2* seg_traits = m_poly_traits.segment_traits_2();
Compare_y_at_x_2 cmp_y_at_x = m_poly_traits.compare_y_at_x_2_object();
typename Segment_traits_2::Equal_2 equal = seg_traits->equal_2_object();
@ -1794,7 +1814,8 @@ namespace CGAL {
*oi++ = make_object(ip);
}
}
return oi;
return oi;
}
};
@ -2804,6 +2825,28 @@ namespace CGAL {
return from;
}
class Trim_2
{
/*!\brief
* add comments
*/
public:
X_monotone_curve_2 operator()(const X_monotone_curve_2& xcv,
const Point_2& src,
const Point_2 tgt)const
{
return (xcv);
}
};
//get a Trim_2 functor object
Trim_2 trim_2_object() const
{
return Trim_2();
}
// A utility class that compare a curve-end with a point.
template <typename Comparer>
class Compare_points {

View File

@ -33,6 +33,8 @@
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <fstream>
namespace CGAL {
template <class Kernel_ = Exact_predicates_exact_constructions_kernel>
@ -65,6 +67,7 @@ public:
typedef Tag_true Has_left_category;
typedef Tag_true Has_merge_category;
typedef Tag_false Has_do_intersect_category;
typedef Tag_true Has_construct_x_monotone_curve_from_two_points_category;
typedef Arr_oblivious_side_tag Left_side_category;
typedef Arr_oblivious_side_tag Bottom_side_category;
@ -1183,4 +1186,5 @@ InputStream& operator>> (InputStream& is, Arr_segment_2<Kernel>& seg)
} //namespace CGAL
#endif

View File

View File

View File

@ -910,7 +910,7 @@ bool Traits_test<Geom_traits_T>::
intersect_wrapper(std::istringstream& str_stream)
{
//I am disabling this test only for polycurve_circular_arc tarits until it is resolved
#if TEST_GEOM_TRAITS != POLYCURVE_CIRCULAR_ARC_GEOM_TRAITS
//#if TEST_GEOM_TRAITS != POLYCURVE_CIRCULAR_ARC_GEOM_TRAITS
typedef Geom_traits_T Traits;
typedef typename Traits::Point_2 Point_2;
@ -965,7 +965,7 @@ intersect_wrapper(std::istringstream& str_stream)
object_vec.clear();
#endif
//#endif
return true;
}

View File

@ -1142,21 +1142,21 @@ test_polycurve_circular_arc_traits()
execute_commands_new_structure Polycurves_circular_arcs polycurve_circular_arc_traits \
COMPARE_Y_AT_X \
EQUAL \
# IS_VERTICAL \
# SPLIT \
# ARE_MERGEABLE \
# COMPARE_Y_AT_X_LEFT \
# COMPARE_Y_AT_X_RIGHT \
# MAKE_X_MONOTONE \
# PUSH_BACK \
# PUSH_FRONT \
# COMPARE_X_POLYCURVE \
# COMPARE_XY_POLYCURVE \
# NUMBER_OF_POINTS \
# VERTEX \
# CONSTRUCT_OPPOSITE \
# MERGE \
# COMPARE_ENDPOINTS_XY
IS_VERTICAL \
SPLIT \
ARE_MERGEABLE \
COMPARE_Y_AT_X_LEFT \
COMPARE_Y_AT_X_RIGHT \
MAKE_X_MONOTONE \
PUSH_BACK \
PUSH_FRONT \
COMPARE_X_POLYCURVE \
COMPARE_XY_POLYCURVE \
NUMBER_OF_POINTS \
VERTEX \
CONSTRUCT_OPPOSITE \
MERGE \
COMPARE_ENDPOINTS_XY
#INTERSECT
else

View File

@ -1,6 +1,7 @@
## -*- comment-start: "#"; -*-
# Format
# <Command> <x-curve 1> <x-curve 2> <Number of intersections expected> <Intersection type> <multiplicity of intersection point or curve>
# <Command> <x-curve 1> <x-curve 2> <Number of intersections expected> <Intersection type> <intersecting point/curve id>
# <multiplicity of intersection point or curve>
#
# Intersection type: 0 if intersection is just a point, 1 if a curve is overlapping
#

View File

@ -40,6 +40,8 @@ typedef Polycurve_arc_traits_2::X_monotone_curve_2 X_mono
typedef Polycurve_arc_traits_2::Curve_2 Polycurve;
typedef Kernel::Circle_2 Circle_2;
typedef Arc_traits_2::Has_construct_x_monotone_curve_from_two_points_category Has_construct_x_monotone_curve_from_two_points_category;
template<typename Curve>
bool check_compare_y_at_x_2(Curve& cv)
@ -144,10 +146,10 @@ int main ()
X_monotone_polycurve x_polycurve_2 = traits.construct_x_monotone_curve_2_object()( x_curves.begin(), x_curves.end() );
//testing for arc construction from two points.
Arc_x_monotone_section_2 x_segment( Kernel::Point_2(0, 0), Kernel::Point_2(2, 0) );
x_curves.clear();
x_curves.push_back(x_segment);
X_monotone_polycurve x_polycurve_3 = traits.construct_x_monotone_curve_2_object()( x_curves.begin(), x_curves.end() );
//Arc_x_monotone_section_2 x_segment( Kernel::Point_2(0, 0), Kernel::Point_2(2, 0) );
//x_curves.clear();
//x_curves.push_back(x_segment);
//X_monotone_polycurve x_polycurve_3 = traits.construct_x_monotone_curve_2_object()( x_curves.begin(), x_curves.end() );
//std::cout<< "x_polycurve_3: " << x_polycurve_3 << std::endl;
@ -180,7 +182,25 @@ int main ()
// check_compare_y_at_x_2(x_polycurve_1);
// check_intersect(x_polycurve_1, x_polycurve_2);
check_make_x_monotone(curve_1);
//check_make_x_monotone(curve_1);
//checking if the cgal_assertion for curve construction for two points work or not.
//Point_2 push_back_point( Number_type (10, 1), Number_type (0, 1));
//traits.push_back_2_object()(x_polycurve_1, push_back_point);
if(Has_construct_x_monotone_curve_from_two_points_category())
std::cout << "It has a line segment constructor. " << std::endl;
//checking for trim.
Arc_traits_2 arc_traits;
source = Point_2 ( Number_type (1, 1), Number_type (0, 1) );
target = Point_2 ( Number_type (3, 1), Number_type (2, 1));
// source = Point_2 ( Number_type (2, 1), Number_type (-2, 1) );
// target = Point_2 ( Number_type (3, 1), Number_type (4, 1));
std::cout << " curve is : " << xc2 << std::endl;
Arc_x_monotone_section_2 trimmed_curve = arc_traits.trim_2_object()(xc2, source, target);
std::cout << "trimmed conic curve is : " << trimmed_curve << std::endl;
return 0;

View File

@ -21,6 +21,9 @@ int main ()
#include <CGAL/Arr_polyline_traits_2.h>
#include <CGAL/Arr_conic_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/tags.h>
#include <CGAL/Arr_tags.h>
#include <boost/type_traits/is_same.hpp>
//#include <CGAL/Arr_geometry_traits/Polyline_2.h>
@ -44,6 +47,8 @@ typedef CGAL::Arr_polyline_traits_2<Conic_traits_2> Polycu
typedef Polycurve_conic_traits_2::X_monotone_curve_2 Pc_x_monotone_curve_2;
//typedef Polycurve_conic_traits_2::Point_2 polypoint;
typedef Conic_traits_2::Has_construct_x_monotone_curve_from_two_points_category Has_construct_x_monotone_curve_from_two_points_category;
// typedef CGAL::Arr_polyline_traits_2<
// CGAL::Arr_conic_traits_2<CGAL::Cartesian<BigRat>,
@ -641,6 +646,11 @@ void check_compare_points(Curve& cv)
CGAL::Arr_parameter_space result = traits.parameter_space_in_x_2_object()(cv, CGAL::ARR_MAX_END);
}
// void check_enable_if(int a, int b, boost::enable_if<boost::is_same<Has_construct_x_monotone_curve_from_two_points_category(), boost::true_type>::type > )
// {
// std::cout << a+b << std::endl;
// }
int main ()
{
Polycurve_conic_traits_2 traits;
@ -732,6 +742,19 @@ int main ()
Polycurve_conic_traits_2::Curve_2 Expected_push_back_result = construct_polycurve( conic_curves.begin(), conic_curves.end() );
// //checking the orientattion consistency
// Conic_curve_2 c21(0,1,0,1,0,0,CGAL::CLOCKWISE, Conic_point_2( Algebraic(9), Algebraic(-3) ), Conic_point_2( Algebraic(0), Algebraic(0) ) );
// Conic_curve_2 c20(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2( Algebraic(0), Algebraic(0) ), Conic_point_2( Algebraic(3), Algebraic(9) ) );
// Conic_x_monotone_curve_2 xc20 (c20);
// Conic_x_monotone_curve_2 xc21 (c21);
// xmono_conic_curves_2.clear();
// xmono_conic_curves_2.push_back(xc20);
// xmono_conic_curves_2.push_back(xc21);
// Pc_x_monotone_curve_2 eric_polycurve = construct_x_mono_polycurve(xmono_conic_curves_2.begin(), xmono_conic_curves_2.end());
// std::cout << "the polycurve is: " << eric_polycurve << std::endl;
// std::cout<< std::endl;
@ -782,11 +805,22 @@ int main ()
// check_compare_y_at_x_left();
// std::cout<< std::endl;
check_compare_points(conic_x_mono_polycurve_1);
//check_compare_points(conic_x_mono_polycurve_1);
//number of segments
//std::cout<< "Number of segments: " << traits.number_of_points_2_object()(base_curve_push_back) << std::endl;
Conic_traits_2 con_traits;
Conic_point_2 ps2 (1, 1);
Conic_point_2 pt2 (2, 4);
std::cout << "conic curve is : " << xc3 << std::endl;
Conic_x_monotone_curve_2 trimmed_curve = con_traits.trim_2_object()(xc3, ps2, pt2);
std::cout << "trimmed conic curve is : " << trimmed_curve << std::endl;
if(Has_construct_x_monotone_curve_from_two_points_category())
std::cout << "It has a line segment constructor. " << std::endl;
return 0;
}

View File