consistency of Naive

This commit is contained in:
kanhuang 2013-08-08 00:28:54 -04:00
parent fd46d789eb
commit 2fbd64a8e5
4 changed files with 30 additions and 23 deletions

View File

@ -30,7 +30,6 @@
#include <CGAL/Ray_2.h> #include <CGAL/Ray_2.h>
#include <CGAL/tags.h> #include <CGAL/tags.h>
#include <CGAL/enum.h> #include <CGAL/enum.h>
#include <CGAL/bounding_box.h>
namespace CGAL { namespace CGAL {
@ -45,6 +44,7 @@ void print(std::vector<Point_handle> ps){
template <typename Arrangement_2, typename RegularizationTag> template <typename Arrangement_2, typename RegularizationTag>
class Naive_visibility_2 { class Naive_visibility_2 {
public:
typedef Arrangement_2 Input_arrangement_2; typedef Arrangement_2 Input_arrangement_2;
typedef Arrangement_2 Output_arrangement_2; typedef Arrangement_2 Output_arrangement_2;
typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2; typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2;
@ -71,16 +71,14 @@ class Naive_visibility_2 {
enum Intersection_type { UNBOUNDED, CORNER, INNER }; enum Intersection_type { UNBOUNDED, CORNER, INNER };
public:
//members
Arrangement_2 arr;
//functions //functions
Naive_visibility_2(const Arrangement_2 &arr):arr(arr), attach_tag(true) {} Naive_visibility_2(const Input_arrangement_2 &arr):arr_env(arr), attach_tag(true) {}
Naive_visibility_2(): attach_tag(false) {} Naive_visibility_2(): attach_tag(false) {}
Face_const_handle visibility_region(const Point_2 &q, Halfedge_const_handle &e, Arrangement_2 &out_arr) { Face_const_handle visibility_region(const Point_2 &q, Halfedge_const_handle e, Output_arrangement_2 &out_arr) {
Arrangement_2 arrc = arr ; //copy of arr; Arrangement_2 arrc = arr_env ; //copy of arr;
Halfedge_handle ec; //copy of edge; Halfedge_handle ec; //copy of edge;
for (Halfedge_handle eh = arrc.edges_begin(); eh != arrc.edges_end(); eh++) { for (Halfedge_handle eh = arrc.edges_begin(); eh != arrc.edges_end(); eh++) {
if (eh->source()->point() == e-> source()->point() && eh->target()->point() == e->target()->point()) { if (eh->source()->point() == e-> source()->point() && eh->target()->point() == e->target()->point()) {
@ -232,7 +230,7 @@ public:
} }
Face_const_handle visibility_region(const Point_2 &q, Face_const_handle fh, Arrangement_2 &out_arr) { Face_const_handle visibility_region(const Point_2 &q, Face_const_handle fh, Output_arrangement_2 &out_arr) {
std::vector<Point_2> polygon; std::vector<Point_2> polygon;
visibility_region_impl(q, fh, polygon); visibility_region_impl(q, fh, polygon);
build_arr(polygon, out_arr); build_arr(polygon, out_arr);
@ -247,18 +245,25 @@ public:
return attach_tag; return attach_tag;
} }
void attach(Arrangement_2 arr) { void attach(const Input_arrangement_2 &arr) {
this->arr = arr; arr_env = arr;
this->attach_tag = true; attach_tag = true;
} }
void detach() { void detach() {
attach_tag = false; attach_tag = false;
} }
const Input_arrangement_2& arr() {
return arr_env;
}
private: private:
//members
Input_arrangement_2 arr_env;
bool attach_tag; bool attach_tag;
// return the intersection of a ray and a segment. if the intersection is a segment, return the end closer to the source of ray. //-----------------------------
//functions
// if there is no intersection, return the source of ray. // if there is no intersection, return the source of ray.
/*! /*!
obtain the vertices of visibility into polygon. these vertices can be used to build output arrangement by build_arr(). obtain the vertices of visibility into polygon. these vertices can be used to build output arrangement by build_arr().

View File

@ -83,7 +83,7 @@ public:
vertices.clear(); vertices.clear();
} }
Input_arrangement_2 arr() { const Input_arrangement_2& arr() {
return *p_arr; return *p_arr;
} }

View File

@ -27,8 +27,7 @@
#include <CGAL/Arrangement_2.h> #include <CGAL/Arrangement_2.h>
#include <CGAL/test_model_methods.h> #include <CGAL/test_model_methods.h>
#include <CGAL/test_utils.h> #include <CGAL/test_utils.h>
#include <CGAL/test_simple_polygons.h> #include <CGAL/Naive_visibility_2.h>
#include <CGAL/Simple_polygon_visibility_2.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -41,11 +40,12 @@ int main() {
typedef Traits_2::Point_2 Point_2; typedef Traits_2::Point_2 Point_2;
typedef Traits_2::X_monotone_curve_2 Segment_2; typedef Traits_2::X_monotone_curve_2 Segment_2;
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2; typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
typedef CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_false> typedef CGAL::Naive_visibility_2<Arrangement_2, CGAL::Tag_false>
Simple_polygon_visibility_2; Naive_visibility_2;
CGAL::test_model_methods<Simple_polygon_visibility_2>(); CGAL::test_model_methods<Naive_visibility_2>();
CGAL::run_tests<Simple_polygon_visibility_2>(1); std::cout << "Running test suite with " << GREEN << "Cartesian" << RESET << " Kernel..." << std::endl;
CGAL::run_tests<Naive_visibility_2>(1);
} }
{ {
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
@ -53,10 +53,12 @@ int main() {
typedef Traits_2::Point_2 Point_2; typedef Traits_2::Point_2 Point_2;
typedef Traits_2::X_monotone_curve_2 Segment_2; typedef Traits_2::X_monotone_curve_2 Segment_2;
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2; typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
typedef CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_false> typedef CGAL::Naive_visibility_2<Arrangement_2, CGAL::Tag_false>
Simple_polygon_visibility_2; Naive_visibility_2;
CGAL::test_model_methods<Simple_polygon_visibility_2>(); CGAL::test_model_methods<Naive_visibility_2>();
std::cout << "Running test suite with " << GREEN << "EPECK" << RESET << " Kernel..." << std::endl;
CGAL::run_tests<Naive_visibility_2>(1);
} }
return 0; return 0;
} }