diff --git a/.gitattributes b/.gitattributes index 7aefc7dc17a..8f46b7bd4d4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3036,7 +3036,7 @@ Principal_component_analysis/examples/Principal_component_analysis/linear_least_ Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_2.cpp -text Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp -text Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp -text -Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedrons_3.cpp -text +Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedra_3.cpp -text Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_2.cpp -text Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp -text Principal_component_analysis/include/CGAL/PCA_tags.h -text diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp index bc8d4d5832e..9d7edc4d08f 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp @@ -14,21 +14,28 @@ typedef K::Iso_cuboid_3 Iso_cuboid_3; int main() { - std::list Iso_cuboids; - Iso_cuboids.push_back(Iso_cuboid_3(Point_3(0.0,0.0,0.0),Point_3(1.0,1.0,1.0))); - Iso_cuboids.push_back(Iso_cuboid_3(Point_3(1.0,1.0,1.0),Point_3(6.0,6.0,6.0))); + std::list cuboids; + cuboids.push_back(Iso_cuboid_3(Point_3(0.0,0.0,0.0),Point_3(1.0,1.0,1.0))); + cuboids.push_back(Iso_cuboid_3(Point_3(1.0,1.0,1.0),Point_3(6.0,6.0,6.0))); Line_3 line; - linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_3_tag()); - Plane_3 plane; - linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_3_tag()); + + // fit volume + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),line,CGAL::PCA_dimension_3_tag()); + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,CGAL::PCA_dimension_3_tag()); + // fit faces + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),line,CGAL::PCA_dimension_2_tag()); + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,CGAL::PCA_dimension_2_tag()); - //Use only faces. - linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_2_tag()); + // fit edges + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),line,CGAL::PCA_dimension_1_tag()); + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,CGAL::PCA_dimension_1_tag()); - linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_2_tag()); + // fit vertices + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),line,CGAL::PCA_dimension_0_tag()); + linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,CGAL::PCA_dimension_0_tag()); return 0; } diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedra_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedra_3.cpp new file mode 100644 index 00000000000..617a2d79cdb --- /dev/null +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedra_3.cpp @@ -0,0 +1,36 @@ +// Example program for the linear_least_square_fitting function +// on a set of tetrahedra in 3D + +#include +#include +#include + +typedef double FT; +typedef CGAL::Cartesian K; +typedef K::Line_3 Line_3; +typedef K::Plane_3 Plane_3; +typedef K::Point_3 Point_3; +typedef K::Tetrahedron_3 Tetrahedron_3; + +int main(void) +{ + Point a( 0.0,0.0,0.0); + Point b( 1.0,0.0,0.0); + Point c(-1.0,0.0,0.0); + Point d( 0.0,1.0,1.0); + Point e( 0.0,0.0,0.0); + + std::list tetrahedra; + tetrahedra.push_back(Tetrahedron_3(a,b,c,d)); + tetrahedra.push_back(Tetrahedron_3(a,b,c,e)); + + // fit a line + Line_3 line; + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),line,CGAL::PCA_dimension_3_tag()); + + // fit a plane + Plane_3 plane; + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),plane,CGAL::PCA_dimension_3_tag()); + + return 0; +} diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedrons_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedrons_3.cpp deleted file mode 100644 index f5509294e7f..00000000000 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_tetrahedrons_3.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Example program for the linear_least_square_fitting function on set of tetrahedrons in 3D - -#include -#include - -#include - -typedef double FT; -typedef CGAL::Cartesian K; -typedef K::Line_3 Line_3; -typedef K::Plane_3 Plane_3; -typedef K::Point_3 Point_3; -typedef K::Tetrahedron_3 Tetrahedron_3; - -int main() -{ - std::list tetrahedrons; - tetrahedrons.push_back(Tetrahedron_3(Point_3(0.0,0.0,0.0),Point_3(1.0,0.0,0.0),Point_3(0.0,1.0,0.0),Point_3(0.0,0.0,1.0))); - tetrahedrons.push_back(Tetrahedron_3(Point_3(0.0,0.0,0.0),Point_3(-1.0,0.0,0.0),Point_3(0.0,-1.0,0.0),Point_3(0.0,0.0,1.0))); - - Line_3 line; - linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,CGAL::PCA_dimension_3_tag()); - - Plane_3 plane; - linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,CGAL::PCA_dimension_3_tag()); - - return 0; -} diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp index 26428483c40..a32e4e29a4e 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp @@ -10,9 +10,9 @@ typedef CGAL::Cartesian K; typedef K::Line_3 Line_3; typedef K::Plane_3 Plane_3; typedef K::Point_3 Point_3; -typedef K::Triangle_3 Triangle_3; +typedef K::Triangle_3 Triangle_3; -int main() +int main(void) { std::list triangles; triangles.push_back(Triangle_3(Point_3(1.0,0.0,0.0),Point_3(0.0,1.0,0.0),Point_3(0.0,0.0,0.0))); diff --git a/Principal_component_analysis/include/CGAL/PCA_tags.h b/Principal_component_analysis/include/CGAL/PCA_tags.h index a7d095143cd..18803240fab 100644 --- a/Principal_component_analysis/include/CGAL/PCA_tags.h +++ b/Principal_component_analysis/include/CGAL/PCA_tags.h @@ -30,22 +30,10 @@ CGAL_BEGIN_NAMESPACE //::between these different types of the same geometry //:::::::::::::::::::::::::::::::::::::::::::::::::::::: -// Fully filled geometry object, such as disks in 2d and balls in 3d -struct PCA_dimension_3_tag {}; - -// Empty geometry objects, such as triangles in 2d and hollow cubes with just the planar facets in 3d -struct PCA_dimension_2_tag {}; - -// Only relevant for 3d objects, outlines of 3d geometry objects formed by just lines joing appropriate vetrices, such as outline of a cuboid. -struct PCA_dimension_1_tag {}; - -// For the vertices of objects. struct PCA_dimension_0_tag {}; - - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::: -// Struct to denote dimension compile time decisions -//:::::::::::::::::::::::::::::::::::::::::::::::::::::: +struct PCA_dimension_1_tag {}; +struct PCA_dimension_2_tag {}; +struct PCA_dimension_3_tag {}; /* diff --git a/Principal_component_analysis/include/CGAL/PCA_util.h b/Principal_component_analysis/include/CGAL/PCA_util.h index 7141ac4aa59..5587f5d4b90 100644 --- a/Principal_component_analysis/include/CGAL/PCA_util.h +++ b/Principal_component_analysis/include/CGAL/PCA_util.h @@ -32,16 +32,16 @@ namespace CGALi { template typename CGAL::Linear_algebraCd::Matrix init_matrix(const int n, - typename K::FT entries[]) + typename K::FT entries[]) { CGAL_assertion(n > 1); // dimension > 1 typedef typename CGAL::Linear_algebraCd::Matrix Matrix; - Matrix m(n); - int i,j; + Matrix m(n); + int i,j; for(i = 0; i < n; i++) for(j = 0; j < n; j++) - m[i][j] = entries[i*n+j]; + m[i][j] = entries[i*n+j]; return m; } // end initialization of matrix @@ -56,7 +56,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Point_3*, // used for indirection - const CGAL::PCA_dimension_0_tag& tag) + const CGAL::PCA_dimension_0_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -93,7 +93,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& k, // kernel const typename K::Triangle_3*,// used for indirection - const CGAL::PCA_dimension_2_tag& tag) + const CGAL::PCA_dimension_2_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -112,7 +112,7 @@ assemble_covariance_matrix_3(InputIterator first, // assemble 2nd order moment about the origin. FT temp[9] = {1.0/12.0, 1.0/24.0, 1.0/24.0, - 1.0/24.0, 1.0/12.0, 1.0/24.0, + 1.0/24.0, 1.0/12.0, 1.0/24.0, 1.0/24.0, 1.0/24.0, 1.0/12.0}; Matrix moment = init_matrix(3,temp); @@ -125,9 +125,8 @@ assemble_covariance_matrix_3(InputIterator first, const Triangle& t = *it; // defined for convenience. - // FT example = CGAL::to_double(t[0].x()); FT delta[9] = {t[0].x(), t[1].x(), t[2].x(), - t[0].y(), t[1].y(), t[2].y(), + t[0].y(), t[1].y(), t[2].y(), t[0].z(), t[1].z(), t[2].z()}; Matrix transformation = init_matrix(3,delta); FT area = std::sqrt(t.squared_area()); @@ -170,7 +169,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Iso_cuboid_3*,// used for indirection - const CGAL::PCA_dimension_3_tag& tag) + const CGAL::PCA_dimension_3_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -189,7 +188,7 @@ assemble_covariance_matrix_3(InputIterator first, // assemble 2nd order moment about the origin. FT temp[9] = {1.0/3.0, 1.0/4.0, 1.0/4.0, - 1.0/4.0, 1.0/3.0, 1.0/4.0, + 1.0/4.0, 1.0/3.0, 1.0/4.0, 1.0/4.0, 1.0/4.0, 1.0/3.0}; Matrix moment = init_matrix(3,temp); @@ -207,7 +206,7 @@ assemble_covariance_matrix_3(InputIterator first, FT y0 = t[0].y(); FT z0 = t[0].z(); FT delta[9] = {t[1].x()-x0, t[3].x()-x0, t[5].x()-x0, - t[1].y()-y0, t[3].y()-y0, t[5].y()-y0, + t[1].y()-y0, t[3].y()-y0, t[5].y()-y0, t[1].z()-z0, t[3].z()-z0, t[5].z()-z0}; Matrix transformation = init_matrix(3,delta); FT volume = t.volume(); @@ -255,12 +254,12 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Iso_cuboid_3*,// used for indirection - const CGAL::PCA_dimension_2_tag& tag) + const CGAL::PCA_dimension_2_tag& tag) { - typedef typename K::FT FT; - typedef typename K::Point_3 Point; - typedef typename K::Vector_3 Vector; - typedef typename K::Iso_cuboid_3 Iso_cuboid; + typedef typename K::FT FT; + typedef typename K::Point_3 Point; + typedef typename K::Vector_3 Vector; + typedef typename K::Iso_cuboid_3 Iso_cuboid; typedef typename CGAL::Linear_algebraCd LA; typedef typename LA::Matrix Matrix; @@ -274,7 +273,7 @@ assemble_covariance_matrix_3(InputIterator first, // assemble 2nd order moment about the origin. FT temp[9] = {7.0/3.0, 1.5, 1.5, - 1.5, 7.0/3.0, 1.5, + 1.5, 7.0/3.0, 1.5, 1.5, 1.5, 7.0/3.0}; Matrix moment = init_matrix(3,temp); @@ -292,18 +291,18 @@ assemble_covariance_matrix_3(InputIterator first, FT y0 = t[0].y(); FT z0 = t[0].z(); FT delta[9] = {t[1].x()-x0, t[3].x()-x0, t[5].x()-x0, - t[1].y()-y0, t[3].y()-y0, t[5].y()-y0, + t[1].y()-y0, t[3].y()-y0, t[5].y()-y0, t[1].z()-z0, t[3].z()-z0, t[5].z()-z0}; Matrix transformation = init_matrix(3,delta); FT area = pow(delta[0]*delta[0] + delta[3]*delta[3] + - delta[6]*delta[6],1/3.0)*pow(delta[1]*delta[1] + - delta[4]*delta[4] + delta[7]*delta[7],1/3.0)*2 + - pow(delta[0]*delta[0] + delta[3]*delta[3] + - delta[6]*delta[6],1/3.0)*pow(delta[2]*delta[2] + - delta[5]*delta[5] + delta[8]*delta[8],1/3.0)*2 + - pow(delta[1]*delta[1] + delta[4]*delta[4] + - delta[7]*delta[7],1/3.0)*pow(delta[2]*delta[2] + - delta[5]*delta[5] + delta[8]*delta[8],1/3.0)*2; + delta[6]*delta[6],1/3.0)*pow(delta[1]*delta[1] + + delta[4]*delta[4] + delta[7]*delta[7],1/3.0)*2 + + pow(delta[0]*delta[0] + delta[3]*delta[3] + + delta[6]*delta[6],1/3.0)*pow(delta[2]*delta[2] + + delta[5]*delta[5] + delta[8]*delta[8],1/3.0)*2 + + pow(delta[1]*delta[1] + delta[4]*delta[4] + + delta[7]*delta[7],1/3.0)*pow(delta[2]*delta[2] + + delta[5]*delta[5] + delta[8]*delta[8],1/3.0)*2; CGAL_assertion(area != 0.0); // Find the 2nd order moment for the cuboid wrt to the origin by an affine transformation. @@ -348,7 +347,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Sphere_3*,// used for indirection - const CGAL::PCA_dimension_3_tag& tag) + const CGAL::PCA_dimension_3_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -366,9 +365,9 @@ assemble_covariance_matrix_3(InputIterator first, FT mass = 0.0; // assemble 2nd order moment about the origin. - FT temp[9] = {4.0/15.0, 0.0, 0.0, - 0.0, 4.0/15.0, 0.0, - 0.0, 0.0, 4.0/15.0}; + FT temp[9] = {4.0/15.0, 0.0, 0.0, + 0.0, 4.0/15.0, 0.0, + 0.0, 0.0, 4.0/15.0}; Matrix moment = init_matrix(3,temp); for(InputIterator it = first; @@ -380,10 +379,9 @@ assemble_covariance_matrix_3(InputIterator first, const Sphere& t = *it; // defined for convenience. - // FT example = CGAL::to_double(t[0].x()); FT radius = std::sqrt(t.squared_radius()); FT delta[9] = {radius, 0.0, 0.0, - 0.0, radius, 0.0, + 0.0, radius, 0.0, 0.0, 0.0, radius}; Matrix transformation = init_matrix(3,delta); FT volume = 4/3.0 * radius*t.squared_radius(); @@ -430,7 +428,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Sphere_3*,// used for indirection - const CGAL::PCA_dimension_2_tag& tag) + const CGAL::PCA_dimension_2_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -449,7 +447,7 @@ assemble_covariance_matrix_3(InputIterator first, // assemble 2nd order moment about the origin. FT temp[9] = {4.0/3.0, 0.0, 0.0, - 0.0, 4.0/3.0, 0.0, + 0.0, 4.0/3.0, 0.0, 0.0, 0.0, 4.0/3.0}; Matrix moment = init_matrix(3,temp); @@ -464,9 +462,9 @@ assemble_covariance_matrix_3(InputIterator first, // defined for convenience. // FT example = CGAL::to_double(t[0].x()); FT radius = std::sqrt(t.squared_radius()); - FT delta[9] = {radius, 0.0, 0.0, - 0.0, radius, 0.0, - 0.0, 0.0, radius}; + FT delta[9] = {radius, 0.0, 0.0, + 0.0, radius, 0.0, + 0.0, 0.0, radius}; Matrix transformation = init_matrix(3,delta); FT area = 4 * t.squared_radius(); CGAL_assertion(area != 0.0); @@ -513,7 +511,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Tetrahedron_3*,// used for indirection - const CGAL::PCA_dimension_3_tag& tag) + const CGAL::PCA_dimension_3_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -532,8 +530,8 @@ assemble_covariance_matrix_3(InputIterator first, // assemble 2nd order moment about the origin. FT temp[9] = {1.0/60.0, 1.0/120.0, 1.0/120.0, - 1.0/120.0, 1.0/60.0, 1.0/120.0, - 1.0/120.0, 1.0/120.0, 1.0/60.0}; + 1.0/120.0, 1.0/60.0, 1.0/120.0, + 1.0/120.0, 1.0/120.0, 1.0/60.0}; Matrix moment = init_matrix(3,temp); for(InputIterator it = first; @@ -545,13 +543,12 @@ assemble_covariance_matrix_3(InputIterator first, const Tetrahedron& t = *it; // defined for convenience. - // FT example = CGAL::to_double(t[0].x()); FT x0 = t[0].x(); FT y0 = t[0].y(); FT z0 = t[0].z(); FT delta[9] = {t[1].x()-x0, t[2].x()-x0, t[3].x()-x0, - t[1].y()-y0, t[2].y()-y0, t[3].y()-y0, + t[1].y()-y0, t[2].y()-y0, t[3].y()-y0, t[1].z()-z0, t[2].z()-z0, t[3].z()-z0}; Matrix transformation = init_matrix(3,delta); FT volume = t.volume(); @@ -599,7 +596,7 @@ assemble_covariance_matrix_3(InputIterator first, const typename K::Point_3& c, // centroid const K& , // kernel const typename K::Segment_3*,// used for indirection - const CGAL::PCA_dimension_1_tag& tag) + const CGAL::PCA_dimension_1_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -618,7 +615,7 @@ assemble_covariance_matrix_3(InputIterator first, // assemble 2nd order moment about the origin. FT temp[9] = {1.0, 0.5, 0.0, - 0.5, 1.0, 0.0, + 0.5, 1.0, 0.0, 0.0, 0.0, 0.0}; Matrix moment = 1.0/3.0 * init_matrix(3,temp); @@ -633,7 +630,7 @@ assemble_covariance_matrix_3(InputIterator first, // defined for convenience. // FT example = CGAL::to_double(t[0].x()); FT delta[9] = {t[0].x(), t[1].x(), 0.0, - t[0].y(), t[1].y(), 0.0, + t[0].y(), t[1].y(), 0.0, t[0].z(), t[1].z(), 1.0}; Matrix transformation = init_matrix(3,delta); FT length = std::sqrt(t.squared_length()); @@ -719,7 +716,7 @@ typename K::FT fitting_line_3(const typename K::FT covariance[6], // covariance matrix const typename K::Point_3& c, // centroid typename K::Line_3& line, // best fit line - const K& ) // kernel + const K&) // kernel { typedef typename K::FT FT; typedef typename K::Point_3 Point; diff --git a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_3.h b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_3.h index fc1b5db3b35..093059dd2c3 100644 --- a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_3.h +++ b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_3.h @@ -23,12 +23,14 @@ #include #include #include + #include -#include -#include #include #include +#include +#include #include + #include #include @@ -46,9 +48,9 @@ inline typename Kernel::FT linear_least_squares_fitting_3(InputIterator first, InputIterator beyond, - typename Object& object, // plane or line (result) - typename Kernel::Point_3& centroid, - const Tag& tag, + typename Object& object, // plane or line + typename Kernel::Point_3& centroid, + const Tag& tag, // dimension tag, ranges from 0 to 3 const Kernel& kernel) { typedef typename std::iterator_traits::value_type Value_type; @@ -56,7 +58,6 @@ linear_least_squares_fitting_3(InputIterator first, centroid, (Value_type*) NULL, kernel, tag); } - // deduces kernel from value type of input iterator template < typename InputIterator, typename Object, @@ -66,16 +67,16 @@ inline typename Kernel_traits::Kernel::FT linear_least_squares_fitting_3(InputIterator first, InputIterator beyond, - Object& object, + Object& object, // plane or line Point& centroid, - const Tag& tag) + const Tag& tag) // dimension tag, ranges from 0 to 3 { typedef typename std::iterator_traits::value_type Value_type; typedef typename Kernel_traits::Kernel Kernel; return CGAL::linear_least_squares_fitting_3(first,beyond,object,centroid,tag,Kernel()); } -// does not writes centroid and deduces kernel +// deduces kernel and does not write centroid template < typename InputIterator, typename Object, typename Tag> @@ -83,108 +84,15 @@ inline typename Kernel_traits::Kernel::FT linear_least_squares_fitting_3(InputIterator first, InputIterator beyond, - Object& object, - const Tag& tag) + Object& object, // plane or line + const Tag& tag) // dimension tag, ranges from 0 to 3 { typedef typename std::iterator_traits::value_type Value_type; typedef typename Kernel_traits::Kernel Kernel; - typename Kernel::Point_3 centroid; // unused by caller + typename Kernel::Point_3 centroid; // not used by caller return CGAL::linear_least_squares_fitting_3(first,beyond,object,centroid,tag); } -// does not return the centroid, deduces kernel, and default tag -// simplest (default) call of the function -/* -template < typename InputIterator, - typename Object> -inline -typename Kernel_traits::Kernel::FT -linear_least_squares_fitting_3(InputIterator first, - InputIterator beyond, - Object& object) -{ - typedef typename std::iterator_traits::value_type Value_type; - typedef typename Kernel_traits::Kernel Kernel; - typename Kernel::Point_3 centroid; // unused by caller - return CGAL::linear_least_squares_fitting_3(first,beyond,object,centroid,(Value_type *)NULL,K()); -}*/ - -/* -template < typename InputIterator, - typename Object, typename tag > -inline -typename Kernel_traits::Kernel::FT -linear_least_squares_fitting_3(InputIterator first, - InputIterator beyond, - Object& object, - const tag& t) -{ - typedef typename std::iterator_traits::value_type Value_type; - // BOOST_STATIC_ASSERT((boost::is_same::Algebraic_category,CGAL::Field_with_sqrt_tag>::value)); - typedef typename Kernel_traits::Kernel K; - return CGAL::linear_least_squares_fitting_3(first,beyond,object,K(), t); -} - -template < typename InputIterator, - typename Object, - typename tag = typename PCA_default_dimension< typename std::iterator_traits::value_type >::Tag> -inline -typename Kernel_traits::Kernel::FT -linear_least_squares_fitting_3(InputIterator first, - InputIterator beyond, - Object& object, - const tag& t = tag()) -{ - typedef typename std::iterator_traits::value_type Value_type; - typedef typename Kernel_traits::Kernel K; - return CGAL::linear_least_squares_fitting_3(first,beyond,object,K(), t); -} - - // BOOST_STATIC_ASSERT((boost::is_same::Algebraic_category,CGAL::Field_with_sqrt_tag>::value)); - - // default tag (dimension of fitted objects, ie 1 for segments, 2 for triangles, 3 for tets, etc.) -template < typename InputIterator, - typename Object, - typename Kernel > -inline -typename Kernel::FT -linear_least_squares_fitting_3(InputIterator first, - InputIterator beyond, - typename Object& object, // plane or line - typename Kernel::Point_3& centroid, - const Kernel& kernel) -{ - typedef typename std::iterator_traits::value_type Value_type; - return CGALi::linear_least_squares_fitting_3(first, beyond, object, - centroid, (Value_type*) NULL, kernel); -} - - - -// omits centroid -template < typename InputIterator, - typename Object, - typename Kernel, - typename Tag > -inline -typename Kernel::FT -linear_least_squares_fitting_3(InputIterator first, - InputIterator beyond, - Object& object, - const Kernel& kernel, - const Tag& tag) -{ - typedef typename std::iterator_traits::value_type Value_type; - typename Kernel::Point_3 centroid; // unused by caller - return CGALi::linear_least_squares_fitting_3(first, beyond, object, - centroid, (Value_type*) NULL, kernel, tag); -} - - - - */ - - CGAL_END_NAMESPACE #endif // CGAL_LINEAR_LEAST_SQUARES_FITTING_3_H diff --git a/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp b/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp index a6f68ec0290..5b078c4d080 100644 --- a/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp +++ b/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp @@ -6,22 +6,31 @@ #include typedef double FT; -typedef CGAL::Cartesian K; -typedef K::Line_3 Line_3; -typedef K::Plane_3 Plane_3; -typedef K::Point_3 Point_3; -typedef K::Sphere_3 Sphere_3; +typedef CGAL::Cartesian Kernel; +typedef Kernel::Line_3 Line_3; +typedef Kernel::Plane_3 Plane_3; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Sphere_3 Sphere_3; -int main() +int main(void) { - std::list spheres; - spheres.push_back(Sphere_3(Point_3(0.0,0.0,0.0),9)); - spheres.push_back(Sphere_3(Point_3(0.0,10.0,0.0),25)); + // centers + Point c1(0.0,0.0,0.0); + Point c2(1.0,1.0,1.0); + // radii + FT sqr1 = 0.1; + FT sqr2 = 0.5; + + // add two spheres + std::list spheres; + spheres.push_back(Sphere_3(c1,sqr1)); + spheres.push_back(Sphere_3(c2,sqr2)); + + Kernel k; + Point_3 c; Line_3 line; Plane_3 plane; - K k; - Point_3 c; linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,CGAL::PCA_dimension_3_tag()); linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,CGAL::PCA_dimension_2_tag());