mirror of https://github.com/CGAL/cgal
fix bbox computation and factorize
This commit is contained in:
parent
278600266d
commit
e6c7c34783
|
|
@ -122,12 +122,34 @@ public:
|
|||
//Intersections
|
||||
class Do_intersect
|
||||
{
|
||||
// TODO: possible optimization using Protector
|
||||
typedef Simple_cartesian<Interval_nt<> > Approximate_kernel;
|
||||
typedef Cartesian_converter<Kernel, Approximate_kernel> C2F;
|
||||
|
||||
|
||||
const AABB_do_intersect_transform_traits<BaseTraits, Kernel>& m_traits;
|
||||
C2F c2f;
|
||||
C2F m_c2f;
|
||||
|
||||
Bounding_box
|
||||
compute_transformed_bbox(const Bounding_box& bbox) const
|
||||
{
|
||||
Approximate_kernel::Aff_transformation_3 af = m_c2f( m_traits.transformation() );
|
||||
|
||||
//TODO reuse the conversions
|
||||
typename Approximate_kernel::Point_3 ps[8];
|
||||
ps[0] = af( m_c2f( Point_3(bbox.min(0), bbox.min(1), bbox.min(2)) ) );
|
||||
ps[1] = af( m_c2f( Point_3(bbox.min(0), bbox.min(1), bbox.max(2)) ) );
|
||||
ps[2] = af( m_c2f( Point_3(bbox.min(0), bbox.max(1), bbox.min(2)) ) );
|
||||
ps[3] = af( m_c2f( Point_3(bbox.min(0), bbox.max(1), bbox.max(2)) ) );
|
||||
|
||||
ps[4] = af( m_c2f( Point_3(bbox.max(0), bbox.min(1), bbox.min(2)) ) );
|
||||
ps[5] = af( m_c2f( Point_3(bbox.max(0), bbox.min(1), bbox.max(2)) ) );
|
||||
ps[6] = af( m_c2f( Point_3(bbox.max(0), bbox.max(1), bbox.min(2)) ) );
|
||||
ps[7] = af( m_c2f( Point_3(bbox.max(0), bbox.max(1), bbox.max(2)) ) );
|
||||
|
||||
return bbox_3(ps, ps+8);
|
||||
}
|
||||
|
||||
public:
|
||||
Do_intersect(const AABB_do_intersect_transform_traits<BaseTraits, Kernel>& traits)
|
||||
:m_traits(traits)
|
||||
|
|
@ -136,39 +158,10 @@ public:
|
|||
template<typename Query>
|
||||
bool operator()(const Query& q, const Bounding_box& bbox) const
|
||||
{
|
||||
Point_3 ps[8];
|
||||
ps[0] = Point_3(bbox.min(0), bbox.min(1), bbox.min(2));
|
||||
ps[1] = Point_3(bbox.min(0), bbox.min(1), bbox.max(2));
|
||||
ps[2] = Point_3(bbox.min(0), bbox.max(1), bbox.min(2));
|
||||
ps[3] = Point_3(bbox.min(0), bbox.max(1), bbox.max(2));
|
||||
|
||||
ps[4] = Point_3(bbox.max(0), bbox.min(1), bbox.min(2));
|
||||
ps[5] = Point_3(bbox.max(0), bbox.min(1), bbox.max(2));
|
||||
ps[6] = Point_3(bbox.max(0), bbox.max(1), bbox.min(2));
|
||||
ps[7] = Point_3(bbox.max(0), bbox.max(1), bbox.max(2));
|
||||
|
||||
for(int i=0; i<8; ++i)
|
||||
{
|
||||
ps[i] = m_traits.transformation().transform(ps[i]);
|
||||
}
|
||||
|
||||
|
||||
Bounding_box temp_box;
|
||||
for(int i=0; i<8; ++i)
|
||||
temp_box += ps[i].bbox();
|
||||
typename Approximate_kernel::Point_3 app_min,
|
||||
app_max;
|
||||
Point_3 tmin(temp_box.xmin(), temp_box.ymin(), temp_box.zmin()),
|
||||
tmax(temp_box.xmax(), temp_box.ymax(), temp_box.zmax());
|
||||
app_min=c2f(tmin);
|
||||
app_max = c2f(tmax);
|
||||
Bounding_box transfo_box(to_double(app_min.x().inf()), to_double(app_min.y().inf()), to_double(app_min.z().inf()),
|
||||
to_double(app_max.x().sup()), to_double(app_max.y().sup()), to_double(app_max.z().sup()));
|
||||
|
||||
bool res = CGAL::do_intersect(c2f(q), transfo_box);
|
||||
return res;
|
||||
// TODO use base_traits
|
||||
return CGAL::do_intersect(q, compute_transformed_bbox(bbox));
|
||||
}
|
||||
|
||||
|
||||
template<typename Query>
|
||||
bool operator()(const Query& q, const Primitive& pr) const
|
||||
{
|
||||
|
|
@ -186,30 +179,7 @@ public:
|
|||
template<typename AABBTraits>
|
||||
bool operator()(const CGAL::AABB_tree<AABBTraits>& other_tree, const Bounding_box& bbox) const
|
||||
{
|
||||
Point_3 ps[8];
|
||||
ps[0] = Point_3(bbox.min(0), bbox.min(1), bbox.min(2));
|
||||
ps[1] = Point_3(bbox.min(0), bbox.min(1), bbox.max(2));
|
||||
ps[2] = Point_3(bbox.min(0), bbox.max(1), bbox.min(2));
|
||||
ps[3] = Point_3(bbox.min(0), bbox.max(1), bbox.max(2));
|
||||
|
||||
ps[4] = Point_3(bbox.max(0), bbox.min(1), bbox.min(2));
|
||||
ps[5] = Point_3(bbox.max(0), bbox.min(1), bbox.max(2));
|
||||
ps[6] = Point_3(bbox.max(0), bbox.max(1), bbox.min(2));
|
||||
ps[7] = Point_3(bbox.max(0), bbox.max(1), bbox.max(2));
|
||||
|
||||
for(int i=0; i<8; ++i)
|
||||
{
|
||||
ps[i] = m_traits.transformation().transform(ps[i]);
|
||||
}
|
||||
|
||||
Bounding_box temp_box;
|
||||
for(int i=0; i<8; ++i)
|
||||
temp_box += ps[i].bbox();
|
||||
Point_3 p_min(temp_box.xmin(), temp_box.ymin(), temp_box.zmin());
|
||||
Point_3 p_max(temp_box.xmax(), temp_box.ymax(), temp_box.zmax());
|
||||
Bounding_box transfo_box(to_double(p_min.x()), to_double(p_min.y()), to_double(p_min.z()),
|
||||
to_double(p_max.x()), to_double(p_max.y()), to_double(p_max.z()));
|
||||
return other_tree.do_intersect(transfo_box);
|
||||
return other_tree.do_intersect(compute_transformed_bbox(bbox));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue