Andreas' fix for handling vectors of points in CGAL::Object

when intersecting with Lazy_kernel. Add a testfile.
This commit is contained in:
Sébastien Loriot 2011-06-21 13:36:00 +00:00
parent 4cf99c4a3d
commit cfd2c9fa94
4 changed files with 113 additions and 7 deletions

1
.gitattributes vendored
View File

@ -1541,6 +1541,7 @@ Envelope_3/test/Envelope_3/spheres_test.cmd eol=lf
Envelope_3/test/Envelope_3/triangles_test.cmd eol=lf Envelope_3/test/Envelope_3/triangles_test.cmd eol=lf
Filtered_kernel/developer_scripts/profile_cleanup -text Filtered_kernel/developer_scripts/profile_cleanup -text
Filtered_kernel/include/CGAL/internal/Static_filters/Compare_squared_radius_3.h -text Filtered_kernel/include/CGAL/internal/Static_filters/Compare_squared_radius_3.h -text
Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp -text
Generator/demo/Generator/qt3/help/index.html svneol=native#text/html Generator/demo/Generator/qt3/help/index.html svneol=native#text/html
Generator/doc_tex/Generator/Segment_generator_prog1.png -text svneol=unset#image/png Generator/doc_tex/Generator/Segment_generator_prog1.png -text svneol=unset#image/png
Generator/doc_tex/Generator/Segment_generator_prog2.png -text svneol=unset#image/png Generator/doc_tex/Generator/Segment_generator_prog2.png -text svneol=unset#image/png

View File

@ -103,14 +103,20 @@ public:
#include <CGAL/Kernel/interface_macros.h> #include <CGAL/Kernel/interface_macros.h>
if (const std::vector<typename K1::Point_2> * ptr = object_cast<std::vector<typename K1::Point_2> >(&obj)) { #define CGAL_Kernel_obj(X) \
std::vector<typename K2::Point_2> res; if (const std::vector<typename K1::X> * ptr = object_cast<std::vector<typename K1::X> >(&obj)) { \
res.reserve((*ptr).size()); std::vector<typename K2::X> res; \
for(unsigned int i=0; i < (*ptr).size(); i++){ res.reserve((*ptr).size()); \
res.push_back(operator()((*ptr)[i])); for(unsigned int i=0; i < (*ptr).size(); i++){ \
} res.push_back(operator()((*ptr)[i])); \
return make_object(res); } \
return make_object(res); \
} }
CGAL_Kernel_obj(Point_2)
CGAL_Kernel_obj(Point_3)
#undef CGAL_Kernel_obj
CGAL_error_msg("Cartesian_converter is unable to determine what is wrapped in the Object"); CGAL_error_msg("Cartesian_converter is unable to determine what is wrapped in the Object");
return Object(); return Object();

View File

@ -1371,6 +1371,24 @@ struct Ith {
} }
}; };
// This functor selects the i'th element in a vector of T2's
template <typename T2>
struct Ith_for_intersection {
typedef T2 result_type;
int i;
Ith_for_intersection(int i_)
: i(i_)
{}
const T2&
operator()(const Object& o) const
{
const std::vector<T2>* ptr = object_cast<std::vector<T2> >(&o);
return (*ptr)[i];
}
};
template <typename LK, typename AC, typename EC> template <typename LK, typename AC, typename EC>
struct Lazy_cartesian_const_iterator_2 struct Lazy_cartesian_const_iterator_2
@ -1690,6 +1708,29 @@ public:
#include <CGAL/Kernel/interface_macros.h> #include <CGAL/Kernel/interface_macros.h>
// We now check vector<X>
#define CGAL_Kernel_obj(X) \
{ \
const std::vector<typename AK::X>* v_ptr;\
if ( (v_ptr = object_cast<std::vector<typename AK::X> >(& (lo.approx()))) ) { \
\
std::vector<typename LK::X> V;\
V.resize(v_ptr->size()); \
for (unsigned int i = 0; i < v_ptr->size(); i++) { \
V[i] = typename LK::X(new Lazy_rep_1<Ith_for_intersection<typename AK::X>, \
Ith_for_intersection<typename EK::X>, E2A, Lazy_object> \
(Ith_for_intersection<typename AK::X>(i), Ith_for_intersection<typename EK::X>(i), lo)); \
\
} \
return make_object(V); \
}\
}
CGAL_Kernel_obj(Point_2)
CGAL_Kernel_obj(Point_3)
#undef CGAL_Kernel_obj
std::cerr << "object_cast inside Lazy_construction_rep::operator() failed. It needs more else if's (#1)" << std::endl; std::cerr << "object_cast inside Lazy_construction_rep::operator() failed. It needs more else if's (#1)" << std::endl;
std::cerr << "dynamic type of the Object : " << lo.approx().type().name() << std::endl; std::cerr << "dynamic type of the Object : " << lo.approx().type().name() << std::endl;

View File

@ -0,0 +1,58 @@
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersection_2.h>
#include <CGAL/intersection_3.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Segment_2 Segment_2;
typedef K::Triangle_2 Triangle_2;
typedef K::Triangle_3 Triangle_3;
typedef K::Point_2 Point_2;
typedef K::Point_3 Point_3;
int main()
{
{
Point_2 p1(0,0), p2(2,0), p3(1,3), q1(0,2), q2(2,2), q3(1,-1);
Triangle_2 t1(p1,p2,p3);
Triangle_2 t2(q1,q2,q3);
Segment_2 s1(p1,p3), s2(p2, q1);
CGAL::Object obj = CGAL::intersection(t1,t2);
const std::vector<Point_2> *V;
if( !(V = CGAL::object_cast<std::vector<Point_2> > (&obj)) ){
std::cerr << "ERROR" << std::endl;
return EXIT_FAILURE;
}
else{
std::cerr << "OK" << std::endl;
for(std::size_t i = 0; i < V->size(); i++){
std::cerr << (*V)[i] << std::endl;
std::cerr << CGAL::exact((*V)[i]) << std::endl;
}
}
obj = CGAL::intersection(s1,s2);
}
{
Point_3 p1(0,0,1), p2(2,0,1), p3(1,3,1), q1(0,2,1), q2(2,2,1), q3(1,-1,1);
Triangle_3 t1(p1,p2,p3);
Triangle_3 t2(q1,q2,q3);
CGAL::Object obj = CGAL::intersection(t1,t2);
const std::vector<Point_3> *V;
if( !(V = CGAL::object_cast<std::vector<Point_3> > (&obj)) ){
std::cerr << "ERROR" << std::endl;
return EXIT_FAILURE;
}
else{
std::cerr << "OK" << std::endl;
for(std::size_t i = 0; i < V->size(); i++){
std::cerr << (*V)[i] << std::endl;
std::cerr << CGAL::exact((*V)[i]) << std::endl;
}
}
}
}