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

@ -3,61 +3,59 @@
#include "ICollisionDetector.h"
#include <CGAL/Arrangement_on_surface_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/intersections.h>
#include <CGAL/intersections.h>
#include "AABB_tree_mod.h"
#include "AABB_2d_traits.h"
#include "AABB_segment_2_primitive.h"
namespace CGAL{
template <class Kernel_, class Container_> class AABBCollisionDetector : public ICollisionDetector< Kernel_, Container_>
{
namespace CGAL {
template <class Kernel_, class Container_> class AABBCollisionDetector : public ICollisionDetector< Kernel_, Container_> {
public:
typedef typename Kernel_::Point_2 Point;
typedef typename CGAL::Polygon_2<Kernel_> Polygon_2;
//typedef typename Polygon_2::Edge_const_iterator Edge_iterator ;
typedef typename Polygon_2::Traits::Segment_2 Segment_2 ;
typedef typename Polygon_2::Edge_const_iterator Edge_iterator;
typedef typename Polygon_2::Edge_const_circulator Edge_circulator;
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_tree<Tree_Traits> AABB_Tree;
typedef CGAL::Arr_segment_traits_2<Kernel_> Traits_2;
typedef typename Kernel_::Point_2 Point;
typedef typename CGAL::Polygon_2<Kernel_> Polygon_2;
//typedef typename Polygon_2::Edge_const_iterator Edge_iterator ;
typedef typename Polygon_2::Traits::Segment_2 Segment_2 ;
typedef typename Polygon_2::Edge_const_iterator Edge_iterator;
typedef typename Polygon_2::Edge_const_circulator Edge_circulator;
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_tree<Tree_Traits> AABB_Tree;
typedef CGAL::Arr_segment_traits_2<Kernel_> Traits_2;
protected:
Traits_2 m_traits;
Traits_2 m_traits;
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)
: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
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();
if (m_stationary_tree.do_intersect_join(m_translating_tree,m_translation_point,m_p,m_q))
return true;
return (p.has_on_bounded_side(*(q.vertices_begin())) || q.has_on_bounded_side(*(p.vertices_begin())));
//return true;
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) {
}
}
//typedef typename Polygon_2::Vertex_circulator Vertex_circulator;
//typedef typename
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();
void setTranslationPoint(const Point& t){
m_translation_point = t;
}
if (m_stationary_tree.do_intersect_join(m_translating_tree, m_translation_point, m_p, m_q)) {
return true;
}
return (p.has_on_bounded_side(*(q.vertices_begin())) || q.has_on_bounded_side(*(p.vertices_begin())));
//return true;
}
void setTranslationPoint(const Point &t) {
m_translation_point = t;
}
private:
AABB_Tree m_stationary_tree;
AABB_Tree m_translating_tree;
Point m_translation_point;
Polygon_2& m_p;
Polygon_2& m_q;
AABB_Tree m_stationary_tree;
AABB_Tree m_translating_tree;
Point m_translation_point;
Polygon_2 &m_p;
Polygon_2 &m_q;
};
}

View File

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

View File

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

View File

@ -5,24 +5,23 @@
#include <CGAL/Env_default_diagram_1.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:
typedef Arr_segment_traits_2<Kernel> Traits_2;//Segment_traits_2;
typedef typename Traits_2::X_monotone_curve_2 Segment_2;
typedef std::list<Segment_2> Segments_list;
typedef Arr_segment_traits_2<Kernel> Traits_2;//Segment_traits_2;
typedef typename Traits_2::X_monotone_curve_2 Segment_2;
typedef std::list<Segment_2> Segments_list;
virtual void calc_sum(Polygon_2& a,Polygon_2& b,Polygon_2& res_poly)
{
Segments_list reduced_conv;
_mink->buildReducedConvolution(a, b, reduced_conv);
virtual void calc_sum(Polygon_2 &a, Polygon_2 &b, Polygon_2 &res_poly) {
Segments_list reduced_conv;
_mink->buildReducedConvolution(a, b, reduced_conv);
}
}
private:
Minkowski_sum_by_convolution_lien_2<Kernel,Container_>* _mink;
Minkowski_sum_by_convolution_lien_2<Kernel, Container_> *_mink;
};
#endif

View File

@ -10,314 +10,304 @@
//#include "ReferencePoint_t.h"
//#include "BasicPolygonManipulation_T.h"
class Graphics
{
class Graphics {
public:
typedef QGraphicsLineItem* Line_handle;
typedef std::vector< Line_handle> Object_handle;
typedef QGraphicsLineItem *Line_handle;
typedef std::vector< Line_handle> Object_handle;
public:
//constructors
Graphics(int argc, char* argv[],double min_x = -1, double max_x = 1, double min_y = -1, double max_y = 1);
//destructor
~Graphics(void);
//displays current scene
void display();
//exports current scene
void save_scene(const std::string& path_name);
//clear the scene
void clear();
//edge drawing functions
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()),
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));
}
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));
//constructors
Graphics(int argc, char *argv[], double min_x = -1, double max_x = 1, double min_y = -1, double max_y = 1);
//destructor
~Graphics(void);
//displays current scene
void display();
//exports current scene
void save_scene(const std::string &path_name);
//clear the scene
void clear();
//edge drawing functions
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()),
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
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_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));
//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));
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;
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);
}
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;
}
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;
}
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)
template <typename K> void draw_polygons(const std::vector <CGAL::Polygon_with_holes_2<K> >& workspace, const QColor& color)
{
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)
std::vector <CGAL::Polygon_with_holes_2<K> >::const_iterator pi;
for (pi=workspace.begin(); pi != workspace.end(); ++pi)
{
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;
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;
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));
}
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;
}
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:
QApplication app;
QGraphicsScene _scene;
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:
QApplication app;
QGraphicsScene _scene;
QGraphicsScene _file_scene;
double _min_x;
double _max_x;
double _min_y;
double _max_y;
double _ratio_x;
double _ratio_y;
double _min_x;
double _max_x;
double _min_y;
double _max_y;
double _ratio_x;
double _ratio_y;
};
extern Graphics* global_graphics;
extern Graphics *global_graphics;
#endif //Graphics_H

View File

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

View File

@ -1,60 +1,61 @@
#ifndef NAIVECOLLISIONDETECTOR_HEADER
#define NAIVECOLLISIONDETECTOR_HEADER
#include "ICollisionDetector.h"
#include <CGAL/intersections.h>
#include <CGAL/intersections.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:
NaiveCollisionDetector(){}
NaiveCollisionDetector() {}
typedef CGAL::Polygon_2<Kernel_> Polygon_2;
typedef typename Polygon_2::Edge_const_iterator Edge_iterator ;
typedef typename Polygon_2::Traits::Segment_2 Segment_2 ;
//typedef typename Polygon_2::Vertex_circulator Vertex_circulator;
//typedef typename
virtual bool checkCollision(const Polygon_2& p,const Polygon_2& q)
{
bool intersect = false;
if (CGAL::do_intersect(p,q))
return true;
else return false;
typedef typename Polygon_2::Edge_const_iterator Edge_iterator ;
typedef typename Polygon_2::Traits::Segment_2 Segment_2 ;
//typedef typename Polygon_2::Vertex_circulator Vertex_circulator;
//typedef typename
virtual bool checkCollision(const Polygon_2 &p, const Polygon_2 &q) {
bool intersect = false;
/*
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 (CGAL::do_intersect(p, q)) {
return true;
} else {
return false;
}
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;
*/
}
};