Pretty-print headers using astyle with the following configuration:

--add-brackets
--align-pointer=name
--break-blocks
--convert-tabs
--pad-header
--pad-oper
--style=attach
--unpad-paren
This commit is contained in:
Sebastian Morr 2014-06-02 17:08:06 +02:00
parent cfc89c5744
commit 26fa63eff1
13 changed files with 5831 additions and 5916 deletions

View File

@ -7,57 +7,55 @@
#include "AABB_tree_mod.h" #include "AABB_tree_mod.h"
#include "AABB_2d_traits.h" #include "AABB_2d_traits.h"
#include "AABB_segment_2_primitive.h" #include "AABB_segment_2_primitive.h"
namespace CGAL{ namespace CGAL {
template <class Kernel_, class Container_> class AABBCollisionDetector : public ICollisionDetector< Kernel_, Container_> template <class Kernel_, class Container_> class AABBCollisionDetector : public ICollisionDetector< Kernel_, Container_> {
{
public: public:
typedef typename Kernel_::Point_2 Point; typedef typename Kernel_::Point_2 Point;
typedef typename CGAL::Polygon_2<Kernel_> Polygon_2; typedef typename CGAL::Polygon_2<Kernel_> Polygon_2;
//typedef typename Polygon_2::Edge_const_iterator Edge_iterator ; //typedef typename Polygon_2::Edge_const_iterator Edge_iterator ;
typedef typename Polygon_2::Traits::Segment_2 Segment_2 ; typedef typename Polygon_2::Traits::Segment_2 Segment_2 ;
typedef typename Polygon_2::Edge_const_iterator Edge_iterator; typedef typename Polygon_2::Edge_const_iterator Edge_iterator;
typedef typename Polygon_2::Edge_const_circulator Edge_circulator; typedef typename Polygon_2::Edge_const_circulator Edge_circulator;
typedef AABB_segment_2_primitive<Kernel_,Edge_iterator,Polygon_2> Tree_Segment_2; typedef AABB_segment_2_primitive<Kernel_, Edge_iterator, Polygon_2> Tree_Segment_2;
typedef AABB_traits_2<Kernel_,Tree_Segment_2> Tree_Traits; typedef AABB_traits_2<Kernel_, Tree_Segment_2> Tree_Traits;
typedef AABB_tree<Tree_Traits> AABB_Tree; typedef AABB_tree<Tree_Traits> AABB_Tree;
typedef CGAL::Arr_segment_traits_2<Kernel_> Traits_2; typedef CGAL::Arr_segment_traits_2<Kernel_> Traits_2;
protected: protected:
Traits_2 m_traits; Traits_2 m_traits;
public: public:
AABBCollisionDetector( Polygon_2&p, Polygon_2& q)//:m_stationary_tree((q.edges_begin()),(q.edges_end())),m_translating_tree((p.edges_begin()),(p.edges_end())),m_p(p),m_q(q) AABBCollisionDetector(Polygon_2 &p, Polygon_2 &q)//:m_stationary_tree((q.edges_begin()),(q.edges_end())),m_translating_tree((p.edges_begin()),(p.edges_end())),m_p(p),m_q(q)
:m_stationary_tree((p.edges_begin()),(p.edges_end())),m_translating_tree((q.edges_begin()),(q.edges_end())),m_p(q),m_q(p) : m_stationary_tree((p.edges_begin()), (p.edges_end())), m_translating_tree((q.edges_begin()), (q.edges_end())), m_p(q), m_q(p) {
{
} }
//typedef typename Polygon_2::Vertex_circulator Vertex_circulator; //typedef typename Polygon_2::Vertex_circulator Vertex_circulator;
//typedef typename //typedef typename
virtual bool checkCollision(const Polygon_2& p,const Polygon_2& q) virtual bool checkCollision(const Polygon_2 &p, const Polygon_2 &q) {
{ //Traits_2::Compare_endpoints_xy_2 cmp_obj = m_traits.compare_endpoints_xy_2_object();
//Traits_2::Compare_endpoints_xy_2 cmp_obj = m_traits.compare_endpoints_xy_2_object();
if (m_stationary_tree.do_intersect_join(m_translating_tree,m_translation_point,m_p,m_q)) if (m_stationary_tree.do_intersect_join(m_translating_tree, m_translation_point, m_p, m_q)) {
return true; return true;
}
return (p.has_on_bounded_side(*(q.vertices_begin())) || q.has_on_bounded_side(*(p.vertices_begin()))); return (p.has_on_bounded_side(*(q.vertices_begin())) || q.has_on_bounded_side(*(p.vertices_begin())));
//return true; //return true;
} }
void setTranslationPoint(const Point& t){ void setTranslationPoint(const Point &t) {
m_translation_point = t; m_translation_point = t;
} }
private: private:
AABB_Tree m_stationary_tree; AABB_Tree m_stationary_tree;
AABB_Tree m_translating_tree; AABB_Tree m_translating_tree;
Point m_translation_point; Point m_translation_point;
Polygon_2& m_p; Polygon_2 &m_p;
Polygon_2& m_q; Polygon_2 &m_q;
}; };
} }

View File

@ -34,91 +34,104 @@ namespace CGAL {
* *
*/ */
template<typename AABBTraits> template<typename AABBTraits>
class AABB_node class AABB_node {
{
public: public:
typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Bounding_box Bounding_box;
/// Constructor /// Constructor
AABB_node() AABB_node()
: m_bbox() : m_bbox()
, m_p_left_child(NULL) , m_p_left_child(NULL)
, m_p_right_child(NULL) { }; , m_p_right_child(NULL) { };
/// Non virtual Destructor /// Non virtual Destructor
/// Do not delete children because the tree hosts and delete them /// Do not delete children because the tree hosts and delete them
~AABB_node() { }; ~AABB_node() { };
/// Returns the bounding box of the node /// Returns the bounding box of the node
Bounding_box bbox() const { return m_bbox; } Bounding_box bbox() const {
return m_bbox;
}
/** /**
* @brief Builds the tree by recursive expansion. * @brief Builds the tree by recursive expansion.
* @param first the first primitive to insert * @param first the first primitive to insert
* @param last the last primitive to insert * @param last the last primitive to insert
* @param range the number of primitive of the range * @param range the number of primitive of the range
* *
* [first,last[ is the range of primitives to be added to the tree. * [first,last[ is the range of primitives to be added to the tree.
*/ */
template<typename ConstPrimitiveIterator> template<typename ConstPrimitiveIterator>
void expand(ConstPrimitiveIterator first, void expand(ConstPrimitiveIterator first,
ConstPrimitiveIterator beyond, ConstPrimitiveIterator beyond,
const std::size_t range); const std::size_t range);
/** /**
* @brief General traversal query * @brief General traversal query
* @param query the query * @param query the query
* @param traits the traversal traits that define the traversal behaviour * @param traits the traversal traits that define the traversal behaviour
* @param nb_primitives the number of primitive * @param nb_primitives the number of primitive
* *
* General traversal query. The traits class allows using it for the various * General traversal query. The traits class allows using it for the various
* traversal methods we need: listing, counting, detecting intersections, * traversal methods we need: listing, counting, detecting intersections,
* drawing the boxes. * drawing the boxes.
*/ */
template<class Traversal_traits, class Query> template<class Traversal_traits, class Query>
void traversal(const Query& query, void traversal(const Query &query,
Traversal_traits& traits, Traversal_traits &traits,
const std::size_t nb_primitives) const; const std::size_t nb_primitives) const;
template<class Traversal_traits> template<class Traversal_traits>
void join_traversal(const AABB_node& other_node, void join_traversal(const AABB_node &other_node,
Traversal_traits& traits, Traversal_traits &traits,
const std::size_t nb_primitives_this,const std::size_t nb_primitives_other, bool first_stationary) const; const std::size_t nb_primitives_this, const std::size_t nb_primitives_other, bool first_stationary) const;
private: private:
typedef AABBTraits AABB_traits; typedef AABBTraits AABB_traits;
typedef AABB_node<AABB_traits> Node; typedef AABB_node<AABB_traits> Node;
typedef typename AABB_traits::Primitive Primitive; typedef typename AABB_traits::Primitive Primitive;
/// Helper functions /// Helper functions
const Node& left_child() const const Node &left_child() const {
{ return *static_cast<Node*>(m_p_left_child); } return *static_cast<Node *>(m_p_left_child);
const Node& right_child() const }
{ return *static_cast<Node*>(m_p_right_child); } const Node &right_child() const {
const Primitive& left_data() const return *static_cast<Node *>(m_p_right_child);
{ return *static_cast<Primitive*>(m_p_left_child); } }
const Primitive& right_data() const const Primitive &left_data() const {
{ return *static_cast<Primitive*>(m_p_right_child); } return *static_cast<Primitive *>(m_p_left_child);
}
const Primitive &right_data() const {
return *static_cast<Primitive *>(m_p_right_child);
}
Node& left_child() { return *static_cast<Node*>(m_p_left_child); } Node &left_child() {
Node& right_child() { return *static_cast<Node*>(m_p_right_child); } return *static_cast<Node *>(m_p_left_child);
Primitive& left_data() { return *static_cast<Primitive*>(m_p_left_child); } }
Primitive& right_data() { return *static_cast<Primitive*>(m_p_right_child); } Node &right_child() {
return *static_cast<Node *>(m_p_right_child);
}
Primitive &left_data() {
return *static_cast<Primitive *>(m_p_left_child);
}
Primitive &right_data() {
return *static_cast<Primitive *>(m_p_right_child);
}
private: private:
/// node bounding box /// node bounding box
Bounding_box m_bbox; Bounding_box m_bbox;
/// children nodes, either pointing towards children (if children are not leaves), /// children nodes, either pointing towards children (if children are not leaves),
/// or pointing toward input primitives (if children are leaves). /// or pointing toward input primitives (if children are leaves).
void *m_p_left_child; void *m_p_left_child;
void *m_p_right_child; void *m_p_right_child;
private: private:
// Disabled copy constructor & assignment operator // Disabled copy constructor & assignment operator
typedef AABB_node<AABBTraits> Self; typedef AABB_node<AABBTraits> Self;
AABB_node(const Self& src); AABB_node(const Self &src);
Self& operator=(const Self& src); Self &operator=(const Self &src);
}; // end class AABB_node }; // end class AABB_node
@ -128,197 +141,188 @@ template<typename ConstPrimitiveIterator>
void void
AABB_node<Tr>::expand(ConstPrimitiveIterator first, AABB_node<Tr>::expand(ConstPrimitiveIterator first,
ConstPrimitiveIterator beyond, ConstPrimitiveIterator beyond,
const std::size_t range) const std::size_t range) {
{ m_bbox = AABB_traits().compute_bbox_object()(first, beyond);
m_bbox = AABB_traits().compute_bbox_object()(first, beyond);
// sort primitives along longest axis aabb // sort primitives along longest axis aabb
AABB_traits().sort_primitives_object()(first, beyond, m_bbox); AABB_traits().sort_primitives_object()(first, beyond, m_bbox);
switch(range) switch (range) {
{ case 2:
case 2: m_p_left_child = &(*first);
m_p_left_child = &(*first); m_p_right_child = &(*(++first));
m_p_right_child = &(*(++first)); break;
break;
case 3: case 3:
m_p_left_child = &(*first); m_p_left_child = &(*first);
m_p_right_child = static_cast<Node*>(this)+1; m_p_right_child = static_cast<Node *>(this) + 1;
right_child().expand(first+1, beyond, 2); right_child().expand(first + 1, beyond, 2);
break; break;
default:
const std::size_t new_range = range/2; default:
m_p_left_child = static_cast<Node*>(this) + 1; const std::size_t new_range = range / 2;
m_p_right_child = static_cast<Node*>(this) + new_range; m_p_left_child = static_cast<Node *>(this) + 1;
left_child().expand(first, first + new_range, new_range); m_p_right_child = static_cast<Node *>(this) + new_range;
right_child().expand(first + new_range, beyond, range - new_range); left_child().expand(first, first + new_range, new_range);
} right_child().expand(first + new_range, beyond, range - new_range);
}
} }
template<typename Tr> template<typename Tr>
template<class Traversal_traits, class Query> template<class Traversal_traits, class Query>
void void
AABB_node<Tr>::traversal(const Query& query, AABB_node<Tr>::traversal(const Query &query,
Traversal_traits& traits, Traversal_traits &traits,
const std::size_t nb_primitives) const const std::size_t nb_primitives) const {
{ // Recursive traversal
// Recursive traversal switch (nb_primitives) {
switch(nb_primitives) case 2:
{ traits.intersection(query, left_data());
case 2:
traits.intersection(query, left_data()); if (traits.go_further()) {
if( traits.go_further() ) traits.intersection(query, right_data());
{ }
traits.intersection(query, right_data());
break;
case 3:
traits.intersection(query, left_data());
if (traits.go_further() && traits.do_intersect(query, right_child())) {
right_child().traversal(query, traits, 2);
}
break;
default:
if (traits.do_intersect(query, left_child())) {
left_child().traversal(query, traits, nb_primitives / 2);
if (traits.go_further() && traits.do_intersect(query, right_child())) {
right_child().traversal(query, traits, nb_primitives - nb_primitives / 2);
}
} else if (traits.do_intersect(query, right_child())) {
right_child().traversal(query, traits, nb_primitives - nb_primitives / 2);
}
} }
break;
case 3:
traits.intersection(query, left_data());
if( traits.go_further() && traits.do_intersect(query, right_child()) )
{
right_child().traversal(query, traits, 2);
}
break;
default:
if( traits.do_intersect(query, left_child()) )
{
left_child().traversal(query, traits, nb_primitives/2);
if( traits.go_further() && traits.do_intersect(query, right_child()) )
{
right_child().traversal(query, traits, nb_primitives-nb_primitives/2);
}
}
else if( traits.do_intersect(query, right_child()) )
{
right_child().traversal(query, traits, nb_primitives-nb_primitives/2);
}
}
} }
template<typename Tr> template<typename Tr>
template<class Traversal_traits> template<class Traversal_traits>
void void
AABB_node<Tr>::join_traversal(const AABB_node& other_node, AABB_node<Tr>::join_traversal(const AABB_node &other_node,
Traversal_traits& traits, Traversal_traits &traits,
const std::size_t nb_primitives_this,const std::size_t nb_primitives_other, bool first_stationary) const const std::size_t nb_primitives_this, const std::size_t nb_primitives_other, bool first_stationary) const {
{ // Recursive traversal
// Recursive traversal bool first_tree_small = nb_primitives_this <= 3;
bool first_tree_small = nb_primitives_this <= 3; bool second_tree_small = nb_primitives_other <= 3;
bool second_tree_small = nb_primitives_other <= 3; bool first_tree_even = nb_primitives_this == 2;
bool first_tree_even = nb_primitives_this == 2; bool second_tree_even = nb_primitives_other == 2;
bool second_tree_even = nb_primitives_other == 2;
if (first_tree_small && second_tree_small) if (first_tree_small && second_tree_small) {
{ traits.intersection(left_data(), other_node.left_data(), !first_stationary);
traits.intersection(left_data(),other_node.left_data(),!first_stationary);
if (traits.go_further() )
{ // 4 cases
if (first_tree_even){
if (second_tree_even){ // 2 and 2
traits.intersection( right_data(),other_node.right_data(),!first_stationary);
if (traits.go_further())
traits.intersection(right_data(),other_node.left_data(),!first_stationary);
if (traits.go_further())
traits.intersection( left_data(),other_node.right_data(),!first_stationary);
}
else{ // 2 and 3
if (traits.do_intersect(right_data(),other_node.right_child(),!first_stationary) || traits.do_intersect(left_data(),other_node.right_child(),!first_stationary) ){
other_node.right_child().join_traversal(*this,traits,2,2,!first_stationary);
}
/*if (traits.go_further() && traits.do_intersect(other_node.right_child(), left_data(),!first_stationary))
{
other_node.right_child().join_traversal(left_data(),traits,2,1,!first_stationary);
}*/
}
}
else {
if (second_tree_even){ // 3 and 2 if (traits.go_further()) {
if (traits.do_intersect(right_child(), other_node.right_data(),!first_stationary) || traits.do_intersect(right_child(), other_node.left_data(),!first_stationary)){ // 4 cases
right_child().join_traversal(other_node,traits,2,2,first_stationary); if (first_tree_even) {
} if (second_tree_even) { // 2 and 2
/*if (traits.go_further() && traits.do_intersect(right_child(), other_node.left_data(),first_stationary)) traits.intersection(right_data(), other_node.right_data(), !first_stationary);
{
right_child().join_traversal(other_node.left_data(),traits,2,1,first_stationary);
}*/
}else{ //3 and 3
if (traits.do_intersect(right_child(), other_node.right_child(),!first_stationary)){
right_child().join_traversal(other_node.right_child(),traits,2,2,first_stationary);
}
if (traits.go_further() && traits.do_intersect(right_child(), other_node.left_data(),!first_stationary))
{
right_child().join_traversal(other_node,traits,2,3,first_stationary);
}
if (traits.go_further() && traits.do_intersect(left_data(),other_node.right_child(),!first_stationary))
{
other_node.right_child().join_traversal(*this,traits,2,3,!first_stationary);
}
}
} if (traits.go_further()) {
traits.intersection(right_data(), other_node.left_data(), !first_stationary);
}
} if (traits.go_further()) {
} traits.intersection(left_data(), other_node.right_data(), !first_stationary);
}
} else { // 2 and 3
if (traits.do_intersect(right_data(), other_node.right_child(), !first_stationary) || traits.do_intersect(left_data(), other_node.right_child(), !first_stationary)) {
other_node.right_child().join_traversal(*this, traits, 2, 2, !first_stationary);
}
// first tree is 3 or smaller and second tree is larger /*if (traits.go_further() && traits.do_intersect(other_node.right_child(), left_data(),!first_stationary))
if (first_tree_small && !second_tree_small) {
{ other_node.right_child().join_traversal(left_data(),traits,2,1,!first_stationary);
if (traits.do_intersect(*this,other_node.left_child(),!first_stationary)) }*/
{ }
other_node.left_child().join_traversal(*this, traits, nb_primitives_other/2,nb_primitives_this,!first_stationary); } else {
if( traits.go_further() && traits.do_intersect(*this, other_node.right_child(),!first_stationary) ){
other_node.right_child().join_traversal(*this, traits, nb_primitives_other-nb_primitives_other/2,nb_primitives_this,!first_stationary);
}
}
else if (traits.do_intersect(*this,other_node.right_child(),!first_stationary))
{
other_node.right_child().join_traversal(*this, traits, nb_primitives_other-nb_primitives_other/2,nb_primitives_this,!first_stationary);
}
}
// symetrical to previous case. if (second_tree_even) { // 3 and 2
if (!first_tree_small && second_tree_small) if (traits.do_intersect(right_child(), other_node.right_data(), !first_stationary) || traits.do_intersect(right_child(), other_node.left_data(), !first_stationary)) {
{ right_child().join_traversal(other_node, traits, 2, 2, first_stationary);
if (traits.do_intersect(left_child(),other_node,!first_stationary)) }
{
left_child().join_traversal(other_node, traits, nb_primitives_this/2,nb_primitives_other,first_stationary);
if( traits.go_further() && traits.do_intersect( right_child(),other_node,!first_stationary) ){
right_child().join_traversal(other_node, traits, nb_primitives_this-nb_primitives_this/2,nb_primitives_other,first_stationary);
}
}
else if (traits.do_intersect(right_child(),other_node,!first_stationary))
{
right_child().join_traversal(other_node, traits, nb_primitives_this-nb_primitives_this/2,nb_primitives_other,first_stationary);
}
}
// both trees as larger then 3 /*if (traits.go_further() && traits.do_intersect(right_child(), other_node.left_data(),first_stationary))
if (!first_tree_small && !second_tree_small) {
{ right_child().join_traversal(other_node.left_data(),traits,2,1,first_stationary);
if (traits.do_intersect(left_child(),other_node.left_child(),!first_stationary)) }*/
{ } else { //3 and 3
left_child().join_traversal(other_node.left_child(), traits, nb_primitives_this/2,nb_primitives_other/2,first_stationary); if (traits.do_intersect(right_child(), other_node.right_child(), !first_stationary)) {
} right_child().join_traversal(other_node.right_child(), traits, 2, 2, first_stationary);
}
if (traits.go_further() && traits.do_intersect(left_child(), other_node.right_child(),!first_stationary)) if (traits.go_further() && traits.do_intersect(right_child(), other_node.left_data(), !first_stationary)) {
{ right_child().join_traversal(other_node, traits, 2, 3, first_stationary);
left_child().join_traversal(other_node.right_child(), traits, nb_primitives_this/2,nb_primitives_other - nb_primitives_other/2,first_stationary); }
}
if (traits.go_further() && traits.do_intersect(right_child(), other_node.left_child(),!first_stationary)) if (traits.go_further() && traits.do_intersect(left_data(), other_node.right_child(), !first_stationary)) {
{ other_node.right_child().join_traversal(*this, traits, 2, 3, !first_stationary);
right_child().join_traversal(other_node.left_child(), traits, nb_primitives_this-nb_primitives_this/2,nb_primitives_other/2,first_stationary); }
} }
if (traits.go_further() && traits.do_intersect(right_child(), other_node.right_child(),!first_stationary)) }
{
right_child().join_traversal(other_node.right_child(), traits, nb_primitives_this-nb_primitives_this/2,nb_primitives_other - nb_primitives_other/2,first_stationary);
}
} }
}
// first tree is 3 or smaller and second tree is larger
if (first_tree_small && !second_tree_small) {
if (traits.do_intersect(*this, other_node.left_child(), !first_stationary)) {
other_node.left_child().join_traversal(*this, traits, nb_primitives_other / 2, nb_primitives_this, !first_stationary);
if (traits.go_further() && traits.do_intersect(*this, other_node.right_child(), !first_stationary)) {
other_node.right_child().join_traversal(*this, traits, nb_primitives_other - nb_primitives_other / 2, nb_primitives_this, !first_stationary);
}
} else if (traits.do_intersect(*this, other_node.right_child(), !first_stationary)) {
other_node.right_child().join_traversal(*this, traits, nb_primitives_other - nb_primitives_other / 2, nb_primitives_this, !first_stationary);
}
}
// symetrical to previous case.
if (!first_tree_small && second_tree_small) {
if (traits.do_intersect(left_child(), other_node, !first_stationary)) {
left_child().join_traversal(other_node, traits, nb_primitives_this / 2, nb_primitives_other, first_stationary);
if (traits.go_further() && traits.do_intersect(right_child(), other_node, !first_stationary)) {
right_child().join_traversal(other_node, traits, nb_primitives_this - nb_primitives_this / 2, nb_primitives_other, first_stationary);
}
} else if (traits.do_intersect(right_child(), other_node, !first_stationary)) {
right_child().join_traversal(other_node, traits, nb_primitives_this - nb_primitives_this / 2, nb_primitives_other, first_stationary);
}
}
// both trees as larger then 3
if (!first_tree_small && !second_tree_small) {
if (traits.do_intersect(left_child(), other_node.left_child(), !first_stationary)) {
left_child().join_traversal(other_node.left_child(), traits, nb_primitives_this / 2, nb_primitives_other / 2, first_stationary);
}
if (traits.go_further() && traits.do_intersect(left_child(), other_node.right_child(), !first_stationary)) {
left_child().join_traversal(other_node.right_child(), traits, nb_primitives_this / 2, nb_primitives_other - nb_primitives_other / 2, first_stationary);
}
if (traits.go_further() && traits.do_intersect(right_child(), other_node.left_child(), !first_stationary)) {
right_child().join_traversal(other_node.left_child(), traits, nb_primitives_this - nb_primitives_this / 2, nb_primitives_other / 2, first_stationary);
}
if (traits.go_further() && traits.do_intersect(right_child(), other_node.right_child(), !first_stationary)) {
right_child().join_traversal(other_node.right_child(), traits, nb_primitives_this - nb_primitives_this / 2, nb_primitives_other - nb_primitives_other / 2, first_stationary);
}
}
} }

View File

@ -27,42 +27,49 @@
namespace CGAL { namespace CGAL {
template <class GeomTraits, class Iterator,class Container_type> template <class GeomTraits, class Iterator, class Container_type>
class AABB_segment_2_primitive class AABB_segment_2_primitive {
{ // types
// types
public: public:
typedef typename GeomTraits::Point_2 Point; // point type typedef typename GeomTraits::Point_2 Point; // point type
typedef typename GeomTraits::Segment_2 Datum; // datum type typedef typename GeomTraits::Segment_2 Datum; // datum type
typedef Container_type Container; typedef Container_type Container;
typedef Iterator Id; // Id type typedef Iterator Id; // Id type
// member data // member data
private: private:
Id m_it; Id m_it;
Datum m_datum; Datum m_datum;
public: public:
// constructors // constructors
AABB_segment_2_primitive() {} AABB_segment_2_primitive() {}
AABB_segment_2_primitive(Id it) AABB_segment_2_primitive(Id it)
: m_it(it) : m_it(it) {
{ m_datum = *it; // copy segment
m_datum = *it; // copy segment }
} AABB_segment_2_primitive(const AABB_segment_2_primitive &primitive) {
AABB_segment_2_primitive(const AABB_segment_2_primitive& primitive) m_it = primitive.id();
{ m_datum = primitive.datum();
m_it = primitive.id(); }
m_datum = primitive.datum();
}
public: public:
Id& id() { return m_it; } Id &id() {
const Id& id() const { return m_it; } return m_it;
Datum& datum() { return m_datum; } }
const Datum& datum() const { return m_datum; } const Id &id() const {
return m_it;
}
Datum &datum() {
return m_datum;
}
const Datum &datum() const {
return m_datum;
}
/// Returns a point on the primitive /// Returns a point on the primitive
Point reference_point() const { return m_datum.source(); } Point reference_point() const {
return m_datum.source();
}
}; };
} // end namespace CGAL } // end namespace CGAL

View File

@ -5,24 +5,23 @@
#include <CGAL/Env_default_diagram_1.h> #include <CGAL/Env_default_diagram_1.h>
#include <CGAL/envelope_2.h> #include <CGAL/envelope_2.h>
template <class Kernel_, class Container_> class BounderyConvCalc: public IBounderySumCalculator< Kernel_, Container_>{ template <class Kernel_, class Container_> class BounderyConvCalc: public IBounderySumCalculator< Kernel_, Container_> {
public: public:
typedef Arr_segment_traits_2<Kernel> Traits_2;//Segment_traits_2; typedef Arr_segment_traits_2<Kernel> Traits_2;//Segment_traits_2;
typedef typename Traits_2::X_monotone_curve_2 Segment_2; typedef typename Traits_2::X_monotone_curve_2 Segment_2;
typedef std::list<Segment_2> Segments_list; typedef std::list<Segment_2> Segments_list;
virtual void calc_sum(Polygon_2& a,Polygon_2& b,Polygon_2& res_poly) virtual void calc_sum(Polygon_2 &a, Polygon_2 &b, Polygon_2 &res_poly) {
{ Segments_list reduced_conv;
Segments_list reduced_conv; _mink->buildReducedConvolution(a, b, reduced_conv);
_mink->buildReducedConvolution(a, b, reduced_conv);
} }
private: private:
Minkowski_sum_by_convolution_lien_2<Kernel,Container_>* _mink; Minkowski_sum_by_convolution_lien_2<Kernel, Container_> *_mink;
}; };
#endif #endif

View File

@ -10,314 +10,304 @@
//#include "ReferencePoint_t.h" //#include "ReferencePoint_t.h"
//#include "BasicPolygonManipulation_T.h" //#include "BasicPolygonManipulation_T.h"
class Graphics class Graphics {
{
public: public:
typedef QGraphicsLineItem* Line_handle; typedef QGraphicsLineItem *Line_handle;
typedef std::vector< Line_handle> Object_handle; typedef std::vector< Line_handle> Object_handle;
public: public:
//constructors //constructors
Graphics(int argc, char* argv[],double min_x = -1, double max_x = 1, double min_y = -1, double max_y = 1); Graphics(int argc, char *argv[], double min_x = -1, double max_x = 1, double min_y = -1, double max_y = 1);
//destructor //destructor
~Graphics(void); ~Graphics(void);
//displays current scene //displays current scene
void display(); void display();
//exports current scene //exports current scene
void save_scene(const std::string& path_name); void save_scene(const std::string &path_name);
//clear the scene //clear the scene
void clear(); void clear();
//edge drawing functions //edge drawing functions
template <typename K> void draw_edge (const typename K::Point_2& p1,const typename K::Point_2& p2,const QColor& color) template <typename K> void draw_edge(const typename K::Point_2 &p1, const typename K::Point_2 &p2, const QColor &color) {
{ _scene.addLine(QLineF(to_screen_double_x<K::FT> (p1.x()),
_scene.addLine(QLineF( to_screen_double_x<K::FT> (p1.x()), to_screen_double_y<K::FT> (p1.y()),
to_screen_double_y<K::FT> (p1.y()), to_screen_double_x<K::FT> (p2.x()),
to_screen_double_x<K::FT> (p2.x()), to_screen_double_y<K::FT> (p2.y())),
to_screen_double_y<K::FT> (p2.y())), QPen(color));
QPen(color)); _file_scene.addLine(QLineF(to_file_double_x<K::FT> (p1.x()),
_file_scene.addLine(QLineF( to_file_double_x<K::FT> (p1.x()), to_file_double_y<K::FT> (p1.y()),
to_file_double_y<K::FT> (p1.y()), to_file_double_x<K::FT> (p2.x()),
to_file_double_x<K::FT> (p2.x()), to_file_double_y<K::FT> (p2.y())),
to_file_double_y<K::FT> (p2.y())), QPen(color));
QPen(color));
}
template <typename K> void draw_edge (const typename K::Point_2& p1,const typename K::Point_2& p2,const QColor& color,const QColor& color2)
{
_scene.addLine(QLineF( to_screen_double_x<K::FT> (p1.x()),
to_screen_double_y<K::FT> (p1.y()),
to_screen_double_x<K::FT> (p2.x()),
to_screen_double_y<K::FT> (p2.y())),
QPen(color));
_file_scene.addLine(QLineF( to_file_double_x<K::FT> (p1.x()),
to_file_double_y<K::FT> (p1.y()),
to_file_double_x<K::FT> (p2.x()),
to_file_double_y<K::FT> (p2.y())),
QPen(color));
double startX = CGAL::to_double(p1.x());
double startY = CGAL::to_double(p1.y());
double endX = CGAL::to_double(p2.x());
double endY = CGAL::to_double(p2.y());
double vecX = endX-startX;
double vecY = endY - startY;
double pstartX = endX - 0.1f * vecX;
double pstartY = endY - 0.1f * vecY;
_scene.addLine(QLineF( to_screen_double_x<K::FT> (pstartX),
to_screen_double_y<K::FT> (pstartY),
to_screen_double_x<K::FT> (p2.x()),
to_screen_double_y<K::FT> (p2.y())),
QPen(color2));
_file_scene.addLine(QLineF( to_screen_double_x<K::FT> (pstartX),
to_screen_double_y<K::FT> (pstartY),
to_screen_double_x<K::FT> (p2.x()),
to_screen_double_y<K::FT> (p2.y())),
QPen(color2));
}
template <typename K> void draw_edge (const typename K::Segment_2& s,const QColor& color)
{
return (this->draw_edge<K> (s.source(),s.target(),color));
}
template <typename K> void draw_edge (const typename K::Segment_2& s,const QColor& color,bool)
{
QColor r(255,0,0);
(this->draw_edge<K> (s.source(),s.target(),color,r));
}
//cross drawing functions
template <typename K> void draw_cross(const typename K::Point_2& p,const QColor& color,double size = CROSS_SIZE)
{
draw_edge<K>(K::Point_2(p.x()-size,p.y()),K::Point_2(p.x()+size,p.y()),color);
draw_edge<K>(K::Point_2(p.x(),p.y()+size),K::Point_2(p.x(),p.y()-size),color);
return;
}
//polgon drawing functions
template <typename K> void draw_polygon(const CGAL::Polygon_2<K>& polygon, const QColor& color)
{
typedef CGAL::Polygon_2<K>::Edge_const_iterator E_iter;
for (E_iter ei (polygon.edges_begin()) ; ei != polygon.edges_end(); ++ei)
{
draw_edge<K>(*ei,color);
} }
return ;
}
template <typename K> void draw_polygon(const CGAL::Polygon_with_holes_2<K>& polygon, const QColor& color)
{
//outer boundary
if (! polygon.is_unbounded())
draw_polygon<K> (polygon.outer_boundary(),color);
//holes template <typename K> void draw_edge(const typename K::Point_2 &p1, const typename K::Point_2 &p2, const QColor &color, const QColor &color2) {
CGAL::Polygon_with_holes_2<K>::Hole_const_iterator hit; _scene.addLine(QLineF(to_screen_double_x<K::FT> (p1.x()),
for (hit = polygon.holes_begin(); hit != polygon.holes_end(); ++hit) to_screen_double_y<K::FT> (p1.y()),
draw_polygon<K>(*hit,color); to_screen_double_x<K::FT> (p2.x()),
} to_screen_double_y<K::FT> (p2.y())),
QPen(color));
_file_scene.addLine(QLineF(to_file_double_x<K::FT> (p1.x()),
to_file_double_y<K::FT> (p1.y()),
to_file_double_x<K::FT> (p2.x()),
to_file_double_y<K::FT> (p2.y())),
QPen(color));
//template <typename K> void draw_arrangement(const CGAL) double startX = CGAL::to_double(p1.x());
/* double startY = CGAL::to_double(p1.y());
template <typename K> void draw_polygons(const CGAL::Polygon_set_2<K>& workspace, const QColor& color) double endX = CGAL::to_double(p2.x());
{ double endY = CGAL::to_double(p2.y());
std::list<CGAL::Polygon_with_holes_2<K> > res; double vecX = endX - startX;
std::list<CGAL::Polygon_with_holes_2<K> >::const_iterator pi; double vecY = endY - startY;
workspace.polygons_with_holes (std::back_inserter (res)); double pstartX = endX - 0.1f * vecX;
double pstartY = endY - 0.1f * vecY;
for (pi = res.begin(); pi != res.end(); ++pi) _scene.addLine(QLineF(to_screen_double_x<K::FT> (pstartX),
{ to_screen_double_y<K::FT> (pstartY),
to_screen_double_x<K::FT> (p2.x()),
to_screen_double_y<K::FT> (p2.y())),
QPen(color2));
_file_scene.addLine(QLineF(to_screen_double_x<K::FT> (pstartX),
to_screen_double_y<K::FT> (pstartY),
to_screen_double_x<K::FT> (p2.x()),
to_screen_double_y<K::FT> (p2.y())),
QPen(color2));
}
template <typename K> void draw_edge(const typename K::Segment_2 &s, const QColor &color) {
return (this->draw_edge<K> (s.source(), s.target(), color));
}
template <typename K> void draw_edge(const typename K::Segment_2 &s, const QColor &color, bool) {
QColor r(255, 0, 0);
(this->draw_edge<K> (s.source(), s.target(), color, r));
}
//cross drawing functions
template <typename K> void draw_cross(const typename K::Point_2 &p, const QColor &color, double size = CROSS_SIZE) {
draw_edge<K>(K::Point_2(p.x() - size, p.y()), K::Point_2(p.x() + size, p.y()), color);
draw_edge<K>(K::Point_2(p.x(), p.y() + size), K::Point_2(p.x(), p.y() - size), color);
return;
}
//polgon drawing functions
template <typename K> void draw_polygon(const CGAL::Polygon_2<K> &polygon, const QColor &color) {
typedef CGAL::Polygon_2<K>::Edge_const_iterator E_iter;
for (E_iter ei(polygon.edges_begin()) ; ei != polygon.edges_end(); ++ei) {
draw_edge<K>(*ei, color);
}
return ;
}
template <typename K> void draw_polygon(const CGAL::Polygon_with_holes_2<K> &polygon, const QColor &color) {
//outer boundary
if (! polygon.is_unbounded()) {
draw_polygon<K> (polygon.outer_boundary(), color);
}
//holes
CGAL::Polygon_with_holes_2<K>::Hole_const_iterator hit;
for (hit = polygon.holes_begin(); hit != polygon.holes_end(); ++hit) {
draw_polygon<K>(*hit, color);
}
}
//template <typename K> void draw_arrangement(const CGAL)
/*
template <typename K> void draw_polygons(const CGAL::Polygon_set_2<K>& workspace, const QColor& color)
{
std::list<CGAL::Polygon_with_holes_2<K> > res;
std::list<CGAL::Polygon_with_holes_2<K> >::const_iterator pi;
workspace.polygons_with_holes (std::back_inserter (res));
for (pi = res.begin(); pi != res.end(); ++pi)
{
draw_polygon<K>(*pi,color);
}
return;
}
template <typename K> void draw_polygons(const std::vector <CGAL::Polygon_2<K> >& workspace, const QColor& color)
{
std::vector <CGAL::Polygon_2<K> >::const_iterator pi;
for (pi=workspace.begin(); pi != workspace.end(); ++pi)
{
draw_polygon<K>(*pi,color); draw_polygon<K>(*pi,color);
}
return;
}
template <typename K> void draw_polygons(const std::vector <CGAL::Polygon_2<K> >& workspace, const QColor& color)
{
std::vector <CGAL::Polygon_2<K> >::const_iterator pi;
for (pi=workspace.begin(); pi != workspace.end(); ++pi)
{
draw_polygon<K>(*pi,color);
}
return;
}
template <typename K> void draw_polygons(const std::vector <CGAL::Polygon_with_holes_2<K> >& workspace, const QColor& color)
{
std::vector <CGAL::Polygon_with_holes_2<K> >::const_iterator pi;
for (pi=workspace.begin(); pi != workspace.end(); ++pi)
{
draw_polygon<K>(*pi,color);
}
return;
}
*/
//utils
template <typename K> void draw_axis (const QColor& color = BLUE)
{
draw_edge<K> (typename K::Segment_2 (typename K::Point_2(0,0),typename K::Point_2(0,1)),color);
draw_edge<K> (typename K::Segment_2 (typename K::Point_2(0,0),typename K::Point_2(1,0)),color);
return;
}
/* template <typename K>
void draw_path(std::vector<Reference_point_t<K> >& path,
typename Extended_polygon_t<K> & polygon,
bool to_draw_polygon)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{
int red = d_red;
int green = d_green;
polygon.move_absolute(ref_p);
if (to_draw_polygon)
{
draw_polygon<K> (polygon.get_absolute_polygon(),QColor(red,green,0));
}
else //!(to_draw_polygon)
{
K::Point_2 polygon_ref_point = get_reference_point(polygon.get_absolute_polygon());
draw_cross<K>(polygon_ref_point ,QColor(red,green,0),0.025);
}
d_red+=color_step;
d_green-=color_step;
} }
return;
return;
}
template <typename K>
void save_path(std::vector<Reference_point_t<K> >& path,
typename Extended_polygon_t<K> & polygon,
const std::vector <CGAL::Polygon_2<K> >& workspace,
bool to_draw_polygon,
const std::string& path_name)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{
int red = d_red;
int green = d_green;
polygon.move_absolute(ref_p);
clear();
draw_polygons<K>(workspace,BLUE);
if (to_draw_polygon)
draw_polygon<K> (polygon.get_absolute_polygon(),QColor(red,green,0));
else //!(to_draw_polygon)
draw_cross<K>(get_reference_point(polygon.get_absolute_polygon()) ,QColor(red,green,0),0.025);
save_scene(path_name);
d_red+=color_step;
d_green-=color_step;
} }
template <typename K> void draw_polygons(const std::vector <CGAL::Polygon_with_holes_2<K> >& workspace, const QColor& color)
return;
}
template <typename K>
void draw_path_dbg(std::vector<Reference_point_t<K> >& path,
typename K::Point_2 & v)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{ {
int red = d_red; std::vector <CGAL::Polygon_with_holes_2<K> >::const_iterator pi;
int green = d_green; for (pi=workspace.begin(); pi != workspace.end(); ++pi)
K::Point_2 rotated (rotate_point<K> (v,ref_p.get_rotation()));
K::Point_2 moved (translate_point<K>(rotated,ref_p.get_location()));
K::Segment_2 rod(ref_p.get_location(),moved);
draw_edge<K> (rod,QColor(red,green,0));
d_red+=color_step;
d_green-=color_step;
}
return;
}
template <typename K>
void draw_path_dbg(std::vector<Reference_point_t<K> >& path,
typename K::Segment_2 & e)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{ {
int red = d_red; draw_polygon<K>(*pi,color);
int green = d_green;
K::Point_2 rotated1,moved1,rotated2,moved2;
rotated1 = rotate_point<K> (e.source(),ref_p.get_rotation());
moved1 = translate_point<K>(rotated1,ref_p.get_location());
rotated2 = rotate_point<K> (e.target(),ref_p.get_rotation());
moved2 = translate_point<K>(rotated2,ref_p.get_location());
K::Segment_2 edge(moved1,moved2);
K::Segment_2 rod1(ref_p.get_location(),moved1);
K::Segment_2 rod2(ref_p.get_location(),moved2);
draw_edge<K> (edge,QColor(red,green,0));
draw_edge<K> (rod1,QColor(red,green,0));
draw_edge<K> (rod2,QColor(red,green,0));
d_red+=color_step;
d_green-=color_step;
} }
return;
}
*/
//utils
template <typename K> void draw_axis(const QColor &color = BLUE) {
draw_edge<K> (typename K::Segment_2(typename K::Point_2(0, 0), typename K::Point_2(0, 1)), color);
draw_edge<K> (typename K::Segment_2(typename K::Point_2(0, 0), typename K::Point_2(1, 0)), color);
return;
}
/* template <typename K>
void draw_path(std::vector<Reference_point_t<K> >& path,
typename Extended_polygon_t<K> & polygon,
bool to_draw_polygon)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
return; Reference_point_t<K> ref_p;
}*/ BOOST_FOREACH (ref_p,path)
private: {
template <typename NT> double to_screen_double_x(const NT& x) int red = d_red;
{ int green = d_green;
return ((CGAL::to_double (x) - _min_x) * _ratio_x); polygon.move_absolute(ref_p);
} if (to_draw_polygon)
template <typename NT> double to_screen_double_y(const NT& y) {
{ draw_polygon<K> (polygon.get_absolute_polygon(),QColor(red,green,0));
return (- (CGAL::to_double (y) - _min_y) * _ratio_y); }
} else //!(to_draw_polygon)
template <typename NT> double to_file_double_x(const NT& x) {
{ K::Point_2 polygon_ref_point = get_reference_point(polygon.get_absolute_polygon());
return (CGAL::to_double (x)); draw_cross<K>(polygon_ref_point ,QColor(red,green,0),0.025);
} }
template <typename NT> double to_file_double_y(const NT& y)
{ d_red+=color_step;
return (-CGAL::to_double (y)); d_green-=color_step;
} }
return;
}
template <typename K>
void save_path(std::vector<Reference_point_t<K> >& path,
typename Extended_polygon_t<K> & polygon,
const std::vector <CGAL::Polygon_2<K> >& workspace,
bool to_draw_polygon,
const std::string& path_name)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{
int red = d_red;
int green = d_green;
polygon.move_absolute(ref_p);
clear();
draw_polygons<K>(workspace,BLUE);
if (to_draw_polygon)
draw_polygon<K> (polygon.get_absolute_polygon(),QColor(red,green,0));
else //!(to_draw_polygon)
draw_cross<K>(get_reference_point(polygon.get_absolute_polygon()) ,QColor(red,green,0),0.025);
save_scene(path_name);
d_red+=color_step;
d_green-=color_step;
}
return;
}
template <typename K>
void draw_path_dbg(std::vector<Reference_point_t<K> >& path,
typename K::Point_2 & v)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{
int red = d_red;
int green = d_green;
K::Point_2 rotated (rotate_point<K> (v,ref_p.get_rotation()));
K::Point_2 moved (translate_point<K>(rotated,ref_p.get_location()));
K::Segment_2 rod(ref_p.get_location(),moved);
draw_edge<K> (rod,QColor(red,green,0));
d_red+=color_step;
d_green-=color_step;
}
return;
}
template <typename K>
void draw_path_dbg(std::vector<Reference_point_t<K> >& path,
typename K::Segment_2 & e)
{
double path_size = path.size();
double color_step = (double)255/(double)path_size;
double d_red=0;
double d_green=255;
Reference_point_t<K> ref_p;
BOOST_FOREACH (ref_p,path)
{
int red = d_red;
int green = d_green;
K::Point_2 rotated1,moved1,rotated2,moved2;
rotated1 = rotate_point<K> (e.source(),ref_p.get_rotation());
moved1 = translate_point<K>(rotated1,ref_p.get_location());
rotated2 = rotate_point<K> (e.target(),ref_p.get_rotation());
moved2 = translate_point<K>(rotated2,ref_p.get_location());
K::Segment_2 edge(moved1,moved2);
K::Segment_2 rod1(ref_p.get_location(),moved1);
K::Segment_2 rod2(ref_p.get_location(),moved2);
draw_edge<K> (edge,QColor(red,green,0));
draw_edge<K> (rod1,QColor(red,green,0));
draw_edge<K> (rod2,QColor(red,green,0));
d_red+=color_step;
d_green-=color_step;
}
return;
}*/
private:
template <typename NT> double to_screen_double_x(const NT &x) {
return ((CGAL::to_double(x) - _min_x) * _ratio_x);
}
template <typename NT> double to_screen_double_y(const NT &y) {
return (- (CGAL::to_double(y) - _min_y) * _ratio_y);
}
template <typename NT> double to_file_double_x(const NT &x) {
return (CGAL::to_double(x));
}
template <typename NT> double to_file_double_y(const NT &y) {
return (-CGAL::to_double(y));
}
private: private:
QApplication app; QApplication app;
QGraphicsScene _scene; QGraphicsScene _scene;
QGraphicsScene _file_scene; QGraphicsScene _file_scene;
double _min_x; double _min_x;
double _max_x; double _max_x;
double _min_y; double _min_y;
double _max_y; double _max_y;
double _ratio_x; double _ratio_x;
double _ratio_y; double _ratio_y;
}; };
extern Graphics* global_graphics; extern Graphics *global_graphics;
#endif //Graphics_H #endif //Graphics_H

View File

@ -4,13 +4,13 @@
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2.h>
template <class Kernel_, class Container_> class IBounderySumCalculator{ template <class Kernel_, class Container_> class IBounderySumCalculator {
protected: protected:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2; typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2;
public: public:
virtual void calc_sum(Polygon_2& a,Polygon_2& b,Polygon_2& res_poly)=0; virtual void calc_sum(Polygon_2 &a, Polygon_2 &b, Polygon_2 &res_poly) = 0;
}; };

View File

@ -4,12 +4,12 @@
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2.h>
template <class Kernel_, class Container_> class ICollisionDetector{ template <class Kernel_, class Container_> class ICollisionDetector {
public: public:
typedef Kernel_ Kernel; typedef Kernel_ Kernel;
typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2; typedef CGAL::Polygon_2<Kernel, Container_> Polygon_2;
virtual bool checkCollision(const Polygon_2& p,const Polygon_2& q) =0; virtual bool checkCollision(const Polygon_2 &p, const Polygon_2 &q) = 0;
}; };
#endif #endif

View File

@ -4,57 +4,58 @@
#include <CGAL/intersections.h> #include <CGAL/intersections.h>
#include <CGAL/Boolean_set_operations_2.h> #include <CGAL/Boolean_set_operations_2.h>
template <class Kernel_, class Container_> class NaiveCollisionDetector : public ICollisionDetector< Kernel_, Container_> template <class Kernel_, class Container_> class NaiveCollisionDetector : public ICollisionDetector< Kernel_, Container_> {
{
public: public:
NaiveCollisionDetector(){} NaiveCollisionDetector() {}
typedef CGAL::Polygon_2<Kernel_> Polygon_2; typedef CGAL::Polygon_2<Kernel_> Polygon_2;
typedef typename Polygon_2::Edge_const_iterator Edge_iterator ; typedef typename Polygon_2::Edge_const_iterator Edge_iterator ;
typedef typename Polygon_2::Traits::Segment_2 Segment_2 ; typedef typename Polygon_2::Traits::Segment_2 Segment_2 ;
//typedef typename Polygon_2::Vertex_circulator Vertex_circulator; //typedef typename Polygon_2::Vertex_circulator Vertex_circulator;
//typedef typename //typedef typename
virtual bool checkCollision(const Polygon_2& p,const Polygon_2& q) virtual bool checkCollision(const Polygon_2 &p, const Polygon_2 &q) {
{ bool intersect = false;
bool intersect = false;
if (CGAL::do_intersect(p,q))
return true;
else return false;
/* if (CGAL::do_intersect(p, q)) {
for (Edge_iterator itr1 = p.edges_begin();itr1!=p.edges_end();++itr1) return true;
{ } else {
for (Edge_iterator itr2 = q.edges_begin();itr2!=q.edges_end();++itr2) return false;
{ }
//intersect = intersect CGAL::Do_intersect(*itr1,*itr2);
CGAL::Object result = CGAL::intersection(*itr1,*itr2);
if (const CGAL::Point_2<Kernel> *ipoint = CGAL::object_cast<CGAL::Point_2<Kernel> >(&result)) {
// handle the point intersection case with *ipoint.
// check if the intersection point is the vertex of one of the edges
if (((*ipoint)==itr1->source()) || ((*ipoint)==itr1->target())
||((*ipoint)==itr2->source()) || ((*ipoint)==itr2->target()))
intersect = false;
else
intersect = true;
} else
if (const CGAL::Segment_2<Kernel> *iseg = CGAL::object_cast<CGAL::Segment_2<Kernel> >(&result)) {
// handle the segment intersection case with *iseg. this is the case where the edges are touching
intersect = false;
} else {
// handle the no intersection case.
}
if (intersect) /*
return intersect; for (Edge_iterator itr1 = p.edges_begin();itr1!=p.edges_end();++itr1)
} {
for (Edge_iterator itr2 = q.edges_begin();itr2!=q.edges_end();++itr2)
{
//intersect = intersect CGAL::Do_intersect(*itr1,*itr2);
CGAL::Object result = CGAL::intersection(*itr1,*itr2);
if (const CGAL::Point_2<Kernel> *ipoint = CGAL::object_cast<CGAL::Point_2<Kernel> >(&result)) {
// handle the point intersection case with *ipoint.
// check if the intersection point is the vertex of one of the edges
if (((*ipoint)==itr1->source()) || ((*ipoint)==itr1->target())
||((*ipoint)==itr2->source()) || ((*ipoint)==itr2->target()))
intersect = false;
else
intersect = true;
} else
if (const CGAL::Segment_2<Kernel> *iseg = CGAL::object_cast<CGAL::Segment_2<Kernel> >(&result)) {
// handle the segment intersection case with *iseg. this is the case where the edges are touching
intersect = false;
} else {
// handle the no intersection case.
}
} if (intersect)
return intersect;
}
if (p.bounded_side(*q.vertices_begin())== CGAL::ON_BOUNDED_SIDE || q.bounded_side(*p.vertices_begin())== CGAL::ON_BOUNDED_SIDE) }
return true;
return intersect;
*/
} if (p.bounded_side(*q.vertices_begin())== CGAL::ON_BOUNDED_SIDE || q.bounded_side(*p.vertices_begin())== CGAL::ON_BOUNDED_SIDE)
return true;
return intersect;
*/
}
}; };