diff --git a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_cuboids_3.h b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_cuboids_3.h index 5bd44fc5251..7cd07626f54 100644 --- a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_cuboids_3.h +++ b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_cuboids_3.h @@ -166,6 +166,10 @@ linear_least_squares_fitting_3(InputIterator first, points.push_back(t[1]); points.push_back(t[2]); points.push_back(t[3]); + points.push_back(t[4]); + points.push_back(t[5]); + points.push_back(t[6]); + points.push_back(t[7]); } // compute fitting plane @@ -307,6 +311,10 @@ linear_least_squares_fitting_3(InputIterator first, points.push_back(t[1]); points.push_back(t[2]); points.push_back(t[3]); + points.push_back(t[4]); + points.push_back(t[5]); + points.push_back(t[6]); + points.push_back(t[7]); } // compute fitting line diff --git a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_points_3.h b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_points_3.h index cf8b8bd0c64..c51826f373b 100644 --- a/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_points_3.h +++ b/Principal_component_analysis/include/CGAL/linear_least_squares_fitting_points_3.h @@ -43,7 +43,7 @@ linear_least_squares_fitting_3(InputIterator first, typename K::Point_3& c, // centroid const typename K::Point_3*, // used for indirection const K& k, // kernel - const CGAL::PCA_dimension_0_tag& tag = CGAL::PCA_dimension_0_tag()) + const CGAL::PCA_dimension_0_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; @@ -77,7 +77,7 @@ linear_least_squares_fitting_3(InputIterator first, typename K::Point_3& c, // centroid const typename K::Point_3*, // used for indirection const K& k, // kernel - const CGAL::PCA_dimension_0_tag& tag = CGAL::PCA_dimension_0_tag) + const CGAL::PCA_dimension_0_tag& tag) { typedef typename K::FT FT; typedef typename K::Point_3 Point; diff --git a/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp b/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp index 88df77fde58..a22b14a153c 100644 --- a/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp +++ b/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp @@ -22,7 +22,6 @@ int main() cuboids.push_back(Iso_cuboid(a,b)); cuboids.push_back(Iso_cuboid(a,c)); - Kernel kernel; Line line; Plane plane; Point centroid; diff --git a/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp b/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp index 81e81ed5a42..7ba222d224d 100644 --- a/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp +++ b/Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_segments_3.cpp @@ -1,27 +1,27 @@ -// test for the linear_least_square_fitting() functions. - - -#include -#include -#include -#include - -#include -#include -#include -#define THRESHOLD 0.001 -// types - -typedef CGAL::Cartesian Kernel; -typedef Kernel::FT FT; - -typedef Kernel::Line_3 Line; -typedef Kernel::Plane_3 Plane; -typedef Kernel::Point_3 Point; -typedef Kernel::Segment_3 Segment; -typedef Kernel::Vector_3 Vector; -typedef Kernel::Direction_3 Direction; - +// test for the linear_least_square_fitting() functions. + + +#include +#include +#include +#include + +#include +#include +#include +#define THRESHOLD 0.001 +// types + +typedef CGAL::Cartesian Kernel; +typedef Kernel::FT FT; + +typedef Kernel::Line_3 Line; +typedef Kernel::Plane_3 Plane; +typedef Kernel::Point_3 Point; +typedef Kernel::Segment_3 Segment; +typedef Kernel::Vector_3 Vector; +typedef Kernel::Direction_3 Direction; + FT fit_set(std::list& segments, Plane& plane, Line& line) @@ -42,197 +42,197 @@ FT fit_set(std::list& segments, return quality; } - - -// case with only one segment in container -// the fitting line must be the same -void test_1() -{ - std::list segments; - segments.push_back(Segment(Point(3.0,3.0,3.0),Point(1.0,1.0,1.0))); - - // fit a line - // call all versions of the function - std::cout << "Test 1" << std::endl; - std::cout << "fit 3D line..."; - Line line; - Plane plane; - Point centroid; - - FT quality = fit_set(segments,plane,line); - std::cout << "done, quality: " << quality << std::endl; - - if(!line.has_on(Point(3.0,3.0,3.0)) || - !line.has_on(Point(1.0,1.0,1.0))) - { - std::cout << "failure" << std::endl; - std::cout << "line: " << line << std::endl; - // exit(1); // failure - } -} - - -// case with two segments cutting the one segment in two parts in -// container the fitting line must be the same -void test_2() -{ - std::cout<<"Test 2"< segments; - segments.push_back(Segment(Point(1.0,1.0,1.0),Point(1.5,1.5,1.5))); - segments.push_back(Segment(Point(2.0,2.0,2.0),Point(1.5,1.5,1.5))); - - // fit a line - std::cout << "fit 3D line..."; - Line line; - Plane plane; - Point centroid; - FT quality = fit_set(segments,plane,line); - std::cout << "done, quality: " << quality << std::endl; - - if(!line.has_on(Point(2.0,2.0,2.0)) || - !line.has_on(Point(1.0,1.0,1.0))) - { - std::cout << "failure" << std::endl; - std::cout << "line: " << line << std::endl; - // exit(1); // failure - } -} - -// case with four segments cutting the one segment in four parts in -// container the fitting line must be the same -void test_3() -{ - std::cout<<"Test 3"< segments; - segments.push_back(Segment(Point(2.00,2.00,2.00),Point(1.75,1.75,1.75))); - segments.push_back(Segment(Point(1.75,1.75,1.75),Point(1.50,1.50,1.50))); - segments.push_back(Segment(Point(1.50,1.50,1.50),Point(1.25,1.25,1.25))); - segments.push_back(Segment(Point(1.25,1.25,1.25),Point(1.00,1.00,1.00))); - - // fit a line - // call all versions of the function - std::cout << "fit 3D line..."; - Line line; - Plane plane; - Point centroid; - FT quality = fit_set(segments,plane,line); - std::cout.precision(20); - std::cout << "done, quality: " << quality << std::endl; - - if(!line.has_on(Point(2.0,2.0,2.0)) || - !line.has_on(Point(1.0,1.0,1.0))) - { - std::cout << "failure" << std::endl; - std::cout << "line: " << line << std::endl; - // exit(1); // failure - } -} - - -// case with a segments in container against just the two end points -// the fitting line must be the same -void test_4() -{ - std::cout<<"Test 4"< segments; - segments.push_back(Segment(p,q)); - - - // fit a line - // call all versions of the function - std::cout << "fit 3D line to segment..."; - Line line; - Plane plane; - Point centroid; - FT quality = fit_set(segments,plane,line); - std::cout << "done, quality: " << quality << std::endl; - - std::list points; - points.push_back(p); - points.push_back(q); - - // fit a line - // call all versions of the function - std::cout << "fit 3D line to end points..."; - Line line1; - Point centroid1; - FT quality1; - quality1 = linear_least_squares_fitting_3(points.begin(),points.end(),line1,CGAL::PCA_dimension_0_tag()); - quality1 = linear_least_squares_fitting_3(points.begin(),points.end(),line1,centroid1,CGAL::PCA_dimension_0_tag()); - std::cout << "done, quality: " << quality1 << std::endl; - - if(!(line.has_on(line1.point(0)) && (double)line.to_vector().y()/line.to_vector().x() - - (double)line1.to_vector().y()/line1.to_vector().x() <= THRESHOLD && - (double)line.to_vector().z()/line.to_vector().x() - - (double)line1.to_vector().z()/line1.to_vector().x() <= THRESHOLD)) - { - std::cout << "failure" << std::endl; - // exit(1); // failure - } -} - - -// Plane fitting -// case with only one segment in container -// the fitting plane must be the same -void test_5() -{ - std::vector segments; - segments.push_back(Segment(Point(3.0,3.0,3.0),Point(1.0,1.0,1.0))); - - - // fit a plane - // call all versions of the function - std::cout<<"Test 5"< segments; - segments.push_back(Segment(Point(3.0,3.0,3.0),Point(1.0,1.0,1.0))); - - // call all versions of the function - std::cout<<"Test 6"< segments; + segments.push_back(Segment(Point(3.0,3.0,3.0),Point(1.0,1.0,1.0))); + + // fit a line + // call all versions of the function + std::cout << "Test 1" << std::endl; + std::cout << "fit 3D line..."; + Line line; + Plane plane; + Point centroid; + + FT quality = fit_set(segments,plane,line); + std::cout << "done, quality: " << quality << std::endl; + + if(!line.has_on(Point(3.0,3.0,3.0)) || + !line.has_on(Point(1.0,1.0,1.0))) + { + std::cout << "failure" << std::endl; + std::cout << "line: " << line << std::endl; + // exit(1); // failure + } +} + + +// case with two segments cutting the one segment in two parts in +// container the fitting line must be the same +void test_2() +{ + std::cout<<"Test 2"< segments; + segments.push_back(Segment(Point(1.0,1.0,1.0),Point(1.5,1.5,1.5))); + segments.push_back(Segment(Point(2.0,2.0,2.0),Point(1.5,1.5,1.5))); + + // fit a line + std::cout << "fit 3D line..."; + Line line; + Plane plane; + Point centroid; + FT quality = fit_set(segments,plane,line); + std::cout << "done, quality: " << quality << std::endl; + + if(!line.has_on(Point(2.0,2.0,2.0)) || + !line.has_on(Point(1.0,1.0,1.0))) + { + std::cout << "failure" << std::endl; + std::cout << "line: " << line << std::endl; + // exit(1); // failure + } +} + +// case with four segments cutting the one segment in four parts in +// container the fitting line must be the same +void test_3() +{ + std::cout<<"Test 3"< segments; + segments.push_back(Segment(Point(2.00,2.00,2.00),Point(1.75,1.75,1.75))); + segments.push_back(Segment(Point(1.75,1.75,1.75),Point(1.50,1.50,1.50))); + segments.push_back(Segment(Point(1.50,1.50,1.50),Point(1.25,1.25,1.25))); + segments.push_back(Segment(Point(1.25,1.25,1.25),Point(1.00,1.00,1.00))); + + // fit a line + // call all versions of the function + std::cout << "fit 3D line..."; + Line line; + Plane plane; + Point centroid; + FT quality = fit_set(segments,plane,line); + std::cout.precision(20); + std::cout << "done, quality: " << quality << std::endl; + + if(!line.has_on(Point(2.0,2.0,2.0)) || + !line.has_on(Point(1.0,1.0,1.0))) + { + std::cout << "failure" << std::endl; + std::cout << "line: " << line << std::endl; + // exit(1); // failure + } +} + + +// case with a segments in container against just the two end points +// the fitting line must be the same +void test_4() +{ + std::cout<<"Test 4"< segments; + segments.push_back(Segment(p,q)); + + + // fit a line + // call all versions of the function + std::cout << "fit 3D line to segment..."; + Line line; + Plane plane; + Point centroid; + FT quality = fit_set(segments,plane,line); + std::cout << "done, quality: " << quality << std::endl; + + std::list points; + points.push_back(p); + points.push_back(q); + + // fit a line + // call all versions of the function + std::cout << "fit 3D line to end points..."; + Line line1; + Point centroid1; + FT quality1; + quality1 = linear_least_squares_fitting_3(points.begin(),points.end(),line1,CGAL::PCA_dimension_0_tag()); + quality1 = linear_least_squares_fitting_3(points.begin(),points.end(),line1,centroid1,CGAL::PCA_dimension_0_tag()); + std::cout << "done, quality: " << quality1 << std::endl; + + if(!(line.has_on(line1.point(0)) && (double)line.to_vector().y()/line.to_vector().x() - + (double)line1.to_vector().y()/line1.to_vector().x() <= THRESHOLD && + (double)line.to_vector().z()/line.to_vector().x() - + (double)line1.to_vector().z()/line1.to_vector().x() <= THRESHOLD)) + { + std::cout << "failure" << std::endl; + // exit(1); // failure + } +} + + +// Plane fitting +// case with only one segment in container +// the fitting plane must be the same +void test_5() +{ + std::vector segments; + segments.push_back(Segment(Point(3.0,3.0,3.0),Point(1.0,1.0,1.0))); + + + // fit a plane + // call all versions of the function + std::cout<<"Test 5"< segments; + segments.push_back(Segment(Point(3.0,3.0,3.0),Point(1.0,1.0,1.0))); + + // call all versions of the function + std::cout<<"Test 6"<