mirror of https://github.com/CGAL/cgal
PCA: cleanup examples and little fix
This commit is contained in:
parent
635a146e07
commit
049d70ad6f
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_2.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Circle_2> 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<Circle> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Iso_cuboid_3> 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<Iso_cuboid> 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;
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_2.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Point_2> 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<Point> 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;
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Point_3> 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<Point> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_2.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Segment_2> 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<Segment> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Segment_3> 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<Segment> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Sphere_3> 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<Sphere> 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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
||||
return 0;
|
||||
// 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());
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_2.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Triangle_2> 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<Triangle> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,27 +2,39 @@
|
|||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
typedef double FT;
|
||||
typedef CGAL::Cartesian<FT> 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<Triangle_3> 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<Triangle> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Point_2> points;
|
||||
std::list<Point> points;
|
||||
for(InputIterator it = first;
|
||||
it != beyond;
|
||||
it++)
|
||||
|
|
|
|||
Loading…
Reference in New Issue