Replace Object

This commit is contained in:
Efi Fogel 2012-02-12 22:53:41 +00:00
parent c9e721511d
commit 5651842b96
2 changed files with 185 additions and 220 deletions

View File

@ -9,8 +9,6 @@ print_point_location
(const typename Arrangement_::Point_2& q,
typename CGAL::Arr_point_location_result<Arrangement_>::Type obj)
{
CGAL_assertion(obj);
typedef Arrangement_ Arrangement_2;
typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle;
@ -22,13 +20,13 @@ print_point_location
const Face_const_handle* f;
std::cout << "The point (" << q << ") is located ";
if (f = boost::get<Face_const_handle>(&(*obj))) // located inside a face
if (f = boost::get<Face_const_handle>(&obj)) // located inside a face
std::cout << "inside "
<< (((*f)->is_unbounded()) ? "the unbounded" : "a bounded")
<< " face." << std::endl;
else if (e = boost::get<Halfedge_const_handle>(&(*obj))) // located on an edge
else if (e = boost::get<Halfedge_const_handle>(&obj)) // located on an edge
std::cout << "on an edge: " << (*e)->curve() << std::endl;
else if (v = boost::get<Vertex_const_handle>(&(*obj))) // located on a vertex
else if (v = boost::get<Vertex_const_handle>(&obj)) // located on a vertex
std::cout << "on " << (((*v)->is_isolated()) ? "an isolated" : "a")
<< " vertex: " << (*v)->point() << std::endl;
else CGAL_error_msg("Invalid object.");
@ -62,7 +60,6 @@ void shoot_vertical_ray(const RayShoot& vrs,
// Perform the point-location query.
typename Vertical_ray_shooting::result_type obj = vrs.ray_shoot_up(q);
CGAL_assertion(obj);
// Print the result.
typedef typename Vertical_ray_shooting::Arrangement_2 Arrangement_2;
@ -75,12 +72,12 @@ void shoot_vertical_ray(const RayShoot& vrs,
const Face_const_handle* f;
std::cout << "Shooting up from (" << q << ") : ";
if (v = boost::get<Vertex_const_handle>(&(*obj))) // we hit a vertex
if (v = boost::get<Vertex_const_handle>(&obj)) // we hit a vertex
std::cout << "hit " << (((*v)->is_isolated()) ? "an isolated" : "a")
<< " vertex: " << (*v)->point() << std::endl;
else if (e = boost::get<Halfedge_const_handle>(&(*obj))) // we hit an edge
else if (e = boost::get<Halfedge_const_handle>(&obj)) // we hit an edge
std::cout << "hit an edge: " << (*e)->curve() << std::endl;
else if (f = boost::get<Face_const_handle>(&(*obj))) { // we hit nothing
else if (f = boost::get<Face_const_handle>(&obj)) { // we hit nothing
CGAL_assertion((*f)->is_unbounded());
std::cout << "hit nothing." << std::endl;
}

View File

@ -45,37 +45,39 @@ typedef Arrangement_2::Edge_const_iterator Edge_const_iterator;
typedef Arrangement_2::Vertex_const_iterator Vertex_const_iterator;
typedef CGAL::Arr_naive_point_location<Arrangement_2>
Naive_point_location;
Naive_point_location;
typedef CGAL::Arr_simple_point_location<Arrangement_2>
Simple_point_location;
Simple_point_location;
typedef CGAL::Arr_walk_along_line_point_location<Arrangement_2>
Walk_point_location;
Walk_point_location;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2>
Lm_point_location;
Lm_point_location;
typedef CGAL::Arr_random_landmarks_generator<Arrangement_2>
Random_lm_generator;
Random_lm_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2, Random_lm_generator>
Lm_random_point_location;
Lm_random_point_location;
typedef CGAL::Arr_grid_landmarks_generator<Arrangement_2>
Grid_lm_generator;
Grid_lm_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2, Grid_lm_generator>
Lm_grid_point_location;
Lm_grid_point_location;
typedef CGAL::Arr_halton_landmarks_generator<Arrangement_2>
Halton_lm_generator;
Halton_lm_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2, Halton_lm_generator>
Lm_halton_point_location;
Lm_halton_point_location;
typedef CGAL::Arr_middle_edges_landmarks_generator<Arrangement_2>
Middle_edges_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2, Middle_edges_generator>
Lm_middle_edges_point_location;
Middle_edges_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2,
Middle_edges_generator>
Lm_middle_edges_point_location;
typedef CGAL::Arr_landmarks_specified_points_generator<Arrangement_2>
Specified_points_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2, Specified_points_generator>
Lm_specified_points_point_location;
Specified_points_generator;
typedef CGAL::Arr_landmarks_point_location<Arrangement_2,
Specified_points_generator>
Lm_specified_points_point_location;
//typedef CGAL::Arr_triangulation_point_location<Arrangement_2>
// Lm_triangulation_point_location;
// typedef CGAL::Arr_triangulation_point_location<Arrangement_2>
// Lm_triangulation_point_location;
// ===> Add new point location type here <===
@ -90,250 +92,234 @@ typedef Objects_vector::iterator Object_iterator;
#define NUM_OF_POINT_LOCATION_STRATEGIES 9
/*! */
int check_point_location (Arrangement_2 &arr, Points_list &plist)
template <typename InputIterator>
int check_point_location(Arrangement_2& arr,
InputIterator begin, InputIterator end)
{
typedef InputIterator Input_iterator;
//init - all point locations
CGAL::Timer timer;
CGAL::Timer timer;
Naive_point_location naive_pl (arr); // 0
Naive_point_location naive_pl(arr); // 0
Simple_point_location simple_pl (arr); // 1
Walk_point_location walk_pl (arr); // 2
Simple_point_location simple_pl(arr); // 1
Walk_point_location walk_pl(arr); // 2
timer.reset(); timer.start();
Lm_point_location lm_pl (arr); // 3
Lm_point_location lm_pl(arr); // 3
timer.stop();
std::cout << "Lm (vert) construction took " << timer.time() <<std::endl;
std::cout << "Lm (vert) construction took " << timer.time() << std::endl;
timer.reset(); timer.start();
Random_lm_generator random_g(arr);
Lm_random_point_location random_lm_pl (arr, &random_g); // 4
Random_lm_generator random_g(arr);
Lm_random_point_location random_lm_pl(arr, &random_g); // 4
timer.stop();
std::cout << "Random lm construction took " << timer.time() <<std::endl;
std::cout << "Random lm construction took " << timer.time() << std::endl;
timer.reset(); timer.start();
Grid_lm_generator grid_g(arr);
Lm_grid_point_location grid_lm_pl (arr, &grid_g); // 5
Grid_lm_generator grid_g(arr);
Lm_grid_point_location grid_lm_pl(arr, &grid_g); // 5
timer.stop();
std::cout << "Grid lm construction took " << timer.time() <<std::endl;
std::cout << "Grid lm construction took " << timer.time() << std::endl;
timer.reset(); timer.start();
Halton_lm_generator halton_g(arr);
Lm_halton_point_location halton_lm_pl (arr, &halton_g); // 6
Halton_lm_generator halton_g(arr);
Lm_halton_point_location halton_lm_pl(arr, &halton_g); // 6
timer.stop();
std::cout << "Halton lm construction took " << timer.time() <<std::endl;
std::cout << "Halton lm construction took " << timer.time() << std::endl;
timer.reset(); timer.start();
Middle_edges_generator middle_edges_g(arr);
Lm_middle_edges_point_location middle_edges_lm_pl (arr, &middle_edges_g); // 7
Middle_edges_generator middle_edges_g(arr);
Lm_middle_edges_point_location middle_edges_lm_pl(arr, &middle_edges_g); // 7
timer.stop();
std::cout << "Middle edges lm construction took " << timer.time() <<std::endl;
std::cout << "Middle edges lm construction took " << timer.time()
<< std::endl;
Specified_points_generator::Points_set points;
//points.push_back(Point_2(1,1));
//points.push_back(Point_2(2,2));
// points.push_back(Point_2(1,1));
// points.push_back(Point_2(2,2));
timer.reset(); timer.start();
//Specified_points_generator specified_points_g(arr,points);
Specified_points_generator specified_points_g(arr);
Lm_specified_points_point_location specified_points_lm_pl (arr, &specified_points_g); // 8
// Specified_points_generator specified_points_g(arr,points);
Specified_points_generator specified_points_g(arr);
Lm_specified_points_point_location
specified_points_lm_pl(arr, &specified_points_g); // 8
timer.stop();
std::cout << "Specified_points lm construction took " << timer.time() <<std::endl;
std::cout << "Specified_points lm construction took " << timer.time()
<< std::endl;
/*
timer.reset(); timer.start();
Lm_triangulation_point_location triangulation_lm_pl (arr); // 9
timer.stop();
std::cout << "Triangulation lm construction took " << timer.time() <<std::endl;
*/
// timer.reset(); timer.start();
// Lm_triangulation_point_location triangulation_lm_pl(arr); // 9
// timer.stop();
// std::cout << "Triangulation lm construction took " << timer.time()
// << std::endl;
std::cout << std::endl;
// ===> Add new point location instance here. <===
CGAL::Object obj;
Objects_vector objs[NUM_OF_POINT_LOCATION_STRATEGIES];
Object_iterator ob_iter[NUM_OF_POINT_LOCATION_STRATEGIES];
Arrangement_2::Vertex_const_handle vh_ref, vh_curr;
Arrangement_2::Halfedge_const_handle hh_ref, hh_curr;
Arrangement_2::Face_const_handle fh_ref, fh_curr;
Objects_vector objs[NUM_OF_POINT_LOCATION_STRATEGIES];
Object_iterator ob_iter[NUM_OF_POINT_LOCATION_STRATEGIES];
Arrangement_2::Halfedge_const_handle hh_curr;
Point_2 q;
Point_iterator piter;
Input_iterator piter;
//LOCATE the points in the list using all PL strategies
// LOCATE the points in the list using all PL strategies
//std::cout << "Time in seconds" <<std::endl; ;
// std::cout << "Time in seconds" << std::endl; ;
std::cout << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = naive_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = naive_pl.locate(q);
objs[0].push_back(obj);
}
timer.stop(); ///END
std::cout << "Naive location took " << timer.time() <<std::endl;
std::cout << "Naive location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = simple_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = simple_pl.locate(q);
objs[1].push_back(obj);
}
timer.stop(); ///END
std::cout << "Simple location took " << timer.time() <<std::endl;
std::cout << "Simple location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = walk_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = walk_pl.locate(q);
objs[2].push_back(obj);
}
timer.stop(); ///END
std::cout << "Walk location took " << timer.time() <<std::endl;
std::cout << "Walk location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++)
{
q = (*piter);
obj = lm_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = lm_pl.locate(q);
objs[3].push_back(obj);
}
timer.stop(); ///END
std::cout << "Landmarks (vertices) location took "
<< timer.time() <<std::endl;
<< timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = random_lm_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = random_lm_pl.locate(q);
objs[4].push_back(obj);
}
timer.stop(); ///END
std::cout << "Random LM location took " << timer.time() <<std::endl;
std::cout << "Random LM location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = grid_lm_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = grid_lm_pl.locate(q);
objs[5].push_back(obj);
}
timer.stop(); ///END
std::cout << "Grid LM location took " << timer.time() <<std::endl;
std::cout << "Grid LM location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = halton_lm_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = halton_lm_pl.locate(q);
objs[6].push_back(obj);
}
timer.stop(); ///END
std::cout << "Halton LM location took " << timer.time() <<std::endl;
std::cout << "Halton LM location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = middle_edges_lm_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = middle_edges_lm_pl.locate(q);
objs[7].push_back(obj);
}
timer.stop(); ///END
std::cout << "Middle edges LM location took " << timer.time() <<std::endl;
std::cout << "Middle edges LM location took " << timer.time() << std::endl;
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = specified_points_lm_pl.locate (q);
for (piter = begin; piter != end; ++piter) {
const Point_2& q = *piter;
CGAL::Object obj = specified_points_lm_pl.locate(q);
objs[8].push_back(obj);
}
timer.stop(); ///END
std::cout << "Specified points LM location took " << timer.time() <<std::endl;
/*
timer.reset();
timer.start(); //START
for (piter = plist.begin(); piter != plist.end(); piter++ )
{
q = (*piter);
obj = triangulation_lm_pl.locate (q);
objs[8].push_back(obj);
}
timer.stop(); ///END
std::cout << "Triangulation LM location took " << timer.time() <<std::endl;
*/
std::cout << "Specified points LM location took " << timer.time()
<< std::endl;
// timer.reset();
// timer.start(); //START
// for (piter = begin; piter != end; ++piter )
// {
// const Point_2& q = *piter;
// obj = triangulation_lm_pl.locate(q);
// objs[8].push_back(obj);
// }
// timer.stop(); ///END
// std::cout << "Triangulation LM location took " << timer.time()
// << std::endl;
std::cout << std::endl;
// ===> Add a call to operate the the new point location. <===
//END LOCATION
// END LOCATION
int pls_num = NUM_OF_POINT_LOCATION_STRATEGIES;
int pl_index;
int result = 0;
//init all obejct iterators
for (pl_index=0; pl_index<pls_num; pl_index++)
{
for (pl_index = 0; pl_index < pls_num; ++pl_index)
ob_iter[pl_index] = objs[pl_index].begin();
}
//get size of objects
unsigned int size = objs[0].size();
//std::cout <<"size is "<< size << std::endl;
for (pl_index=0; pl_index<pls_num; pl_index++)
{
if (size != objs[pl_index].size())
{
std::cout << "Error: size of pl number "<<pl_index<<" is "
<<objs[pl_index].size()<< std::endl;
for (pl_index = 0; pl_index < pls_num; ++pl_index) {
if (size != objs[pl_index].size()) {
std::cout << "Error: size of pl number " << pl_index << " is "
<< objs[pl_index].size() << std::endl;
result = -1;
}
}
//assign and check results
unsigned int qi; //qi is the query point index
for (qi=0; qi<size; qi++)
{
//assign object to a face
if (CGAL::assign (fh_ref, ob_iter[0][qi]))
{
for (int pl_index=1; pl_index<pls_num; pl_index++)
{
if (! CGAL::assign(fh_curr, ob_iter[pl_index][qi]))
{
for (qi = 0; qi < size; ++qi) {
// Assign object to a face
Arrangement_2::Vertex_const_handle vh_ref;
Arrangement_2::Halfedge_const_handle hh_ref;
Arrangement_2::Face_const_handle fh_ref;
if (CGAL::assign(fh_ref, ob_iter[0][qi])) {
for (int pl_index = 1; pl_index < pls_num; ++pl_index) {
Arrangement_2::Face_const_handle fh_curr;
if (! CGAL::assign(fh_curr, ob_iter[pl_index][qi])) {
std::cout << "Error in point location number " << pl_index;
if (CGAL::assign(fh_curr, ob_iter[pl_index][qi]))
{
std::cout << ", an halfedge returned instead of a face"<< std::endl;
}
std::cout << ", an halfedge returned instead of a face"
<< std::endl;
else if (CGAL::assign(hh_curr, ob_iter[pl_index][qi]))
{
std::cout << ", a vertex returned instead of a face"<< std::endl;
}
std::cout << ", a vertex returned instead of a face" << std::endl;
else
{
std::cout << ", an unknowen object returned instead of a face"<< std::endl;
}
std::cout << ", an unknowen object returned instead of a face"
<< std::endl;
result = -1;
}
else if (fh_curr != fh_ref)
{
else if (fh_curr != fh_ref) {
std::cout << "Error: point location number "
<< pl_index << " return a different face"<< std::endl;
<< pl_index << " return a different face" << std::endl;
result = -1;
}
}
@ -343,63 +329,51 @@ int check_point_location (Arrangement_2 &arr, Points_list &plist)
// std::cout << "Face." << std::endl;
}
//assign object to a halfedge
else if (CGAL::assign (hh_ref, ob_iter[0][qi]))
{
std::cout << "Halfedge: "<< hh_ref->curve() << std::endl;
for (int pl_index=1; pl_index<pls_num; pl_index++)
{
if (! CGAL::assign(hh_curr, ob_iter[pl_index][qi]))
{
// Assign object to a halfedge
else if (CGAL::assign(hh_ref, ob_iter[0][qi])) {
std::cout << "Halfedge: " << hh_ref->curve() << std::endl;
for (int pl_index = 1; pl_index < pls_num; ++pl_index) {
if (! CGAL::assign(hh_curr, ob_iter[pl_index][qi])) {
std::cout << "Error in point location number " << pl_index;
Arrangement_2::Face_const_handle fh_curr;
if (CGAL::assign(fh_curr, ob_iter[pl_index][qi]))
{
std::cout << ", a face returned instead of an halfedge"<< std::endl;
}
std::cout << ", a face returned instead of an halfedge"
<< std::endl;
else if (CGAL::assign(hh_curr, ob_iter[pl_index][qi]))
{
std::cout << ", a vertex returned instead of an halfedge"<< std::endl;
}
std::cout << ", a vertex returned instead of an halfedge"
<< std::endl;
else
{
std::cout << ", an unknowen object returned instead of an halfedge"<< std::endl;
}
std::cout << ", an unknowen object returned instead of an halfedge"
<< std::endl;
result = -1;
}
else if ((hh_curr != hh_ref) && (hh_curr->twin() != hh_ref))
{
else if ((hh_curr != hh_ref) && (hh_curr->twin() != hh_ref)) {
std::cout << "Error: point location number "
<< pl_index << " return a different halfedge"<< std::endl;
<< pl_index << " return a different halfedge" << std::endl;
std::cout << "Halfedge (curr): "<< hh_curr->curve() << std::endl;
result = -1;
}
}
}
//assign object to a vertex
else if (CGAL::assign (vh_ref, ob_iter[0][qi]))
{
for (int pl_index=1; pl_index<pls_num; pl_index++)
{
if (! CGAL::assign(vh_curr, ob_iter[pl_index][qi]))
{
// Assign object to a vertex
else if (CGAL::assign(vh_ref, ob_iter[0][qi])) {
for (int pl_index = 1; pl_index < pls_num; ++pl_index) {
Arrangement_2::Vertex_const_handle vh_curr;
if (! CGAL::assign(vh_curr, ob_iter[pl_index][qi])) {
std::cout << "Error in point location number " << pl_index;
Arrangement_2::Face_const_handle fh_curr;
if (CGAL::assign(fh_curr, ob_iter[pl_index][qi]))
{
std::cout << ", a face returned instead of a vertex"<< std::endl;
}
else if (CGAL::assign(hh_curr, ob_iter[pl_index][qi]))
{
std::cout << ", an halfedge returned instead of a vertex"<< std::endl;
}
std::cout << ", an halfedge returned instead of a vertex"
<< std::endl;
else
{
std::cout << ", an unknown object returned instead of a vertex"<< std::endl;
}
std::cout << ", an unknown object returned instead of a vertex"
<< std::endl;
result = -1;
}
else if (vh_curr != vh_ref)
{
else if (vh_curr != vh_ref) {
std::cout << "Error: point location number "
<< pl_index << " return a different vertex"<< std::endl;
result = -1;
@ -407,9 +381,7 @@ int check_point_location (Arrangement_2 &arr, Points_list &plist)
}
std::cout << "Vertex: "<< vh_ref->point() << std::endl;
}
else
{
else {
std::cout << "Illegal point-location result." << std::endl;
result = -1;
}
@ -418,12 +390,11 @@ int check_point_location (Arrangement_2 &arr, Points_list &plist)
}
/*! */
int read_points(const char * points_filename, Points_list &plist)
int read_points(const char* points_filename, Points_list& plist)
{
//read points from file into list
std::ifstream inp_pnt_file(points_filename);
if (!inp_pnt_file.is_open())
{
if (!inp_pnt_file.is_open()) {
std::cerr << "Cannot open file " << points_filename << "!" << std::endl;
return (-1);
}
@ -455,36 +426,34 @@ bool test(const char* curves_filename, const char* points_filename)
timer.reset();
timer.start(); //START
Arrangement_2 arr;
insert (arr, curve_list.begin(), curve_list.end());
insert(arr, curve_list.begin(), curve_list.end());
timer.stop(); ///END
std::cout << "Arrangement aggregate construction took "
<< timer.time() <<std::endl;
<< timer.time() << std::endl;
// Print the size of the arrangement.
std::cout << "V = " << arr.number_of_vertices()
<< ", E = " << arr.number_of_edges()
<< ", F = " << arr.number_of_faces() << std::endl;
//read point and insert them into a list of points
Points_list plist;
Points_list plist;
//read points from file into list
if (read_points(points_filename, plist))
{
std::cout << "ERROR in read_points."<<std::endl<<std::endl;
return (false);
if (read_points(points_filename, plist)) {
std::cout << "ERROR in read_points." << std::endl<< std::endl;
return false;
}
//check point location of points
if (check_point_location(arr, plist))
{
std::cout << "ERROR in check_point_location."<<std::endl<<std::endl;
return (false);
if (check_point_location(arr, plist.begin(), plist.end())) {
std::cout << "ERROR in check_point_location." << std::endl<< std::endl;
return false;
}
std::cout << std::endl;
return (true);
return true;
}
int main (int argc, char * argv[])
int main(int argc, char* argv[])
{
//get arguments
if (argc < 3) {
@ -494,17 +463,16 @@ int main (int argc, char * argv[])
std::exit(-1);
}
int success = 0;
for(int i=1; i<argc; i+=2)
{
const char * curves_filename = argv[i];
const char * points_filename = argv[i+1];
for (int i = 1; i < argc; i+=2) {
const char* curves_filename = argv[i];
const char* points_filename = argv[i+1];
if(!test(curves_filename, points_filename))
{
std::cout<<"ERROR : "<<argv[0]<<" "<<argv[i]<<" "<<argv[i+1]<<std::endl;
if (!test(curves_filename, points_filename)) {
std::cout << "ERROR : " << argv[0] << " " << argv[i] << " "
<< argv[i+1] << std::endl;
success = -1;
}
}
return (success);
return success;
}