adapted torus to traits concept

ToDo: Collinear_2 needs to be adapted
This commit is contained in:
Sven Oesau 2015-07-10 00:14:09 +02:00
parent bb2998e11f
commit 3e218a2c07
5 changed files with 173 additions and 59 deletions

View File

@ -22,7 +22,7 @@ public:
// Computes squared Euclidean distance from query point to the shape. // Computes squared Euclidean distance from query point to the shape.
virtual FT squared_distance(const Point &p) const { virtual FT squared_distance(const Point &p) const {
const FT sd = (p - m_point_on_primitive) * m_normal; const FT sd = (this->constr_vec(m_point_on_primitive, p)) * m_normal;
return sd * sd; return sd * sd;
} }
@ -43,7 +43,7 @@ protected:
// Computes squared Euclidean distance from a set of points. // Computes squared Euclidean distance from a set of points.
virtual void squared_distance(const std::vector<std::size_t> &indices, virtual void squared_distance(const std::vector<std::size_t> &indices,
std::vector<FT> &dists) { std::vector<FT> &dists) const {
for (std::size_t i = 0; i < indices.size(); i++) { for (std::size_t i = 0; i < indices.size(); i++) {
const FT sd = (this->point(indices[i]) const FT sd = (this->point(indices[i])
- m_point_on_primitive) * m_normal; - m_point_on_primitive) * m_normal;

View File

@ -123,7 +123,7 @@ int main()
const Point_with_normal &p = *(points.begin() + (*index_it)); const Point_with_normal &p = *(points.begin() + (*index_it));
// Adds Euclidean distance between point and shape. // Adds Euclidean distance between point and shape.
sum_distances += CGAL::sqrt((*it)->squared_distance(p)); sum_distances += CGAL::sqrt((*it)->squared_distance(p.first));
// Proceeds with next point. // Proceeds with next point.
index_it++; index_it++;

View File

@ -60,6 +60,8 @@ namespace CGAL {
/// ///
struct Circle_2 {}; struct Circle_2 {};
/// ///
struct Vector_2 {};
///
struct Plane_3 {}; struct Plane_3 {};
/// ///
struct Point_2 {}; struct Point_2 {};
@ -137,6 +139,14 @@ namespace CGAL {
{ return Construct_point_3(); } { return Construct_point_3(); }
struct Construct_point_2
{
Point_2 operator()() { return Point_2(); }
Point_2 operator()(FT a, FT b) { return Point_2(); }
};
Construct_point_2 construct_point_2_object() const
{ return Construct_point_2(); }
struct Construct_vector_3 struct Construct_vector_3
{ {
Vector_3 operator()(Null_vector const&) { return NULL_VECTOR; } Vector_3 operator()(Null_vector const&) { return NULL_VECTOR; }
@ -146,6 +156,14 @@ namespace CGAL {
Construct_vector_3 construct_vector_3_object() const Construct_vector_3 construct_vector_3_object() const
{ return Construct_vector_3(); } { return Construct_vector_3(); }
struct Construct_vector_2
{
Vector_2 operator()(Null_vector const&) { return NULL_VECTOR; }
Vector_2 operator()(Point_2 const&, Point_2 const&) { return Vector_2(); }
};
Construct_vector_2 construct_vector_2_object() const
{ return Construct_vector_2(); }
struct Construct_sphere_3 struct Construct_sphere_3
{ {
Sphere_3 operator()(Point_3 const&, FT) { return Sphere_3(); } Sphere_3 operator()(Point_3 const&, FT) { return Sphere_3(); }
@ -153,6 +171,13 @@ namespace CGAL {
Construct_sphere_3 construct_sphere_3_object() const Construct_sphere_3 construct_sphere_3_object() const
{ return Construct_sphere_3(); } { return Construct_sphere_3(); }
struct Construct_circle_2
{
Circle_2 operator()(Point_2 const&, Point_2 const&, Point_2 const&) { return Circle_2(); }
};
Construct_circle_2 construct_circle_2_object() const
{ return Construct_circle_2(); }
struct Construct_line_3 struct Construct_line_3
{ {
Line_3 operator()(Point_3 const&, Vector_3 const&) { return Line_3(); } Line_3 operator()(Point_3 const&, Vector_3 const&) { return Line_3(); }
@ -167,6 +192,22 @@ namespace CGAL {
Construct_point_on_3 construct_point_on_3_object() const Construct_point_on_3 construct_point_on_3_object() const
{ return Construct_point_on_3(); } { return Construct_point_on_3(); }
struct Compute_x_2
{
FT operator()(Point_2 const&) const { return 0; }
FT operator()(Vector_2 const&) const { return 0; }
};
Compute_x_2 compute_x_2_object() const
{ return Compute_x_2(); }
struct Compute_y_2
{
FT operator()(Point_2 const&) const { return 0; }
FT operator()(Vector_2 const&) const { return 0; }
};
Compute_y_2 compute_y_2_object() const
{ return Compute_y_2(); }
struct Compute_x_3 struct Compute_x_3
{ {
FT operator()(Point_3 const&) const { return 0; } FT operator()(Point_3 const&) const { return 0; }
@ -197,6 +238,11 @@ namespace CGAL {
Compute_squared_length_3 compute_squared_length_3_object() const Compute_squared_length_3 compute_squared_length_3_object() const
{ return Compute_squared_length_3(); } { return Compute_squared_length_3(); }
struct Compute_squared_length_2
{ FT operator()(Vector_2 const&) const { return 0; } };
Compute_squared_length_2 compute_squared_length_2_object() const
{ return Compute_squared_length_2(); }
struct Construct_scaled_vector_3 struct Construct_scaled_vector_3
{ {
Vector_3 operator()(Vector_3 const&, FT) { return Vector_3(); } Vector_3 operator()(Vector_3 const&, FT) { return Vector_3(); }
@ -236,6 +282,22 @@ namespace CGAL {
Compute_squared_radius_3 compute_squared_radius_3_object() const Compute_squared_radius_3 compute_squared_radius_3_object() const
{ return Compute_squared_radius_3(); } { return Compute_squared_radius_3(); }
struct Compute_squared_radius_2
{ FT operator()(Circle_2 const&) const { return 0; } };
Compute_squared_radius_2 compute_squared_radius_2_object() const
{ return Compute_squared_radius_2(); }
struct Construct_center_2
{ Point_2 operator()(Circle_2 const&) const { return Point_2(); } };
Construct_center_2 construct_center_2_object() const
{ return Construct_center_2(); }
/*struct Collinear_2
{ result_type operator()(const Point_2& p, const Point_2& q, const Point_2& r) const
{ return false; } };
Collinear_2 construct_collinear_2_object() const
{ return Collinear_2(); }*/
/*struct Compute_squared_distance_3 /*struct Compute_squared_distance_3
{ FT operator()(Point_3 const&, Point_3 const&) const { return 0; } }; { FT operator()(Point_3 const&, Point_3 const&) const { return 0; } };
Compute_squared_distance_3 compute_squared_distance_3_object() const Compute_squared_distance_3 compute_squared_distance_3_object() const

View File

@ -63,6 +63,8 @@ namespace CGAL {
/// ///
typedef typename Gt::Point_2 Point_2; typedef typename Gt::Point_2 Point_2;
/// ///
typedef typename Gt::Vector_2 Vector_2;
///
typedef InputRange Input_range; typedef InputRange Input_range;
/// ///
typedef InputPointMap Point_map; typedef InputPointMap Point_map;
@ -82,6 +84,14 @@ namespace CGAL {
Construct_vector_3 construct_vector_3_object() const Construct_vector_3 construct_vector_3_object() const
{ return m_gt.construct_vector_3_object(); } { return m_gt.construct_vector_3_object(); }
typedef typename Gt::Construct_point_2 Construct_point_2;
Construct_point_2 construct_point_2_object() const
{ return m_gt.construct_point_2_object(); }
typedef typename Gt::Construct_vector_2 Construct_vector_2;
Construct_vector_2 construct_vector_2_object() const
{ return m_gt.construct_vector_2_object(); }
typedef typename Gt::Construct_sphere_3 Construct_sphere_3; typedef typename Gt::Construct_sphere_3 Construct_sphere_3;
Construct_sphere_3 construct_sphere_3_object() const Construct_sphere_3 construct_sphere_3_object() const
{ return m_gt.construct_sphere_3_object(); } { return m_gt.construct_sphere_3_object(); }
@ -90,10 +100,22 @@ namespace CGAL {
Construct_line_3 construct_line_3_object() const Construct_line_3 construct_line_3_object() const
{ return m_gt.construct_line_3_object(); } { return m_gt.construct_line_3_object(); }
typedef typename Gt::Construct_circle_2 Construct_circle_2;
Construct_circle_2 construct_circle_2_object() const
{ return m_gt.construct_circle_2_object(); }
typedef typename Gt::Construct_point_on_3 Construct_point_on_3; typedef typename Gt::Construct_point_on_3 Construct_point_on_3;
Construct_point_on_3 construct_point_on_3_object() const Construct_point_on_3 construct_point_on_3_object() const
{ return m_gt.construct_point_on_3_object(); } { return m_gt.construct_point_on_3_object(); }
typedef typename Gt::Compute_x_2 Compute_x_2;
Compute_x_2 compute_x_2_object() const
{ return m_gt.compute_x_2_object(); }
typedef typename Gt::Compute_y_2 Compute_y_2;
Compute_y_2 compute_y_2_object() const
{ return m_gt.compute_y_2_object(); }
typedef typename Gt::Compute_x_3 Compute_x_3; typedef typename Gt::Compute_x_3 Compute_x_3;
Compute_x_3 compute_x_3_object() const Compute_x_3 compute_x_3_object() const
{ return m_gt.compute_x_3_object(); } { return m_gt.compute_x_3_object(); }
@ -110,6 +132,10 @@ namespace CGAL {
Compute_squared_length_3 compute_squared_length_3_object() const Compute_squared_length_3 compute_squared_length_3_object() const
{ return m_gt.compute_squared_length_3_object(); } { return m_gt.compute_squared_length_3_object(); }
typedef typename Gt::Compute_squared_length_2 Compute_squared_length_2;
Compute_squared_length_2 compute_squared_length_2_object() const
{ return m_gt.compute_squared_length_2_object(); }
typedef typename Gt::Construct_scaled_vector_3 Construct_scaled_vector_3; typedef typename Gt::Construct_scaled_vector_3 Construct_scaled_vector_3;
Construct_scaled_vector_3 construct_scaled_vector_3_object() const Construct_scaled_vector_3 construct_scaled_vector_3_object() const
{ return m_gt.construct_scaled_vector_3_object(); } { return m_gt.construct_scaled_vector_3_object(); }
@ -134,10 +160,18 @@ namespace CGAL {
Construct_center_3 construct_center_3_object() const Construct_center_3 construct_center_3_object() const
{ return m_gt.construct_center_3_object(); } { return m_gt.construct_center_3_object(); }
typedef typename Gt::Construct_center_2 Construct_center_2;
Construct_center_2 construct_center_2_object() const
{ return m_gt.construct_center_2_object(); }
typedef typename Gt::Compute_squared_radius_3 Compute_squared_radius_3; typedef typename Gt::Compute_squared_radius_3 Compute_squared_radius_3;
Compute_squared_radius_3 compute_squared_radius_3_object() const Compute_squared_radius_3 compute_squared_radius_3_object() const
{ return m_gt.compute_squared_radius_3_object(); } { return m_gt.compute_squared_radius_3_object(); }
typedef typename Gt::Compute_squared_radius_2 Compute_squared_radius_2;
Compute_squared_radius_2 compute_squared_radius_2_object() const
{ return m_gt.compute_squared_radius_2_object(); }
private: private:
Gt m_gt; Gt m_gt;
}; };

View File

@ -48,12 +48,17 @@ namespace CGAL {
///< property map to access the location of an input point. ///< property map to access the location of an input point.
typedef typename Traits::Normal_map Normal_map; typedef typename Traits::Normal_map Normal_map;
///< property map to access the unoriented normal of an input point. ///< property map to access the unoriented normal of an input point.
typedef typename Traits::FT FT; ///< number type. typedef typename Traits::FT FT;
typedef typename Traits::Point_3 Point_3; ///< point type. ///< number type.
typedef typename Traits::Vector_3 Vector_3; ///< vector type. typedef typename Traits::Point_3 Point_3;
///< point type.
typedef typename Traits::Vector_3 Vector_3;
///< vector type.
typedef typename Traits::Vector_2 Vector_2;
///< 2D vector type.
typedef typename Traits::Point_2 Point_2; typedef typename Traits::Point_2 Point_2;
///< 2D point type used during construction. ///< 2D point type used during construction.
typedef typename Traits::Circle_2 Circle; typedef typename Traits::Circle_2 Circle_2;
///< cricle type used during construction. ///< cricle type used during construction.
/// \endcond /// \endcond
@ -132,12 +137,25 @@ namespace CGAL {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Utilities // Utilities
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
Sphere_3 constr_sphere(const Point_3& c, FT r) const FT get_x_2(const Vector_2& v) const { return m_traits.compute_x_2_object()(v); }
{ return m_traits.construct_sphere_3_object()(c, r); } FT get_y_2(const Vector_2& v) const { return m_traits.compute_y_2_object()(v); }
Point_3 sph_center(const Sphere_3& s) const FT get_x_2(const Point_2& p) const { return m_traits.compute_x_2_object()(p); }
{ return m_traits.construct_center_3_object()(s); } FT get_y_2(const Point_2& p) const { return m_traits.compute_y_2_object()(p); }
FT sqradius(const Sphere_3& s) const
{ return m_traits.compute_squared_radius_3_object()(s); } Circle_2 constr_circle(const Point_2& a, const Point_2& b,const Point_2& c) const
{ return m_traits.construct_circle_2_object()(a, b, c); }
Point_2 circle_center(const Circle_2& s) const
{ return m_traits.construct_center_2_object()(s); }
FT sqradius(const Circle_2& s) const
{ return m_traits.compute_squared_radius_2_object()(s); }
Point_2 constr_point_2(FT a, FT b) const
{ return m_traits.construct_point_2_object()(a, b); }
Vector_2 constr_vec_2(const Point_2 &a, const Point_2 &b) const
{ return m_traits.construct_vector_2_object()(a, b); }
FT sqlen_2(const Vector_2& v) const
{ return m_traits.compute_squared_length_2_object()(v); }
bool collinear_2(const Point_2& p, const Point_2& q, const Point_2& r) const
{ return m_traits.construct_collinear_2_object()(p, q, r); }
void create_shape(const std::vector<std::size_t> &indices) { void create_shape(const std::vector<std::size_t> &indices) {
std::vector<Point_3> p; std::vector<Point_3> p;
@ -152,14 +170,14 @@ namespace CGAL {
} }
// Implemented method from 'Geometric least-squares fitting of spheres, cylinders, cones and tori' by G. Lukacs,A.D. Marshall, R. R. Martin // Implemented method from 'Geometric least-squares fitting of spheres, cylinders, cones and tori' by G. Lukacs,A.D. Marshall, R. R. Martin
const FT a01 = this->cross_pdct(n[0], n[1]) * n[2]; const FT a01 = this->scalar_pdct(this->cross_pdct(n[0], n[1]), n[2]);
const FT b01 = this->cross_pdct(n[0], n[1]) * n[3]; const FT b01 = this->scalar_pdct(this->cross_pdct(n[0], n[1]), n[3]);
const FT a0 = this->cross_pdct(p[2] - p[1], n[0]) * n[2]; const FT a0 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[1], p[2]), n[0]), n[2]);
const FT b0 = this->cross_pdct(p[3] - p[1], n[0]) * n[3]; const FT b0 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[1], p[3]), n[0]), n[3]);
const FT a1 = this->cross_pdct(p[0] - p[2], n[1]) * n[2]; const FT a1 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[2], p[0]), n[1]), n[2]);
const FT b1 = this->cross_pdct(p[0] - p[3], n[1]) * n[3]; const FT b1 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[3], p[0]), n[1]), n[3]);
const FT a = this->cross_pdct(p[0] - p[2], p[1] - p[0]) * n[2]; const FT a = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[2], p[0]), this->constr_vec(p[0], p[1])), n[2]);
const FT b = this->cross_pdct(p[0] - p[3], p[1] - p[0]) * n[3]; const FT b = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[3], p[0]), this->constr_vec(p[0], p[1])), n[3]);
FT div = (b1 * a01 - b01 * a1); FT div = (b1 * a01 - b01 * a1);
if (div == 0) if (div == 0)
@ -189,12 +207,12 @@ namespace CGAL {
Point_3 c1; Point_3 c1;
Vector_3 axis1; Vector_3 axis1;
if (is_finite(x1) && is_finite(y1)) { if (is_finite(x1) && is_finite(y1)) {
c1 = p[0] + n[0] * x1; c1 = this->transl(p[0], this->scale(n[0], x1));
axis1 = c1 - (p[1] + n[1] * y1); axis1 = this->constr_vec(this->transl(p[1], this->scale(n[1], y1)), c1);
FT l = this->sqlen(axis1); FT l = this->sqlen(axis1);
if (l > (FT)0.00001 && l == l) { if (l > (FT)0.00001 && l == l) {
axis1 = axis1 / CGAL::sqrt(l); axis1 = this->scale(axis1, FT(1.0) / CGAL::sqrt(l));
dist1 = getCircle(c1, axis1, p, majorRad1, minorRad1); dist1 = getCircle(c1, axis1, p, majorRad1, minorRad1);
} }
} }
@ -204,12 +222,12 @@ namespace CGAL {
Point_3 c2; Point_3 c2;
Vector_3 axis2; Vector_3 axis2;
if (is_finite(x2) && is_finite(y2)) { if (is_finite(x2) && is_finite(y2)) {
c2 = p[0] + n[0] * x2; c2 = this->transl(p[0], this->scale(n[0], x2));
axis2 = c2 - (p[1] + n[1] * y2); axis2 = this->constr_vec(this->transl(p[1], this->scale(n[1], y2)), c2);
FT l = this->sqlen(axis2); FT l = this->sqlen(axis2);
if (l > (FT)0.00001 && l == l) { if (l > (FT)0.00001 && l == l) {
axis2 = axis2 / CGAL::sqrt(l); axis2 = this->scale(axis2, FT(1.0) / CGAL::sqrt(l));
dist2 = getCircle(c2, axis2, p, majorRad2, minorRad2); dist2 = getCircle(c2, axis2, p, majorRad2, minorRad2);
} }
} }
@ -243,27 +261,27 @@ namespace CGAL {
} }
// check normal deviation // check normal deviation
Vector_3 d = p[i] - m_center; Vector_3 d = this->constr_vec(m_center, p[i]);
Vector_3 in_plane = this->cross_pdct(m_axis, Vector_3 in_plane = this->cross_pdct(m_axis,
this->cross_pdct(m_axis, d)); this->cross_pdct(m_axis, d));
if (this->scalar_pdct(in_plane, d) < 0) if (this->scalar_pdct(in_plane, d) < 0)
in_plane = -in_plane; in_plane = this->scale(in_plane, FT(-1.0));
FT length = CGAL::sqrt(this->sqlen(in_plane)); FT length = CGAL::sqrt(this->sqlen(in_plane));
if (length == 0) if (length == 0)
return; return;
in_plane = in_plane / length; in_plane = this->scale(in_plane, FT(1.0) / length);
d = p[i] - (m_center + this->scalar_pdct(in_plane, m_majorRad)); d = this->constr_vec((this->transl(m_center, this->scale(in_plane, m_majorRad))), p[i]);
length = CGAL::sqrt(this->sqlen(d)); length = CGAL::sqrt(this->sqlen(d));
if (length == 0) if (length == 0)
return; return;
d = d / length; d = this->scale(d, FT(1.0) / length);
if (CGAL::abs(d * n[i]) < this->m_normal_threshold) { if (CGAL::abs(this->scalar_pdct(d, n[i])) < this->m_normal_threshold) {
this->m_is_valid = false; this->m_is_valid = false;
return; return;
} }
@ -294,12 +312,12 @@ namespace CGAL {
virtual void cos_to_normal(const std::vector<std::size_t> &indices, virtual void cos_to_normal(const std::vector<std::size_t> &indices,
std::vector<FT> &angles) const { std::vector<FT> &angles) const {
for (std::size_t i = 0;i<indices.size();i++) { for (std::size_t i = 0;i<indices.size();i++) {
Vector_3 d = this->point(indices[i]) - m_center; Vector_3 d = this->constr_vec(m_center, this->point(indices[i]));
Vector_3 in_plane = this->cross_pdct(m_axis, Vector_3 in_plane = this->cross_pdct(m_axis,
this->cross_pdct(m_axis, d)); this->cross_pdct(m_axis, d));
if (this->scalar_pdct(in_plane, d) < 0) if (this->scalar_pdct(in_plane, d) < 0)
in_plane = -in_plane; in_plane = this->scale(in_plane, FT(-1.0));
FT length = (FT) CGAL::sqrt(this->sqlen(in_plane)); FT length = (FT) CGAL::sqrt(this->sqlen(in_plane));
@ -310,11 +328,11 @@ namespace CGAL {
continue; continue;
} }
in_plane = in_plane / CGAL::sqrt(this->sqlen(in_plane)); in_plane = this->scale(in_plane,FT(1.0) / CGAL::sqrt(this->sqlen(in_plane)));
d = this->point(indices[i]) - (m_center + this->scalar_pdct(in_plane, m_majorRad)); d = this->constr_vec((this->transl(m_center, this->scale(in_plane, m_majorRad))), this->point(indices[i]));
d = d / CGAL::sqrt(this->sqlen(d)); d = this->scale(d, FT(1.0) / CGAL::sqrt(this->sqlen(d)));
angles[i] = CGAL::abs(d * this->normal(indices[i])); angles[i] = CGAL::abs(this->scalar_pdct(d, this->normal(indices[i])));
} }
} }
@ -356,26 +374,26 @@ namespace CGAL {
std::vector<Point_2> pts; std::vector<Point_2> pts;
pts.resize(p.size()); pts.resize(p.size());
for (unsigned int i = 0;i<p.size();i++) { for (unsigned int i = 0;i<p.size();i++) {
Vector_3 d = p[i] - center; Vector_3 d = this->constr_vec(center, p[i]);
FT e = this->scalar_pdct(d, axis); FT e = this->scalar_pdct(d, axis);
FT f = this->scalar_pdct(d, d) - e * e; FT f = this->scalar_pdct(d, d) - e * e;
if (f <= 0) if (f <= 0)
pts[i] = Point_2(e, (FT) 0); pts[i] = this->constr_point_2(e, (FT) 0);
else else
pts[i] = Point_2(e, CGAL::sqrt(this->scalar_pdct(d, d) - e * e)); pts[i] = this->constr_point_2(e, CGAL::sqrt(this->scalar_pdct(d, d) - e * e));
} }
if (CGAL::collinear(pts[0], pts[1], pts[2])) { if (this->collinear_2(pts[0], pts[1], pts[2])) {
return (std::numeric_limits<FT>::max)(); return (std::numeric_limits<FT>::max)();
} }
Circle c(pts[0], pts[1], pts[2]); Circle_2 c = this->constr_circle(pts[0], pts[1], pts[2]);
minorRad = this->sqradius(c); minorRad = this->sqradius(c);
majorRad = this->get_y(this->sph_center(c)); majorRad = this->get_y_2(this->circle_center(c));
center = center + this->get_x(this->sph_center(c)) * axis; center = this->transl(center, this->scale(axis, this->get_x_2(this->circle_center(c))));
return CGAL::abs( return CGAL::abs(
this->sqlen(this->constr_vec(this->sph_center(c), pts[3])) - this->sqradius(c)); this->sqlen_2(this->constr_vec_2(this->circle_center(c), pts[3])) - this->sqradius(c));
} }
Point_3 m_center; Point_3 m_center;