mirror of https://github.com/CGAL/cgal
Enrich Projection_traits so that it can be used with AABB_traits_2
This commit is contained in:
parent
e62f249a49
commit
f231a3d812
|
|
@ -6,8 +6,10 @@
|
|||
#include <CGAL/AABB_tree.h>
|
||||
#include <CGAL/AABB_traits_2.h>
|
||||
#include <CGAL/AABB_indexed_triangle_primitive_2.h>
|
||||
#include <CGAL/Projection_traits_xy_3.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> K;
|
||||
typedef CGAL::Simple_cartesian<double> SC;
|
||||
typedef CGAL::Projection_traits_xy_3<SC> K;
|
||||
typedef K::Point_2 Point;
|
||||
|
||||
typedef std::vector<std::array<uint8_t, 3> >::iterator IndexIterator;
|
||||
|
|
@ -19,12 +21,12 @@ typedef Tree::Point_and_primitive_id Point_and_primitive_id;
|
|||
|
||||
int main()
|
||||
{
|
||||
Point a(0.0, 0.0);
|
||||
Point b(0.0, 1.0);
|
||||
Point c(1.0, 0.0);
|
||||
Point d(1.0, 1.0);
|
||||
Point e(2.0, 0.0);
|
||||
Point f(2.0, 1.0);
|
||||
Point a(0.0, 0.0, 0.0);
|
||||
Point b(0.0, 1.0, 0.0);
|
||||
Point c(1.0, 0.0, 0.0);
|
||||
Point d(1.0, 1.0, 0.0);
|
||||
Point e(2.0, 0.0, 0.0);
|
||||
Point f(2.0, 1.0, 0.0);
|
||||
|
||||
std::vector<Point> points = { a, b, c, d, e, f };
|
||||
|
||||
|
|
@ -39,17 +41,17 @@ int main()
|
|||
|
||||
// point sampling
|
||||
Point_and_primitive_id id;
|
||||
id = tree.closest_point_and_primitive(Point(0.5, 0.4));
|
||||
id = tree.closest_point_and_primitive(Point(0.5, 0.4, 0.0));
|
||||
std::cout << std::distance(triangles.begin(), id.second) << ". triangle" << std::endl;
|
||||
id = tree.closest_point_and_primitive(Point(0.5, 0.6));
|
||||
id = tree.closest_point_and_primitive(Point(0.5, 0.6, 0.0));
|
||||
std::cout << std::distance(triangles.begin(), id.second) << ". triangle" << std::endl;
|
||||
id = tree.closest_point_and_primitive(Point(1.5, 0.5));
|
||||
id = tree.closest_point_and_primitive(Point(1.5, 0.5, 0.0));
|
||||
std::cout << std::distance(triangles.begin(), id.second) << ". triangle" << std::endl;
|
||||
id = tree.closest_point_and_primitive(Point(1.5, 0.6));
|
||||
id = tree.closest_point_and_primitive(Point(1.5, 0.6, 0.0));
|
||||
std::cout << std::distance(triangles.begin(), id.second) << ". triangle" << std::endl;
|
||||
id = tree.closest_point_and_primitive(Point(1.0, 0.0));
|
||||
id = tree.closest_point_and_primitive(Point(1.0, 0.0, 0.0));
|
||||
std::cout << std::distance(triangles.begin(), id.second) << ". triangle" << std::endl;
|
||||
id = tree.closest_point_and_primitive(Point(3.0, 0.5));
|
||||
id = tree.closest_point_and_primitive(Point(3.0, 0.5, 0.0));
|
||||
std::cout << std::distance(triangles.begin(), id.second) << ". triangle" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -192,6 +192,11 @@ public:
|
|||
/// Point query type.
|
||||
typedef typename GeomTraits::Point_2 Point_2;
|
||||
|
||||
/// <summary>
|
||||
/// point type
|
||||
/// </summary>
|
||||
typedef Point_2 Point;
|
||||
|
||||
/// additional types for the search tree, required by the RangeSearchTraits concept
|
||||
/// \bug This is not documented for now in the AABBTraits concept.
|
||||
typedef typename GeomTraits::Iso_rectangle_2 Iso_rectangle_2;
|
||||
|
|
@ -446,7 +451,7 @@ private:
|
|||
|
||||
Bounding_box compute_bbox(const Primitive& pr, const Default&)const
|
||||
{
|
||||
return internal::Primitive_helper<AT>::get_datum(pr,*this).bbox();
|
||||
return GeomTraits().construct_bbox_2_object()(internal::Primitive_helper<AT>::get_datum(pr, *this));
|
||||
}
|
||||
|
||||
/// Comparison functions
|
||||
|
|
|
|||
|
|
@ -87,13 +87,32 @@ struct Projector<R,2>
|
|||
static const int y_index=1;
|
||||
};
|
||||
|
||||
template <class R, int dim>
|
||||
class Construct_cartesian_const_iterator_projected_3 {
|
||||
public:
|
||||
typedef typename R::Point_3 Point_3;
|
||||
typedef typename R::Cartesian_const_iterator_3 Cartesian_const_iterator;
|
||||
Cartesian_const_iterator operator()(const Point_3& p) const
|
||||
{
|
||||
return typename R::Construct_cartesian_const_iterator_3()(p);
|
||||
}
|
||||
Cartesian_const_iterator operator()(const Point_3& p, int) const
|
||||
{
|
||||
Cartesian_const_iterator it = typename R::Construct_cartesian_const_iterator_3()(p,0);
|
||||
--it;
|
||||
return it;
|
||||
}
|
||||
};
|
||||
|
||||
template <class R,int dim>
|
||||
class Construct_bbox_projected_2 {
|
||||
public:
|
||||
typedef typename R::Point_3 Point;
|
||||
typedef typename R::Triangle_3 Triangle_3;
|
||||
typedef Bbox_2 result_type;
|
||||
|
||||
Bbox_2 operator()(const Point& p) const { typename R::Construct_bbox_3 bb; return Projector<R, dim>::bbox(bb(p)); }
|
||||
Bbox_2 operator()(const Triangle_3& t) const { typename R::Construct_bbox_3 bb; return Projector<R, dim>::bbox(bb(t)); }
|
||||
};
|
||||
|
||||
template <class R,int dim>
|
||||
|
|
@ -203,6 +222,108 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <class R, int dim>
|
||||
class Construct_center_3
|
||||
{
|
||||
public:
|
||||
typedef typename R::Sphere_3 Sphere_3;
|
||||
typedef typename R::Point_3 Point_3;
|
||||
typedef typename R::Point_2 Point_2;
|
||||
typedef typename R::FT RT;
|
||||
typename R::FT x(const Point_3& p) const { return Projector<R, dim>::x(p); }
|
||||
typename R::FT y(const Point_3& p) const { return Projector<R, dim>::y(p); }
|
||||
|
||||
Point_2 project(const Point_3& p) const
|
||||
{
|
||||
return Point_2(x(p), y(p));
|
||||
}
|
||||
|
||||
Point_2 operator()(const Sphere_3& s) const
|
||||
{
|
||||
Point_3 p = typename R::Construct_center_3()(s);
|
||||
return project(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class R, int dim>
|
||||
class Construct_projected_point_3
|
||||
{
|
||||
public:
|
||||
typedef typename R::Point_3 Point_3;
|
||||
typedef typename R::Point_2 Point_2;
|
||||
typedef typename R::Triangle_3 Triangle_3;
|
||||
typedef typename R::Triangle_2 Triangle_2;
|
||||
typedef typename R::FT RT;
|
||||
typename R::FT x(const Point_3& p) const { return Projector<R, dim>::x(p); }
|
||||
typename R::FT y(const Point_3& p) const { return Projector<R, dim>::y(p); }
|
||||
|
||||
Point_2 project(const Point_3& p) const
|
||||
{
|
||||
return Point_2(x(p), y(p));
|
||||
}
|
||||
|
||||
Point_3 operator()(const Triangle_3& t, const Point_3& p) const
|
||||
{
|
||||
Point_2 p2 = typename R::Construct_projected_point_2()(Triangle_2(project(t.vertex(0)), project(t.vertex(1)), project(t.vertex(2))),
|
||||
project(p));
|
||||
return Point_3(p.x(), p.y(), 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Point_3 operator()(const T& t, const Point_3& p) const
|
||||
{ std::cout << "todo: implement Projection_traits_3::Construct_projected_point_3 for " << typeid(t).name() << " and Point_3" << std::endl;
|
||||
return Point_3();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class R, int dim>
|
||||
class Construct_min_vertex_3
|
||||
{
|
||||
public:
|
||||
typedef typename R::Iso_cuboid_3 Iso_cuboid_3;
|
||||
typedef typename R::Point_3 Point_3;
|
||||
typedef typename R::Point_2 Point_2;
|
||||
typedef typename R::FT RT;
|
||||
typename R::FT x(const Point_3& p) const { return Projector<R, dim>::x(p); }
|
||||
typename R::FT y(const Point_3& p) const { return Projector<R, dim>::y(p); }
|
||||
|
||||
Point_2 project(const Point_3& p) const
|
||||
{
|
||||
return Point_2(x(p), y(p));
|
||||
}
|
||||
|
||||
Point_2 operator()(const Iso_cuboid_3& ic) const
|
||||
{
|
||||
Point_3 p = typename R::Construct_min_vertex_3()(ic);
|
||||
return project(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class R, int dim>
|
||||
class Construct_max_vertex_3
|
||||
{
|
||||
public:
|
||||
typedef typename R::Iso_cuboid_3 Iso_cuboid_3;
|
||||
typedef typename R::Point_3 Point_3;
|
||||
typedef typename R::Point_2 Point_2;
|
||||
typedef typename R::FT RT;
|
||||
typename R::FT x(const Point_3& p) const { return Projector<R, dim>::x(p); }
|
||||
typename R::FT y(const Point_3& p) const { return Projector<R, dim>::y(p); }
|
||||
|
||||
Point_2 project(const Point_3& p) const
|
||||
{
|
||||
return Point_2(x(p), y(p));
|
||||
}
|
||||
|
||||
Point_2 operator()(const Iso_cuboid_3& ic) const
|
||||
{
|
||||
Point_3 p = typename R::Construct_max_vertex_3()(ic);
|
||||
return project(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class R,int dim>
|
||||
class Compare_distance_projected_3
|
||||
{
|
||||
|
|
@ -401,6 +522,35 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
template <class R, int dim>
|
||||
class Do_intersect_projected_3
|
||||
{
|
||||
public:
|
||||
typedef typename R::Point_3 Point_3;
|
||||
typedef typename R::Sphere_3 Sphere_3;
|
||||
typedef typename R::Point_2 Point_2;
|
||||
typedef typename R::Vector_2 Vector_2;
|
||||
typedef typename R::Circle_2 Circle_2;
|
||||
typedef typename R::FT FT;
|
||||
|
||||
typename R::FT x(const Point_3& p) const { return Projector<R, dim>::x(p); }
|
||||
typename R::FT y(const Point_3& p) const { return Projector<R, dim>::y(p); }
|
||||
|
||||
Point_2 project(const Point_3& p) const
|
||||
{
|
||||
return Point_2(x(p), y(p));
|
||||
}
|
||||
|
||||
bool operator()(const Sphere_3& s, const Bbox_2& bb)
|
||||
{
|
||||
Circle_2 circ(project(s.center()), s.squared_radius());
|
||||
|
||||
return R::Do_intersect_2()(circ,bb);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class R,int dim>
|
||||
class Intersect_projected_3
|
||||
{
|
||||
|
|
@ -927,6 +1077,9 @@ public:
|
|||
typedef typename Rp::Triangle_3 Triangle_2;
|
||||
typedef typename Rp::Line_3 Line_2;
|
||||
typedef typename Rp::Ray_3 Ray_2;
|
||||
typedef typename Rp::Iso_cuboid_3 Iso_rectangle_2;
|
||||
typedef typename Rp::Sphere_3 Circle_2;
|
||||
typedef typename Rp::Cartesian_const_iterator_3 Cartesian_const_iterator_2;
|
||||
|
||||
typedef typename Projector<R,dim>::Less_x_2 Less_x_2;
|
||||
typedef typename Projector<R,dim>::Less_y_2 Less_y_2;
|
||||
|
|
@ -943,6 +1096,7 @@ public:
|
|||
typedef Collinear_are_ordered_along_line_projected_3<Rp,dim> Collinear_are_ordered_along_line_2;
|
||||
typedef Squared_distance_projected_3<Rp,dim> Compute_squared_distance_2;
|
||||
typedef Intersect_projected_3<Rp,dim> Intersect_2;
|
||||
typedef Do_intersect_projected_3<Rp, dim> Do_intersect_2;
|
||||
typedef Compute_squared_radius_projected<Rp,dim> Compute_squared_radius_2;
|
||||
typedef Compute_scalar_product_projected_3<Rp,dim> Compute_scalar_product_2;
|
||||
typedef Compute_squared_length_projected_3<Rp,dim> Compute_squared_length_2;
|
||||
|
|
@ -959,6 +1113,14 @@ public:
|
|||
|
||||
typedef Construct_centroid_projected_3<Rp,dim> Construct_centroid_2;
|
||||
typedef Compute_determinant_projected_3<Rp,dim> Compute_determinant_2;
|
||||
typedef Construct_min_vertex_3<Rp, dim> Construct_min_vertex_2;
|
||||
typedef Construct_max_vertex_3<Rp, dim> Construct_max_vertex_2;
|
||||
typedef Construct_center_3<Rp, dim> Construct_center_2;
|
||||
typedef Construct_projected_point_3<Rp, dim> Construct_projected_point_2;
|
||||
|
||||
typedef typename Rp::Construct_iso_cuboid_3 Construct_iso_rectangle_2;
|
||||
typedef typename Rp::Construct_sphere_3 Construct_circle_2;
|
||||
typedef Construct_cartesian_const_iterator_projected_3<Rp,dim> Construct_cartesian_const_iterator_2;
|
||||
|
||||
typedef typename Rp::Construct_point_3 Construct_point_2;
|
||||
typedef typename Rp::Construct_weighted_point_3 Construct_weighted_point_2;
|
||||
|
|
@ -1136,6 +1298,16 @@ public:
|
|||
return Intersect_2();
|
||||
}
|
||||
|
||||
Do_intersect_2
|
||||
do_intersect_2_object() const
|
||||
{ return Do_intersect_2();}
|
||||
|
||||
Construct_projected_point_2 construct_projected_point_2_object() const
|
||||
{ return Construct_projected_point_2();}
|
||||
|
||||
Construct_circle_2 construct_circle_2_object() const
|
||||
{ return Construct_circle_2();}
|
||||
|
||||
Construct_point_2 construct_point_2_object() const
|
||||
{ return Construct_point_2();}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue