Make the intersection point static; Move the normal construction higher up

This commit is contained in:
Andreas Fabri 2020-10-03 20:23:42 +01:00
parent 6752a9c238
commit b101674749
3 changed files with 60 additions and 20 deletions

View File

@ -537,6 +537,7 @@ struct Envelope {
is_3_triangle_cut_float_fast(const ePoint_3& tp, is_3_triangle_cut_float_fast(const ePoint_3& tp,
const ePoint_3& tq, const ePoint_3& tq,
const ePoint_3& tr, const ePoint_3& tr,
const ePoint_3& n,
const Plane& facet1, const Plane& facet1,
const Plane& facet2, const Plane& facet2,
const ePoint_3& ip const ePoint_3& ip
@ -567,12 +568,13 @@ struct Envelope {
} }
} }
#endif #endif
#if 0
Point_3 itp(CGAL::approx(tp).x().inf(), CGAL::approx(tp).y().inf(), CGAL::approx(tp).z().inf()); Point_3 itp(CGAL::approx(tp).x().inf(), CGAL::approx(tp).y().inf(), CGAL::approx(tp).z().inf());
Point_3 itq(CGAL::approx(tq).x().inf(), CGAL::approx(tq).y().inf(), CGAL::approx(tq).z().inf()); Point_3 itq(CGAL::approx(tq).x().inf(), CGAL::approx(tq).y().inf(), CGAL::approx(tq).z().inf());
Point_3 itr(CGAL::approx(tr).x().inf(), CGAL::approx(tr).y().inf(), CGAL::approx(tr).z().inf()); Point_3 itr(CGAL::approx(tr).x().inf(), CGAL::approx(tr).y().inf(), CGAL::approx(tr).z().inf());
Point_3 in = itp + CGAL::cross_product((itp - itq), (itp - itr)); Point_3 in = itp + CGAL::cross_product((itp - itq), (itp - itr));
ePoint_3 n(in.x(),in.y(),in.z()); ePoint_3 n(in.x(),in.y(),in.z());
#endif
// return 2; // return 2;
// todo: what do we test here with n ? // todo: what do we test here with n ?
// todo : do this not with Epeck // todo : do this not with Epeck
@ -607,14 +609,16 @@ struct Envelope {
is_3_triangle_cut(const ePoint_3& tp, is_3_triangle_cut(const ePoint_3& tp,
const ePoint_3& tq, const ePoint_3& tq,
const ePoint_3& tr, const ePoint_3& tr,
const ePoint_3& n,
const ePoint_3& ip) const const ePoint_3& ip) const
{ {
#if 0
Point_3 itp(CGAL::approx(tp).x().inf(), CGAL::approx(tp).y().inf(), CGAL::approx(tp).z().inf()); Point_3 itp(CGAL::approx(tp).x().inf(), CGAL::approx(tp).y().inf(), CGAL::approx(tp).z().inf());
Point_3 itq(CGAL::approx(tq).x().inf(), CGAL::approx(tq).y().inf(), CGAL::approx(tq).z().inf()); Point_3 itq(CGAL::approx(tq).x().inf(), CGAL::approx(tq).y().inf(), CGAL::approx(tq).z().inf());
Point_3 itr(CGAL::approx(tr).x().inf(), CGAL::approx(tr).y().inf(), CGAL::approx(tr).z().inf()); Point_3 itr(CGAL::approx(tr).x().inf(), CGAL::approx(tr).y().inf(), CGAL::approx(tr).z().inf());
Point_3 in = itp + CGAL::cross_product((itp - itq), (itp - itr)); Point_3 in = itp + CGAL::cross_product((itp - itq), (itp - itr));
ePoint_3 n(in.x(),in.y(),in.z()); ePoint_3 n(in.x(),in.y(),in.z());
#endif
//ePoint_3 n = tp + CGAL::cross_product((tp - tq), (tp - tr)); //ePoint_3 n = tp + CGAL::cross_product((tp - tq), (tp - tr));
#if 0 #if 0
if (Predicates::orient_3d(n, tp, q, tr) == 0) if (Predicates::orient_3d(n, tp, q, tr) == 0)
@ -666,6 +670,7 @@ struct Envelope {
int int
is_triangle_cut_envelope_polyhedra(const int &cindex,//the triangle is not degenerated is_triangle_cut_envelope_polyhedra(const int &cindex,//the triangle is not degenerated
const ePoint_3 &tri0, const ePoint_3 &tri1, const ePoint_3 &tri2, const ePoint_3 &tri0, const ePoint_3 &tri1, const ePoint_3 &tri2,
const ePoint_3 &n,
std::vector<int> &cid) const std::vector<int> &cid) const
{ {
const Prism& prism = halfspace[cindex]; const Prism& prism = halfspace[cindex];
@ -836,6 +841,7 @@ struct Envelope {
boost::optional<ePoint_3> ipp = CGAL::intersection_point(tri_eplane, prism[cutp[i]].eplane, prism[cutp[j]].eplane); boost::optional<ePoint_3> ipp = CGAL::intersection_point(tri_eplane, prism[cutp[i]].eplane, prism[cutp[j]].eplane);
if(ipp){ if(ipp){
inter = is_3_triangle_cut_float_fast(tri0, tri1, tri2, inter = is_3_triangle_cut_float_fast(tri0, tri1, tri2,
n,
prism[cutp[i]], prism[cutp[i]],
prism[cutp[j]], prism[cutp[j]],
*ipp); *ipp);
@ -1246,17 +1252,24 @@ struct Envelope {
bool bool
triangle_out_of_envelope(const std::array<Point_3,3>& triangle, triangle_out_of_envelope(const Point_3 & t0,
const Point_3 & t1,
const Point_3 & t2,
const std::vector<unsigned int> &prismindex) const const std::vector<unsigned int> &prismindex) const
{ {
if (prismindex.size() == 0) if (prismindex.size() == 0)
{ {
return true; return true;
} }
std::array<ePoint_3,3> etriangle = { ePoint_3(triangle[0].x(),triangle[0].y(),triangle[0].z()), std::array<Point_3,3> triangle = { t0, t1, t2 };
ePoint_3(triangle[1].x(),triangle[1].y(),triangle[1].z()), std::array<ePoint_3,3> etriangle = { ePoint_3(t0.x(), t0.y(), t0.z()),
ePoint_3(triangle[2].x(),triangle[2].y(),triangle[2].z()) }; ePoint_3(t1.x(), t1.y(), t1.z()),
ePoint_3(t2.x(), t2.y(), t2.z()) };
Point_3 in = t0 + CGAL::cross_product((t0 - t1), (t0 - t2));
ePoint_3 n(in.x(), in.y(), in.z());
int jump1, jump2; int jump1, jump2;
static const std::array<std::array<int, 2>, 3> triseg = { static const std::array<std::array<int, 2>, 3> triseg = {
@ -1354,7 +1367,9 @@ struct Envelope {
std::vector<int> cidl; cidl.reserve(8); std::vector<int> cidl; cidl.reserve(8);
for (int i = 0; i < prismindex.size(); i++) { for (int i = 0; i < prismindex.size(); i++) {
tti = is_triangle_cut_envelope_polyhedra(prismindex[i], tti = is_triangle_cut_envelope_polyhedra(prismindex[i],
etriangle[0], etriangle[1], etriangle[2], cidl); etriangle[0], etriangle[1], etriangle[2],
n,
cidl);
if (tti == 2) { if (tti == 2) {
return false;//totally inside of this polyhedron return false;//totally inside of this polyhedron
@ -1521,7 +1536,7 @@ struct Envelope {
const ePoint_3& ip = *op; const ePoint_3& ip = *op;
cut = is_3_triangle_cut(etriangle[0], etriangle[1], etriangle[2], ip); cut = is_3_triangle_cut(etriangle[0], etriangle[1], etriangle[2], n, ip);
if (!cut){ if (!cut){
#ifdef TRACE #ifdef TRACE
@ -1858,8 +1873,7 @@ struct Envelope {
prism_to_off(prismindex[i], "prism"); prism_to_off(prismindex[i], "prism");
} }
#endif #endif
std::array<Point_3,3> triangle = { t0, t1, t2 }; if(triangle_out_of_envelope(t0, t1, t2, prismindex)){
if(triangle_out_of_envelope(triangle, prismindex)){
return false; return false;
} }
return true; return true;

View File

@ -245,6 +245,10 @@ public:
Lazy_rep (A&& a) Lazy_rep (A&& a)
: at(std::forward<A>(a)), et(nullptr){} : at(std::forward<A>(a)), et(nullptr){}
template<class A>
Lazy_rep (int count, A&& a)
: Rep(count), at(std::forward<A>(a)), et(nullptr){}
template<class A, class E> template<class A, class E>
Lazy_rep (A&& a, E&& e) Lazy_rep (A&& a, E&& e)
: at(std::forward<A>(a)), et(new ET(std::forward<E>(e))) {} : at(std::forward<A>(a)), et(new ET(std::forward<E>(e))) {}
@ -362,7 +366,9 @@ class Lazy_rep_optional_n :
static_assert(sizeof...(L)>0, "Use Lazy_rep_0 instead"); static_assert(sizeof...(L)>0, "Use Lazy_rep_0 instead");
template <class Ei, class Ai, class E2Ai, class Ki> friend class Lazy_kernel_base; template <class Ei, class Ai, class E2Ai, class Ki> friend class Lazy_kernel_base;
mutable std::tuple<L...> l; // L...l; is not yet allowed. mutable std::tuple<L...> l; // L...l; is not yet allowed.
const EC& ec() const { return *this; } const EC& ec() const { return *this; }
template<std::size_t...I> template<std::size_t...I>
void update_exact_helper(std::index_sequence<I...>) const { void update_exact_helper(std::index_sequence<I...>) const {
this->et = new ET( * ec()( CGAL::exact( std::get<I>(l) ) ... ) ); this->et = new ET( * ec()( CGAL::exact( std::get<I>(l) ) ... ) );
@ -370,15 +376,27 @@ class Lazy_rep_optional_n :
l = std::tuple<L...>{}; l = std::tuple<L...>{};
} }
public: public:
Lazy_rep_optional_n()
{}
void update_exact() const { void update_exact() const {
update_exact_helper(std::make_index_sequence<sizeof...(L)>{}); update_exact_helper(std::make_index_sequence<sizeof...(L)>{});
} }
template<class...LL> template<class...LL>
Lazy_rep_optional_n(const AT& a, const EC& ec, LL&&...ll) : Lazy_rep_optional_n(const AT& a, const EC& ec, LL&&...ll) :
Lazy_rep<AT, ET, E2A>(a), EC(ec), l(std::forward<LL>(ll)...) Lazy_rep<AT, ET, E2A>(a), EC(ec), l(std::forward<LL>(ll)...)
{ {
this->set_depth((std::max)({ -1, (int)CGAL::depth(ll)...}) + 1); this->set_depth((std::max)({ -1, (int)CGAL::depth(ll)...}) + 1);
} }
template<class...LL>
Lazy_rep_optional_n(int count, const AT& a, const EC& ec, LL&&...ll) :
Lazy_rep<AT, ET, E2A>(count, a), EC(ec), l(std::forward<LL>(ll)...)
{
this->set_depth((std::max)({ -1, (int)CGAL::depth(ll)...}) + 1);
}
#ifdef CGAL_LAZY_KERNEL_DEBUG #ifdef CGAL_LAZY_KERNEL_DEBUG
private: private:
template<std::size_t...I> template<std::size_t...I>
@ -393,6 +411,7 @@ class Lazy_rep_optional_n :
expander{0,(CGAL::print_dag(std::get<I>(l), os, level+1),0)...}; expander{0,(CGAL::print_dag(std::get<I>(l), os, level+1),0)...};
} }
} }
public: public:
void print_dag(std::ostream& os, int level) const { void print_dag(std::ostream& os, int level) const {
print_dag_helper(os, level, std::make_index_sequence<sizeof...L>{}); print_dag_helper(os, level, std::make_index_sequence<sizeof...L>{});
@ -874,9 +893,11 @@ struct Lazy_construction_optional
} }
// Now we have to construct a rep for a lazy point with the three lazy planes. // Now we have to construct a rep for a lazy point with the three lazy planes.
typedef Lazy_rep_optional_n<typename AK::Point_3, typename EK::Point_3, AC, EC, E2A, L1, L1, L1> LazyPointRep; typedef Lazy_rep_optional_n<typename AK::Point_3, typename EK::Point_3, AC, EC, E2A, L1, L1, L1> LazyPointRep;
static LazyPointRep rep;
const typename AK::Point_3 ap = *oap; const typename AK::Point_3 ap = *oap;
LazyPointRep *rep = new LazyPointRep(ap, ec, l1, l2, l3); rep = LazyPointRep(2,ap, ec, l1, l2, l3);
typename LK::Point_3 lp(rep); typename LK::Point_3 lp(&rep);
return boost::make_optional(lp); return boost::make_optional(lp);
@ -900,6 +921,7 @@ struct Lazy_construction_optional
template <typename L1, typename L2> template <typename L1, typename L2>
result_type operator()(const L1& l1, const L2& l2) const result_type operator()(const L1& l1, const L2& l2) const
{ {
typedef Lazy_rep_optional_n<typename AK::Point_3, typename EK::Point_3, AC, EC, E2A, L1, L2> LazyPointRep;
Protect_FPU_rounding<Protection> P; Protect_FPU_rounding<Protection> P;
try { try {
@ -907,8 +929,8 @@ struct Lazy_construction_optional
if(oap == boost::none){ if(oap == boost::none){
return boost::none; return boost::none;
} }
// Now we have to construct a rep for a lazy point with the three lazy planes. // Now we have to construct a rep for a lazy point with the line and the plane.
typedef Lazy_rep_optional_n<typename AK::Point_3, typename EK::Point_3, AC, EC, E2A, L1, L2> LazyPointRep;
const typename AK::Point_3 ap = *oap; const typename AK::Point_3 ap = *oap;
LazyPointRep *rep = new LazyPointRep(ap, ec, l1, l2); LazyPointRep *rep = new LazyPointRep(ap, ec, l1, l2);
typename LK::Point_3 lp(rep); typename LK::Point_3 lp(rep);

View File

@ -26,13 +26,17 @@ namespace CGAL {
class Rep class Rep
{ {
friend class Handle; friend class Handle;
protected: protected:
Rep() { count = 1; } Rep() { count = 1; }
Rep(int count)
: count(count)
{}
virtual ~Rep() {} virtual ~Rep() {}
int count; int count;
}; };
class Handle class Handle
{ {
public: public: