From 049d70ad6f2e37da9bcb59d38e1559ec6ebc33fd Mon Sep 17 00:00:00 2001 From: Pierre Alliez Date: Sat, 19 Jan 2008 19:57:18 +0000 Subject: [PATCH] PCA: cleanup examples and little fix --- ...linear_least_squares_fitting_circles_2.cpp | 30 +++++++--------- ...linear_least_squares_fitting_cuboids_3.cpp | 33 ++++++++--------- .../linear_least_squares_fitting_points_2.cpp | 19 +++++----- .../linear_least_squares_fitting_points_3.cpp | 24 +++++++------ ...inear_least_squares_fitting_segments_2.cpp | 25 ++++++------- ...inear_least_squares_fitting_segments_3.cpp | 35 +++++++++++-------- ...linear_least_squares_fitting_spheres_3.cpp | 30 ++++++++-------- ...ear_least_squares_fitting_tetrahedra_3.cpp | 21 ++++++++--- ...near_least_squares_fitting_triangles_2.cpp | 34 ++++++++++-------- ...near_least_squares_fitting_triangles_3.cpp | 34 ++++++++++++------ ...linear_least_squares_fitting_triangles_2.h | 2 +- 11 files changed, 160 insertions(+), 127 deletions(-) diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_circles_2.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_circles_2.cpp index 96233be76fe..2f3cc2ba937 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_circles_2.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_circles_2.cpp @@ -1,31 +1,27 @@ -// Example program for the linear_least_square_fitting function on a set of circles in 2D - +// Example program for linear least squares fitting of 2D circles #include #include - #include typedef double FT; typedef CGAL::Cartesian K; -typedef K::Line_2 Line_2; -typedef K::Point_2 Point_2; -typedef K::Circle_2 Circle_2; +typedef K::Line_2 Line; +typedef K::Point_2 Point; +typedef K::Circle_2 Circle; int main() { - std::list circles; - circles.push_back(Circle_2(Point_2(0.0,0.0),9)); - circles.push_back(Circle_2(Point_2(0.0,10.0),49)); - circles.push_back(Circle_2(Point_2(10.0,0.0),49)); + // generate a set of 2D circles + std::list circles; + circles.push_back(Circle(Point(1.0,2.0),16.0)); + circles.push_back(Circle(Point(3.0,4.0),25.0)); - Line_2 line; - Point_2 c; + // fit line to circles + Line line; + linear_least_squares_fitting_2(circles.begin(),circles.end(),line,CGAL::PCA_dimension_1_tag()); - // fit circles - linear_least_squares_fitting_2(circles.begin(),circles.end(),line,c,CGAL::PCA_dimension_1_tag()); - - // fit disks - linear_least_squares_fitting_2(circles.begin(),circles.end(),line,c,CGAL::PCA_dimension_2_tag()); + // fit line to disks + linear_least_squares_fitting_2(circles.begin(),circles.end(),line,CGAL::PCA_dimension_2_tag()); return 0; } 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 9d7edc4d08f..e942e9fdc42 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 @@ -1,40 +1,41 @@ -// Example program for the linear_least_square_fitting function on set of cuboids in 3D - +// Example program for linear least squares fitting of 3D cuboids #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::Iso_cuboid_3 Iso_cuboid_3; +typedef K::Line_3 Line; +typedef K::Plane_3 Plane; +typedef K::Point_3 Point; +typedef K::Iso_cuboid_3 Iso_cuboid; int main() { - 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))); + std::list cuboids; + Point a(1.0,2.0,3.0); + Point b(4.0,5.0,6.0); + Point c(7.0,8.0,9.0); + cuboids.push_back(Iso_cuboid(a,b)); + cuboids.push_back(Iso_cuboid(a,c)); - Line_3 line; - Plane_3 plane; + Line line; + Plane plane; // 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(),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(),line, CGAL::PCA_dimension_2_tag()); linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,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(),line, CGAL::PCA_dimension_1_tag()); linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,CGAL::PCA_dimension_1_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(),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_points_2.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_2.cpp index 0f4d0566e4a..9f7d83e7334 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_2.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_2.cpp @@ -1,23 +1,22 @@ -// Example program for the linear_least_square_fitting function on set of points in 2D - +// Example program for linear least squares fitting of a 2D point set #include #include - #include typedef double FT; typedef CGAL::Cartesian K; -typedef K::Line_2 Line_2; -typedef K::Point_2 Point_2; +typedef K::Line_2 Line; +typedef K::Point_2 Point; int main() { - std::list points; - points.push_back(Point_2(1.0,0.0)); - points.push_back(Point_2(2.0,0.0)); - points.push_back(Point_2(3.0,0.0)); + std::list points; + points.push_back(Point(1.0,2.0)); + points.push_back(Point(3.0,4.0)); + points.push_back(Point(5.0,6.0)); - Line_2 line; + // fit a line + Line line; linear_least_squares_fitting_2(points.begin(),points.end(),line,CGAL::PCA_dimension_0_tag()); return 0; diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_3.cpp index f2336e959c5..f356d92f0ff 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_3.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_points_3.cpp @@ -1,24 +1,28 @@ -// Example program for the linear_least_square_fitting function on set of points in 3D - +// Example program for linear least squares fitting of 3D points #include #include - #include typedef double FT; typedef CGAL::Cartesian K; -typedef K::Line_3 Line_3; -typedef K::Point_3 Point_3; +typedef K::Line_3 Line; +typedef K::Plane_3 Plane; +typedef K::Point_3 Point; int main() { - std::list points; - points.push_back(Point_3(1.0,0.0,0.0)); - points.push_back(Point_3(2.0,0.0,0.0)); - points.push_back(Point_3(3.0,0.0,0.0)); + std::list points; + points.push_back(Point(1.0,2.0,3.0)); + points.push_back(Point(4.0,5.0,6.0)); + points.push_back(Point(7.0,8.0,9.0)); - Line_3 line; + // fit a line + Line line; linear_least_squares_fitting_3(points.begin(),points.end(),line,CGAL::PCA_dimension_0_tag()); + // fit a plane + Plane plane; + linear_least_squares_fitting_3(points.begin(),points.end(),plane,CGAL::PCA_dimension_0_tag()); + return 0; } diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_2.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_2.cpp index 37d0410bb79..cd7cbd7b6b7 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_2.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_2.cpp @@ -1,25 +1,26 @@ -// Example program for the linear_least_square_fitting function on set of segments in 2D - +// Example program for linear least squares fitting of 2D segments #include #include - #include typedef double FT; typedef CGAL::Cartesian K; -typedef K::Line_2 Line_2; -typedef K::Point_2 Point_2; -typedef K::Segment_2 Segment_2; +typedef K::Line_2 Line; +typedef K::Point_2 Point; +typedef K::Segment_2 Segment; int main() { - std::list segments; - segments.push_back(Segment_2(Point_2(0.0,1.0),Point_2(-1.0,0.0))); - segments.push_back(Segment_2(Point_2(0.0,1.0),Point_2(1.0,0.0))); + Point a(1.0,2.0); + Point b(3.0,4.0); + Point c(5.0,6.0); + std::list segments; + segments.push_back(Segment(a,b)); + segments.push_back(Segment(a,c)); - Line_2 line; - Point_2 c; - linear_least_squares_fitting_2(segments.begin(),segments.end(),line,c,CGAL::PCA_dimension_1_tag()); + // fit a line + Line line; + linear_least_squares_fitting_2(segments.begin(),segments.end(),line,CGAL::PCA_dimension_1_tag()); return 0; } diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp index e74e07fb8ac..d0632e0f7da 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp @@ -1,29 +1,34 @@ -// Example program for the linear_least_square_fitting function on set of segments in 3D - +// Example program for linear least squares fitting of 3D segments #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::Segment_3 Segment_3; +typedef K::Line_3 Line; +typedef K::Plane_3 Plane; +typedef K::Point_3 Point; +typedef K::Segment_3 Segment; int main() { - std::list segments; - segments.push_back(Segment_3(Point_3(1.0,1.0,1.0),Point_3(2.0,2.0,2.0))); - segments.push_back(Segment_3(Point_3(3.0,3.0,3.0),Point_3(8.0,8.0,8.0))); + Point a(1.0,2.0,3.0); + Point b(4.0,5.0,6.0); + Point c(7.0,8.0,9.0); + std::list segments; + segments.push_back(Segment(a,b)); + segments.push_back(Segment(a,c)); - Line_3 line; - Point_3 c; - linear_least_squares_fitting_3(segments.begin(),segments.end(),line,c,CGAL::PCA_dimension_1_tag()); + Line line; + Plane plane; - Plane_3 plane; - linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,c,CGAL::PCA_dimension_1_tag()); + // fit a line and a plane to segments + linear_least_squares_fitting_3(segments.begin(),segments.end(),line, CGAL::PCA_dimension_1_tag()); + linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,CGAL::PCA_dimension_1_tag()); + + // fit a line and a plane to segment end points + linear_least_squares_fitting_3(segments.begin(),segments.end(),line, CGAL::PCA_dimension_0_tag()); + linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,CGAL::PCA_dimension_0_tag()); return 0; } diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp index b4ad1eb74c1..d70758d6c0e 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp @@ -1,32 +1,30 @@ -// Example program for the linear_least_square_fitting function on set of spheres in 3D - +// Example program for linear least squares fitting of 3D spheres #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::Sphere_3 Sphere_3; +typedef K::Line_3 Line; +typedef K::Plane_3 Plane; +typedef K::Point_3 Point; +typedef K::Sphere_3 Sphere; int main() { - 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)); + std::list spheres; + spheres.push_back(Sphere(Point(1.0,2.0,3.0),16.0)); + spheres.push_back(Sphere(Point(4.0,5.0,6.0),25.0)); - Line_3 line; - Plane_3 plane; + Line line; + Plane plane; - // fit balls (dimension 3) - linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,CGAL::PCA_dimension_3_tag()); + // fit a line and a plane to balls (dimension 3) + linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line, CGAL::PCA_dimension_3_tag()); linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,CGAL::PCA_dimension_3_tag()); - // fit spheres (dimension 2) - linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,CGAL::PCA_dimension_2_tag()); + // fit a line and a plane to spheres (dimension 2) + linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line, CGAL::PCA_dimension_2_tag()); linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,CGAL::PCA_dimension_2_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 index 12e81be05e1..b1eeb4d0544 100644 --- 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 @@ -24,13 +24,24 @@ int main(void) tetrahedra.push_back(Tetrahedron(a,b,c,d)); tetrahedra.push_back(Tetrahedron(a,b,c,e)); - // fit a line Line line; - linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),line,CGAL::PCA_dimension_3_tag()); - - // fit a plane Plane plane; + + // fit a line and a plane to tetrahedra + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),line, CGAL::PCA_dimension_3_tag()); linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),plane,CGAL::PCA_dimension_3_tag()); + + // fit a line and a plane to tetrahedron faces + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),line, CGAL::PCA_dimension_2_tag()); + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),plane,CGAL::PCA_dimension_2_tag()); - return 0; + // fit a line and a plane to tetrahedron edges + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),line, CGAL::PCA_dimension_1_tag()); + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),plane,CGAL::PCA_dimension_1_tag()); + + // fit a line and a plane to tetrahedron vertices + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),line, CGAL::PCA_dimension_0_tag()); + linear_least_squares_fitting_3(tetrahedra.begin(),tetrahedra.end(),plane,CGAL::PCA_dimension_0_tag()); + + return 0; } diff --git a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_2.cpp b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_2.cpp index 46d569084b5..8b51f6537e8 100644 --- a/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_2.cpp +++ b/Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_triangles_2.cpp @@ -1,28 +1,34 @@ -// Example program for the linear_least_square_fitting function on set of triangles in 2D - +// Example program for linear least squares fitting of 2D triangles #include #include - #include typedef double FT; typedef CGAL::Cartesian K; -typedef K::Line_2 Line_2; -typedef K::Point_2 Point_2; -typedef K::Triangle_2 Triangle_2; +typedef K::Line_2 Line; +typedef K::Point_2 Point; +typedef K::Triangle_2 Triangle; int main() { - std::list triangles; - Point_2 c; - triangles.push_back(Triangle_2(Point_2(0.0,1.0),Point_2(-1.0,0.0),Point_2(1.0,0.0))); - triangles.push_back(Triangle_2(Point_2(0.0,-1.0),Point_2(-1.0,0.0),Point_2(1.0,0.0))); + // generate 2D triangles + std::list triangles; + Point a(1.0,2.0,3.0); + Point b(4.0,5.0,6.0); + Point c(7.0,8.0,9.0); + Point d(0.1,0.2,0.3); + triangles.push_back(Triangle(a,b,c)); + triangles.push_back(Triangle(a,b,d)); - Line_2 line; - linear_least_squares_fitting_2(triangles.begin(),triangles.end(),line,c,CGAL::PCA_dimension_2_tag()); + // fit line to triangles + Line line; + linear_least_squares_fitting_2(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_2_tag()); - //Fit using the edges - linear_least_squares_fitting_2(triangles.begin(),triangles.end(),line,c,CGAL::PCA_dimension_1_tag()); + // fit line to triangle edges + linear_least_squares_fitting_2(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_1_tag()); + + // fit line to triangle vertices + linear_least_squares_fitting_2(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_0_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 a32e4e29a4e..de61e93afb7 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 @@ -2,27 +2,39 @@ #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::Triangle_3 Triangle_3; +typedef K::Line_3 Line; +typedef K::Plane_3 Plane; +typedef K::Point_3 Point; +typedef K::Triangle_3 Triangle; 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))); - 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))); + std::list triangles; + 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); + triangles.push_back(Triangle(a,b,c)); + triangles.push_back(Triangle(a,b,d)); - Line_3 line; - linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_2_tag()); + Line line; + Plane plane; - Plane_3 plane; + // fit a line and a plane to triangles + linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line, CGAL::PCA_dimension_2_tag()); linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,CGAL::PCA_dimension_2_tag()); + // fit a line and a plane to triangle edges + linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line, CGAL::PCA_dimension_2_tag()); + linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,CGAL::PCA_dimension_2_tag()); + + // fit a line and a plane to triangle vertices + linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line, CGAL::PCA_dimension_0_tag()); + linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,CGAL::PCA_dimension_0_tag()); + return 0; } diff --git a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles_2.h b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles_2.h index f1a3542e1b7..28d4cf000e6 100644 --- a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles_2.h +++ b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles_2.h @@ -203,7 +203,7 @@ linear_least_squares_fitting_2(InputIterator first, // precondition: at least one element in the container. CGAL_precondition(first != beyond); - std::list points; + std::list points; for(InputIterator it = first; it != beyond; it++)