mirror of https://github.com/CGAL/cgal
PCA: renamed example file for tetrahedra
started cleaning up the examples codes
This commit is contained in:
parent
638b292458
commit
d88923b47c
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -14,21 +14,28 @@ typedef K::Iso_cuboid_3 Iso_cuboid_3;
|
|||
|
||||
int main()
|
||||
{
|
||||
std::list<Iso_cuboid_3> 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<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)));
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
// Example program for the linear_least_square_fitting function
|
||||
// on a set of tetrahedra in 3D
|
||||
|
||||
#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::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<Tetrahedron_3> 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;
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
// Example program for the linear_least_square_fitting function on set of tetrahedrons in 3D
|
||||
|
||||
#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::Tetrahedron_3 Tetrahedron_3;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::list<Tetrahedron_3> 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;
|
||||
}
|
||||
|
|
@ -10,9 +10,9 @@ 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::Triangle_3 Triangle_3;
|
||||
|
||||
int main()
|
||||
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)));
|
||||
|
|
|
|||
|
|
@ -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 {};
|
||||
|
||||
/*
|
||||
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@ namespace CGALi {
|
|||
template <typename K>
|
||||
typename CGAL::Linear_algebraCd<typename K::FT>::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<typename K::FT>::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<K>(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<K>(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<K>(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<K>(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<FT> 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<K>(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<K>(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<K>(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<K>(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<K>(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<K>(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<K>(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<K>(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<K>(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<K>(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;
|
||||
|
|
|
|||
|
|
@ -23,12 +23,14 @@
|
|||
#include <CGAL/Object.h>
|
||||
#include <CGAL/Algebraic_structure_traits.h>
|
||||
#include <CGAL/IO/io.h>
|
||||
|
||||
#include <CGAL/linear_least_squares_fitting_points_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_segments_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_triangles_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_spheres_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_cuboids_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_segments_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_triangles_3.h>
|
||||
#include <CGAL/linear_least_squares_fitting_tetrahedra_3.h>
|
||||
|
||||
#include <CGAL/PCA_tags.h>
|
||||
|
||||
#include <iterator>
|
||||
|
|
@ -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<InputIterator>::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<Object>::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<InputIterator>::value_type Value_type;
|
||||
typedef typename Kernel_traits<Value_type>::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<Object>::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<InputIterator>::value_type Value_type;
|
||||
typedef typename Kernel_traits<Value_type>::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<Object>::Kernel::FT
|
||||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
Object& object)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type Value_type;
|
||||
typedef typename Kernel_traits<Value_type>::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<Object>::Kernel::FT
|
||||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
Object& object,
|
||||
const tag& t)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type Value_type;
|
||||
// BOOST_STATIC_ASSERT((boost::is_same<typename CGAL::Algebraic_structure_traits<Value_type>::Algebraic_category,CGAL::Field_with_sqrt_tag>::value));
|
||||
typedef typename Kernel_traits<Value_type>::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<InputIterator>::value_type >::Tag>
|
||||
inline
|
||||
typename Kernel_traits<Object>::Kernel::FT
|
||||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
Object& object,
|
||||
const tag& t = tag())
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type Value_type;
|
||||
typedef typename Kernel_traits<Value_type>::Kernel K;
|
||||
return CGAL::linear_least_squares_fitting_3(first,beyond,object,K(), t);
|
||||
}
|
||||
|
||||
// BOOST_STATIC_ASSERT((boost::is_same<typename CGAL::Algebraic_structure_traits<Value_type>::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<InputIterator>::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<InputIterator>::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
|
||||
|
|
|
|||
|
|
@ -6,22 +6,31 @@
|
|||
#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 CGAL::Cartesian<FT> 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<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));
|
||||
// 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<Sphere_3> 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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue