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.
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;
}
@ -43,7 +43,7 @@ protected:
// Computes squared Euclidean distance from a set of points.
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++) {
const FT sd = (this->point(indices[i])
- m_point_on_primitive) * m_normal;

View File

@ -123,7 +123,7 @@ int main()
const Point_with_normal &p = *(points.begin() + (*index_it));
// 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.
index_it++;

View File

@ -60,6 +60,8 @@ namespace CGAL {
///
struct Circle_2 {};
///
struct Vector_2 {};
///
struct Plane_3 {};
///
struct Point_2 {};
@ -137,6 +139,14 @@ namespace CGAL {
{ 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
{
Vector_3 operator()(Null_vector const&) { return NULL_VECTOR; }
@ -145,13 +155,28 @@ namespace CGAL {
};
Construct_vector_3 construct_vector_3_object() const
{ 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
{
Sphere_3 operator()(Point_3 const&, FT) { return Sphere_3(); }
};
Construct_sphere_3 construct_sphere_3_object() const
{ 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
{
@ -167,6 +192,22 @@ namespace CGAL {
Construct_point_on_3 construct_point_on_3_object() const
{ 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
{
FT operator()(Point_3 const&) const { return 0; }
@ -174,7 +215,7 @@ namespace CGAL {
};
Compute_x_3 compute_x_3_object() const
{ return Compute_x_3(); }
struct Compute_y_3
{
FT operator()(Point_3 const&) const { return 0; }
@ -191,11 +232,16 @@ namespace CGAL {
Compute_z_3 compute_z_3_object() const
{ return Compute_z_3(); }
struct Compute_squared_length_3
{ FT operator()(Vector_3 const&) const { return 0; } };
Compute_squared_length_3 compute_squared_length_3_object() const
{ 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
{
@ -230,11 +276,27 @@ namespace CGAL {
{ Point_3 operator()(Sphere_3 const&) const { return Point_3(); } };
Construct_center_3 construct_center_3_object() const
{ return Construct_center_3(); }
struct Compute_squared_radius_3
{ FT operator()(Sphere_3 const&) const { return 0; } };
Compute_squared_radius_3 compute_squared_radius_3_object() const
{ 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
{ FT operator()(Point_3 const&, Point_3 const&) const { return 0; } };

View File

@ -63,6 +63,8 @@ namespace CGAL {
///
typedef typename Gt::Point_2 Point_2;
///
typedef typename Gt::Vector_2 Vector_2;
///
typedef InputRange Input_range;
///
typedef InputPointMap Point_map;
@ -73,15 +75,23 @@ namespace CGAL {
///
Efficient_RANSAC_traits(const Gt& gt = Gt())
: m_gt(gt) {}
typedef typename Gt::Construct_point_3 Construct_point_3;
Construct_point_3 construct_point_3_object() const
{ return m_gt.construct_point_3_object(); }
typedef typename Gt::Construct_vector_3 Construct_vector_3;
Construct_vector_3 construct_vector_3_object() const
{ 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;
Construct_sphere_3 construct_sphere_3_object() const
{ return m_gt.construct_sphere_3_object(); }
@ -89,11 +99,23 @@ namespace CGAL {
typedef typename Gt::Construct_line_3 Construct_line_3;
Construct_line_3 construct_line_3_object() const
{ 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;
Construct_point_on_3 construct_point_on_3_object() const
{ 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;
Compute_x_3 compute_x_3_object() const
{ return m_gt.compute_x_3_object(); }
@ -105,10 +127,14 @@ namespace CGAL {
typedef typename Gt::Compute_z_3 Compute_z_3;
Compute_z_3 compute_z_3_object() const
{ return m_gt.compute_z_3_object(); }
typedef typename Gt::Compute_squared_length_3 Compute_squared_length_3;
Compute_squared_length_3 compute_squared_length_3_object() const
{ 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;
Construct_scaled_vector_3 construct_scaled_vector_3_object() const
@ -129,15 +155,23 @@ namespace CGAL {
typedef typename Gt::Construct_cross_product_vector_3 Construct_cross_product_vector_3;
Construct_cross_product_vector_3 construct_cross_product_vector_3_object() const
{ return m_gt.construct_cross_product_vector_3_object(); }
typedef typename Gt::Construct_center_3 Construct_center_3;
Construct_center_3 construct_center_3_object() const
{ 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;
Compute_squared_radius_3 compute_squared_radius_3_object() const
{ 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:
Gt m_gt;
};

View File

@ -48,12 +48,17 @@ namespace CGAL {
///< property map to access the location of an input point.
typedef typename Traits::Normal_map Normal_map;
///< property map to access the unoriented normal of an input point.
typedef typename Traits::FT FT; ///< number type.
typedef typename Traits::Point_3 Point_3; ///< point type.
typedef typename Traits::Vector_3 Vector_3; ///< vector type.
typedef typename Traits::FT FT;
///< number 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;
///< 2D point type used during construction.
typedef typename Traits::Circle_2 Circle;
///< 2D point type used during construction.
typedef typename Traits::Circle_2 Circle_2;
///< cricle type used during construction.
/// \endcond
@ -132,12 +137,25 @@ namespace CGAL {
// ------------------------------------------------------------------------
// Utilities
// ------------------------------------------------------------------------
Sphere_3 constr_sphere(const Point_3& c, FT r) const
{ return m_traits.construct_sphere_3_object()(c, r); }
Point_3 sph_center(const Sphere_3& s) const
{ return m_traits.construct_center_3_object()(s); }
FT sqradius(const Sphere_3& s) const
{ return m_traits.compute_squared_radius_3_object()(s); }
FT get_x_2(const Vector_2& v) const { return m_traits.compute_x_2_object()(v); }
FT get_y_2(const Vector_2& v) const { return m_traits.compute_y_2_object()(v); }
FT get_x_2(const Point_2& p) const { return m_traits.compute_x_2_object()(p); }
FT get_y_2(const Point_2& p) const { return m_traits.compute_y_2_object()(p); }
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) {
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
const FT a01 = this->cross_pdct(n[0], n[1]) * n[2];
const FT b01 = 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 b0 = this->cross_pdct(p[3] - p[1], n[0]) * n[3];
const FT a1 = this->cross_pdct(p[0] - p[2], n[1]) * n[2];
const FT b1 = this->cross_pdct(p[0] - p[3], n[1]) * n[3];
const FT a = this->cross_pdct(p[0] - p[2], p[1] - p[0]) * n[2];
const FT b = this->cross_pdct(p[0] - p[3], p[1] - p[0]) * n[3];
const FT a01 = this->scalar_pdct(this->cross_pdct(n[0], n[1]), n[2]);
const FT b01 = this->scalar_pdct(this->cross_pdct(n[0], n[1]), n[3]);
const FT a0 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[1], p[2]), n[0]), n[2]);
const FT b0 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[1], p[3]), n[0]), n[3]);
const FT a1 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[2], p[0]), n[1]), n[2]);
const FT b1 = this->scalar_pdct(this->cross_pdct(this->constr_vec(p[3], p[0]), n[1]), n[3]);
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->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);
if (div == 0)
@ -189,12 +207,12 @@ namespace CGAL {
Point_3 c1;
Vector_3 axis1;
if (is_finite(x1) && is_finite(y1)) {
c1 = p[0] + n[0] * x1;
axis1 = c1 - (p[1] + n[1] * y1);
c1 = this->transl(p[0], this->scale(n[0], x1));
axis1 = this->constr_vec(this->transl(p[1], this->scale(n[1], y1)), c1);
FT l = this->sqlen(axis1);
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);
}
}
@ -204,12 +222,12 @@ namespace CGAL {
Point_3 c2;
Vector_3 axis2;
if (is_finite(x2) && is_finite(y2)) {
c2 = p[0] + n[0] * x2;
axis2 = c2 - (p[1] + n[1] * y2);
c2 = this->transl(p[0], this->scale(n[0], x2));
axis2 = this->constr_vec(this->transl(p[1], this->scale(n[1], y2)), c2);
FT l = this->sqlen(axis2);
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);
}
}
@ -243,27 +261,27 @@ namespace CGAL {
}
// 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,
this->cross_pdct(m_axis, d));
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));
if (length == 0)
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));
if (length == 0)
return;
d = d / length;
if (CGAL::abs(d * n[i]) < this->m_normal_threshold) {
d = this->scale(d, FT(1.0) / length);
if (CGAL::abs(this->scalar_pdct(d, n[i])) < this->m_normal_threshold) {
this->m_is_valid = false;
return;
}
@ -294,12 +312,12 @@ namespace CGAL {
virtual void cos_to_normal(const std::vector<std::size_t> &indices,
std::vector<FT> &angles) const {
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,
this->cross_pdct(m_axis, d));
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));
@ -310,11 +328,11 @@ namespace CGAL {
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 = d / CGAL::sqrt(this->sqlen(d));
angles[i] = CGAL::abs(d * this->normal(indices[i]));
d = this->constr_vec((this->transl(m_center, this->scale(in_plane, m_majorRad))), this->point(indices[i]));
d = this->scale(d, FT(1.0) / CGAL::sqrt(this->sqlen(d)));
angles[i] = CGAL::abs(this->scalar_pdct(d, this->normal(indices[i])));
}
}
@ -356,26 +374,26 @@ namespace CGAL {
std::vector<Point_2> pts;
pts.resize(p.size());
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 f = this->scalar_pdct(d, d) - e * e;
if (f <= 0)
pts[i] = Point_2(e, (FT) 0);
pts[i] = this->constr_point_2(e, (FT) 0);
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)();
}
Circle c(pts[0], pts[1], pts[2]);
Circle_2 c = this->constr_circle(pts[0], pts[1], pts[2]);
minorRad = this->sqradius(c);
majorRad = this->get_y(this->sph_center(c));
center = center + this->get_x(this->sph_center(c)) * axis;
majorRad = this->get_y_2(this->circle_center(c));
center = this->transl(center, this->scale(axis, this->get_x_2(this->circle_center(c))));
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;