mirror of https://github.com/CGAL/cgal
Final Changes to PCA Package; Updated Test Suite!
A Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_circles_2.cpp A Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp A Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp A Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp A Principal_component_analysis/test/Principal_component_analysis/fitting_segments_3.cpp M Principal_component_analysis/test/Principal_component_analysis/fitting_rectangles_2.cpp A Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_tetrahedrons_3.cpp A Principal_component_analysis/test/Principal_component_analysis/fitting_triangles_2.cpp M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_tetrahedrons_3.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_spheres_3.h M Principal_component_analysis/include/CGAL/centroid.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_2.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_3.h M Principal_component_analysis/include/CGAL/util.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_circles_2.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_segments_3.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles_2.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles_3.h M Principal_component_analysis/include/CGAL/linear_least_squares_fitting_cuboids_3.h M Principal_component_analysis/examples/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp
This commit is contained in:
parent
0b797b55f1
commit
0c408aeee2
|
|
@ -2099,6 +2099,13 @@ Principal_component_analysis/include/CGAL/linear_least_squares_fitting_triangles
|
|||
Principal_component_analysis/include/CGAL/util.h -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/fitting_rectangles_2.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/fitting_segments_2.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/fitting_segments_3.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/fitting_triangles_2.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_circles_2.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_cuboids_3.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_spheres_3.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_tetrahedrons_3.cpp -text
|
||||
Principal_component_analysis/test/Principal_component_analysis/linear_least_squares_fitting_triangles_3.cpp -text
|
||||
QP_solver/doc_tex/QP_solver/PkgDescription.tex -text
|
||||
QP_solver/doc_tex/QP_solver/closest_point.eps -text svneol=unset#application/postscript
|
||||
QP_solver/doc_tex/QP_solver/closest_point.fig -text svneol=unset#application/octet-stream
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Example program for the linear_least_square_fitting function
|
||||
// Example program for the linear_least_square_fitting function on set of spheres in 3D
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
|
|
|
|||
|
|
@ -444,8 +444,9 @@ centroid(InputIterator begin,
|
|||
it++)
|
||||
{
|
||||
const Segment& s = *it;
|
||||
FT length = std::sqrt(std::abs(s.squared_length()));
|
||||
Point c = K().construct_midpoint_3_object()(s[0],s[1]);
|
||||
FT length = std::sqrt(s.squared_length());
|
||||
// Point c = K().construct_midpoint_3_object()(s[0],s[1]);
|
||||
Point c = Point((s[0][0] + s[1][0])/2.0, (s[0][1] + s[1][1])/2.0, (s[0][2] + s[1][2])/2.0);
|
||||
v = v + length * (c - ORIGIN);
|
||||
sum_lengths += length;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@ linear_least_squares_fitting_2(InputIterator first,
|
|||
// deduces the kernel from the points in container.
|
||||
template < typename InputIterator,
|
||||
typename Line,
|
||||
typename Point, typename tag>
|
||||
typename tag>
|
||||
inline
|
||||
typename Kernel_traits<Line>::Kernel::FT
|
||||
linear_least_squares_fitting_2(InputIterator first,
|
||||
InputIterator beyond,
|
||||
Line& line,
|
||||
Point& centroid,
|
||||
typename Kernel_traits<Line>::Kernel::Point_2& centroid,
|
||||
const tag& t)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type Value_type;
|
||||
|
|
|
|||
|
|
@ -108,13 +108,13 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
// deduces the kernel from the points in container.
|
||||
template < typename InputIterator,
|
||||
typename Object,
|
||||
typename Point, typename tag>
|
||||
typename tag>
|
||||
inline
|
||||
typename Kernel_traits<Object>::Kernel::FT
|
||||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
Object& object,
|
||||
Point& centroid,
|
||||
typename Kernel_traits<Object>::Kernel::Point_3& centroid,
|
||||
const tag& t)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type Value_type;
|
||||
|
|
|
|||
|
|
@ -120,9 +120,6 @@ linear_least_squares_fitting_2(InputIterator first,
|
|||
covariance[1] += mass * (-1.0 * c.x() * c.y());
|
||||
covariance[2] += mass * (-1.0 * c.y() * c.y());
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<std::endl;
|
||||
|
||||
// solve for eigenvalues and eigenvectors.
|
||||
// eigen values are sorted in descending order,
|
||||
// eigen vectors are sorted in accordance.
|
||||
|
|
@ -230,9 +227,6 @@ linear_least_squares_fitting_2(InputIterator first,
|
|||
covariance[1] += mass * (-1.0 * c.x() * c.y());
|
||||
covariance[2] += mass * (-1.0 * c.y() * c.y());
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<std::endl;
|
||||
|
||||
// solve for eigenvalues and eigenvectors.
|
||||
// eigen values are sorted in descending order,
|
||||
// eigen vectors are sorted in accordance.
|
||||
|
|
|
|||
|
|
@ -56,9 +56,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Iso_cuboid*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
// std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting plane
|
||||
return fitting_plane_3(covariance,c,plane,k);
|
||||
|
||||
|
|
@ -90,9 +87,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Iso_cuboid*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
// std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting plane
|
||||
return fitting_plane_3(covariance,c,plane,k);
|
||||
|
||||
|
|
@ -106,7 +100,7 @@ typename K::FT
|
|||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
typename K::Plane_3& plane, // best fit plane
|
||||
typename K::Segment_3& c, // centroid
|
||||
typename K::Point_3& c, // centroid
|
||||
const K& k, // kernel
|
||||
const typename K::Iso_cuboid_3*, // used for indirection
|
||||
const CGAL::PCA_dimension_1_tag& tag)
|
||||
|
|
@ -124,18 +118,18 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Iso_cuboid& t = *it;
|
||||
segments.push_back(t[0],t[1]);
|
||||
segments.push_back(t[1],t[2]);
|
||||
segments.push_back(t[2],t[3]);
|
||||
segments.push_back(t[3],t[0]);
|
||||
segments.push_back(t[4],t[5]);
|
||||
segments.push_back(t[5],t[6]);
|
||||
segments.push_back(t[6],t[7]);
|
||||
segments.push_back(t[7],t[4]);
|
||||
segments.push_back(t[5],t[0]);
|
||||
segments.push_back(t[1],t[6]);
|
||||
segments.push_back(t[2],t[7]);
|
||||
segments.push_back(t[3],t[4]);
|
||||
segments.push_back(Segment(t[0],t[1]));
|
||||
segments.push_back(Segment(t[1],t[2]));
|
||||
segments.push_back(Segment(t[2],t[3]));
|
||||
segments.push_back(Segment(t[3],t[0]));
|
||||
segments.push_back(Segment(t[4],t[5]));
|
||||
segments.push_back(Segment(t[5],t[6]));
|
||||
segments.push_back(Segment(t[6],t[7]));
|
||||
segments.push_back(Segment(t[7],t[4]));
|
||||
segments.push_back(Segment(t[5],t[0]));
|
||||
segments.push_back(Segment(t[1],t[6]));
|
||||
segments.push_back(Segment(t[2],t[7]));
|
||||
segments.push_back(Segment(t[3],t[4]));
|
||||
}
|
||||
|
||||
// compute fitting plane
|
||||
|
|
@ -233,9 +227,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
// assemble covariance matrix
|
||||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Iso_cuboid*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
// std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting line
|
||||
return fitting_line_3(covariance,c,line,k);
|
||||
|
|
@ -250,7 +241,7 @@ typename K::FT
|
|||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
typename K::Line_3& line, // best fit line
|
||||
typename K::Segment_3& c, // centroid
|
||||
typename K::Point_3& c, // centroid
|
||||
const K& k, // kernel
|
||||
const typename K::Iso_cuboid_3*, // used for indirection
|
||||
const CGAL::PCA_dimension_1_tag& tag)
|
||||
|
|
@ -268,18 +259,18 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Iso_cuboid& t = *it;
|
||||
segments.push_back(t[0],t[1]);
|
||||
segments.push_back(t[1],t[2]);
|
||||
segments.push_back(t[2],t[3]);
|
||||
segments.push_back(t[3],t[0]);
|
||||
segments.push_back(t[4],t[5]);
|
||||
segments.push_back(t[5],t[6]);
|
||||
segments.push_back(t[6],t[7]);
|
||||
segments.push_back(t[7],t[4]);
|
||||
segments.push_back(t[5],t[0]);
|
||||
segments.push_back(t[1],t[6]);
|
||||
segments.push_back(t[2],t[7]);
|
||||
segments.push_back(t[3],t[4]);
|
||||
segments.push_back(Segment(t[0],t[1]));
|
||||
segments.push_back(Segment(t[1],t[2]));
|
||||
segments.push_back(Segment(t[2],t[3]));
|
||||
segments.push_back(Segment(t[3],t[0]));
|
||||
segments.push_back(Segment(t[4],t[5]));
|
||||
segments.push_back(Segment(t[5],t[6]));
|
||||
segments.push_back(Segment(t[6],t[7]));
|
||||
segments.push_back(Segment(t[7],t[4]));
|
||||
segments.push_back(Segment(t[5],t[0]));
|
||||
segments.push_back(Segment(t[1],t[6]));
|
||||
segments.push_back(Segment(t[2],t[7]));
|
||||
segments.push_back(Segment(t[3],t[4]));
|
||||
}
|
||||
|
||||
// compute fitting line
|
||||
|
|
|
|||
|
|
@ -56,9 +56,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Segment*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting plane
|
||||
return fitting_plane_3(covariance,c,plane,k);
|
||||
|
||||
|
|
@ -123,9 +120,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Segment*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting line
|
||||
return fitting_line_3(covariance,c,line,k);
|
||||
|
||||
|
|
|
|||
|
|
@ -116,8 +116,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Sphere*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
// std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting line
|
||||
return fitting_line_3(covariance,c,line,k);
|
||||
|
|
@ -149,9 +147,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Sphere*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
// std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting line
|
||||
return fitting_line_3(covariance,c,line,k);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,9 +55,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
// assemble covariance matrix
|
||||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Tetrahedron*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting plane
|
||||
return fitting_plane_3(covariance,c,plane,k);
|
||||
|
|
@ -90,10 +87,10 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Tetrahedron& t = *it;
|
||||
triangles.push_back(t[0],t[1],t[2]);
|
||||
triangles.push_back(t[0],t[2],t[3]);
|
||||
triangles.push_back(t[0],t[3],t[1]);
|
||||
triangles.push_back(t[3],t[1],t[2]);
|
||||
triangles.push_back(Triangle(t[0],t[1],t[2]));
|
||||
triangles.push_back(Triangle(t[0],t[2],t[3]));
|
||||
triangles.push_back(Triangle(t[0],t[3],t[1]));
|
||||
triangles.push_back(Triangle(t[3],t[1],t[2]));
|
||||
}
|
||||
|
||||
// compute fitting plane
|
||||
|
|
@ -126,12 +123,12 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Tetrahedron& t = *it;
|
||||
segments.push_back(t[0],t[1]);
|
||||
segments.push_back(t[1],t[2]);
|
||||
segments.push_back(t[1],t[3]);
|
||||
segments.push_back(t[2],t[3]);
|
||||
segments.push_back(t[0],t[2]);
|
||||
segments.push_back(t[0],t[3]);
|
||||
segments.push_back(Segment(t[0],t[1]));
|
||||
segments.push_back(Segment(t[1],t[2]));
|
||||
segments.push_back(Segment(t[1],t[3]));
|
||||
segments.push_back(Segment(t[2],t[3]));
|
||||
segments.push_back(Segment(t[0],t[2]));
|
||||
segments.push_back(Segment(t[0],t[3]));
|
||||
}
|
||||
|
||||
// compute fitting plane
|
||||
|
|
@ -199,10 +196,7 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
// assemble covariance matrix
|
||||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Tetrahedron*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
|
||||
// compute fitting line
|
||||
return fitting_line_3(covariance,c,line,k);
|
||||
|
||||
|
|
@ -233,10 +227,10 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Tetrahedron& t = *it;
|
||||
triangles.push_back(t[0],t[1],t[2]);
|
||||
triangles.push_back(t[0],t[2],t[3]);
|
||||
triangles.push_back(t[0],t[3],t[1]);
|
||||
triangles.push_back(t[3],t[1],t[2]);
|
||||
triangles.push_back(Triangle(t[0],t[1],t[2]));
|
||||
triangles.push_back(Triangle(t[0],t[2],t[3]));
|
||||
triangles.push_back(Triangle(t[0],t[3],t[1]));
|
||||
triangles.push_back(Triangle(t[3],t[1],t[2]));
|
||||
}
|
||||
|
||||
// compute fitting line
|
||||
|
|
@ -269,12 +263,12 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Tetrahedron& t = *it;
|
||||
segments.push_back(t[0],t[1]);
|
||||
segments.push_back(t[1],t[2]);
|
||||
segments.push_back(t[1],t[3]);
|
||||
segments.push_back(t[2],t[3]);
|
||||
segments.push_back(t[0],t[2]);
|
||||
segments.push_back(t[0],t[3]);
|
||||
segments.push_back(Segment(t[0],t[1]));
|
||||
segments.push_back(Segment(t[1],t[2]));
|
||||
segments.push_back(Segment(t[1],t[3]));
|
||||
segments.push_back(Segment(t[2],t[3]));
|
||||
segments.push_back(Segment(t[0],t[2]));
|
||||
segments.push_back(Segment(t[0],t[3]));
|
||||
}
|
||||
|
||||
// compute fitting line
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ linear_least_squares_fitting_2(InputIterator first,
|
|||
covariance[0] += mass * (-1.0 * c.x() * c.x());
|
||||
covariance[1] += mass * (-1.0 * c.x() * c.y());
|
||||
covariance[2] += mass * (-1.0 * c.y() * c.y());
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<std::endl;
|
||||
|
||||
// std::cout<<"cov: "<<covariance[0]*covariance[2]<<" =? "<<covariance[1]*covariance[1]<<std::endl;
|
||||
|
||||
// solve for eigenvalues and eigenvectors.
|
||||
// eigen values are sorted in descending order,
|
||||
|
|
@ -139,11 +139,13 @@ linear_least_squares_fitting_2(InputIterator first,
|
|||
if(eigen_values.first != eigen_values.second)
|
||||
{
|
||||
// regular case
|
||||
// std::cout<<"AnIsotropic!! "<<eigen_values.second<<" "<<eigen_values.first<<" "<<std::sqrt((double)covariance[0]/(double)covariance[2])<<std::endl;
|
||||
line = Line(c, eigen_vectors.first);
|
||||
return (FT)1.0 - eigen_values.second / eigen_values.first;
|
||||
}
|
||||
else
|
||||
{
|
||||
// std::cout<<"Isotropic!!"<<std::endl;
|
||||
// isotropic case (infinite number of directions)
|
||||
// by default: assemble a line that goes through
|
||||
// the centroid and with a default horizontal vector.
|
||||
|
|
|
|||
|
|
@ -55,9 +55,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
// assemble covariance matrix
|
||||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Triangle*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting plane
|
||||
return fitting_plane_3(covariance,c,plane,k);
|
||||
|
|
@ -71,7 +68,7 @@ typename K::FT
|
|||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
typename K::Plane_3& plane, // best fit plane
|
||||
typename K::Segment_3& c, // centroid
|
||||
typename K::Point_3& c, // centroid
|
||||
const K& k, // kernel
|
||||
const typename K::Triangle_3*, // used for indirection
|
||||
const CGAL::PCA_dimension_1_tag& tag)
|
||||
|
|
@ -89,9 +86,9 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Triangle& t = *it;
|
||||
segments.push_back(t[0],t[1]);
|
||||
segments.push_back(t[1],t[2]);
|
||||
segments.push_back(t[2],t[0]);
|
||||
segments.push_back(Segment(t[0],t[1]));
|
||||
segments.push_back(Segment(t[1],t[2]));
|
||||
segments.push_back(Segment(t[2],t[0]));
|
||||
}
|
||||
|
||||
// compute fitting plane
|
||||
|
|
@ -159,9 +156,6 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
FT covariance[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
assemble_covariance_matrix_3(first,beyond,covariance,c,k,(Triangle*) NULL,tag);
|
||||
|
||||
// to remove later
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// compute fitting line
|
||||
return fitting_line_3(covariance,c,line,k);
|
||||
|
||||
|
|
@ -174,7 +168,7 @@ typename K::FT
|
|||
linear_least_squares_fitting_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
typename K::Line_3& line, // best fit line
|
||||
typename K::Segment_3& c, // centroid
|
||||
typename K::Point_3& c, // centroid
|
||||
const K& k, // kernel
|
||||
const typename K::Triangle_3*, // used for indirection
|
||||
const CGAL::PCA_dimension_1_tag& tag)
|
||||
|
|
@ -192,9 +186,9 @@ linear_least_squares_fitting_3(InputIterator first,
|
|||
it++)
|
||||
{
|
||||
const Triangle& t = *it;
|
||||
segments.push_back(t[0],t[1]);
|
||||
segments.push_back(t[1],t[2]);
|
||||
segments.push_back(t[2],t[0]);
|
||||
segments.push_back(Segment(t[0],t[1]));
|
||||
segments.push_back(Segment(t[1],t[2]));
|
||||
segments.push_back(Segment(t[2],t[0]));
|
||||
}
|
||||
|
||||
// compute fitting line
|
||||
|
|
|
|||
|
|
@ -292,13 +292,13 @@ assemble_covariance_matrix_3(InputIterator first,
|
|||
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();
|
||||
CGAL_assertion(volume != 0.0);
|
||||
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;
|
||||
CGAL_assertion(area != 0.0);
|
||||
|
||||
// Find the 2nd order moment for the cuboid wrt to the origin by an affine transformation.
|
||||
|
||||
// Transform the standard 2nd order moment using the transformation matrix
|
||||
transformation = volume * transformation * moment * LA::transpose(transformation);
|
||||
transformation = area * transformation * moment * LA::transpose(transformation);
|
||||
|
||||
// Translate the 2nd order moment to the minimum corner (x0,y0,z0) of the cuboid.
|
||||
FT xav0 = (delta[0] + delta[1] + delta[2])/4.0;
|
||||
|
|
@ -306,14 +306,14 @@ assemble_covariance_matrix_3(InputIterator first,
|
|||
FT zav0 = (delta[6] + delta[7] + delta[8])/4.0;
|
||||
|
||||
// and add to covariance matrix
|
||||
covariance[0] += transformation[0][0] + volume * (2*x0*xav0 + x0*x0);
|
||||
covariance[1] += transformation[1][0] + volume * (xav0*y0 + yav0*x0 + x0*y0);
|
||||
covariance[2] += transformation[1][1] + volume * (2*y0*yav0 + y0*y0);
|
||||
covariance[3] += transformation[2][0] + volume * (x0*zav0 + xav0*z0 + x0*z0);
|
||||
covariance[4] += transformation[2][1] + volume * (yav0*z0 + y0*zav0 + z0*y0);
|
||||
covariance[5] += transformation[2][2] + volume * (2*zav0*z0 + z0*z0);
|
||||
covariance[0] += transformation[0][0] + area * (2*x0*xav0 + x0*x0);
|
||||
covariance[1] += transformation[1][0] + area * (xav0*y0 + yav0*x0 + x0*y0);
|
||||
covariance[2] += transformation[1][1] + area * (2*y0*yav0 + y0*y0);
|
||||
covariance[3] += transformation[2][0] + area * (x0*zav0 + xav0*z0 + x0*z0);
|
||||
covariance[4] += transformation[2][1] + area * (yav0*z0 + y0*zav0 + z0*y0);
|
||||
covariance[5] += transformation[2][2] + area * (2*zav0*z0 + z0*z0);
|
||||
|
||||
mass += volume;
|
||||
mass += area;
|
||||
}
|
||||
|
||||
// Translate the 2nd order moment calculated about the origin to
|
||||
|
|
@ -375,13 +375,95 @@ assemble_covariance_matrix_3(InputIterator first,
|
|||
0.0, radius, 0.0,
|
||||
0.0, 0.0, radius};
|
||||
Matrix transformation = init_Matrix<K>(3,delta);
|
||||
FT area = 4/3.0 * radius*t.squared_radius();
|
||||
FT volume = 4/3.0 * radius*t.squared_radius();
|
||||
CGAL_assertion(volume != 0.0);
|
||||
|
||||
// Find the 2nd order moment for the sphere wrt to the origin by an affine transformation.
|
||||
|
||||
// Transform the standard 2nd order moment using the transformation matrix
|
||||
transformation = (3.0/4.0) * volume * transformation * moment * LA::transpose(transformation);
|
||||
|
||||
// Translate the 2nd order moment to the center of the sphere.
|
||||
FT x0 = t.center().x();
|
||||
FT y0 = t.center().y();
|
||||
FT z0 = t.center().z();
|
||||
|
||||
// and add to covariance matrix
|
||||
covariance[0] += transformation[0][0] + volume * x0*x0;
|
||||
covariance[1] += transformation[1][0] + volume * x0*y0;
|
||||
covariance[2] += transformation[1][1] + volume * y0*y0;
|
||||
covariance[3] += transformation[2][0] + volume * x0*z0;
|
||||
covariance[4] += transformation[2][1] + volume * z0*y0;
|
||||
covariance[5] += transformation[2][2] + volume * z0*z0;
|
||||
|
||||
mass += volume;
|
||||
}
|
||||
|
||||
// Translate the 2nd order moment calculated about the origin to
|
||||
// the center of mass to get the covariance.
|
||||
covariance[0] += mass * (-1.0 * c.x() * c.x());
|
||||
covariance[1] += mass * (-1.0 * c.x() * c.y());
|
||||
covariance[2] += mass * (-1.0 * c.y() * c.y());
|
||||
covariance[3] += mass * (-1.0 * c.z() * c.x());
|
||||
covariance[4] += mass * (-1.0 * c.z() * c.y());
|
||||
covariance[5] += mass * (-1.0 * c.z() * c.z());
|
||||
|
||||
}
|
||||
// assemble covariance matrix from a sphere set
|
||||
template < typename InputIterator,
|
||||
typename K >
|
||||
void
|
||||
assemble_covariance_matrix_3(InputIterator first,
|
||||
InputIterator beyond,
|
||||
typename K::FT covariance[6], // covariance matrix
|
||||
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)
|
||||
{
|
||||
typedef typename K::FT FT;
|
||||
typedef typename K::Point_3 Point;
|
||||
typedef typename K::Vector_3 Vector;
|
||||
typedef typename K::Sphere_3 Sphere;
|
||||
typedef typename CGAL::Linear_algebraCd<FT> LA;
|
||||
typedef typename LA::Matrix Matrix;
|
||||
|
||||
// assemble covariance matrix as a semi-definite matrix.
|
||||
// Matrix numbering:
|
||||
// 0
|
||||
// 1 2
|
||||
// 3 4 5
|
||||
//Final combined covariance matrix for all spheres and their combined mass
|
||||
FT mass = 0.0;
|
||||
|
||||
// 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, 0.0, 4.0/3.0};
|
||||
Matrix moment = init_Matrix<K>(3,temp);
|
||||
|
||||
for(InputIterator it = first;
|
||||
it != beyond;
|
||||
it++)
|
||||
{
|
||||
// Now for each sphere, construct the 2nd order moment about the origin.
|
||||
// assemble the transformation matrix.
|
||||
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, 0.0, radius};
|
||||
Matrix transformation = init_Matrix<K>(3,delta);
|
||||
FT area = 4 * t.squared_radius();
|
||||
CGAL_assertion(area != 0.0);
|
||||
|
||||
// Find the 2nd order moment for the sphere wrt to the origin by an affine transformation.
|
||||
|
||||
// Transform the standard 2nd order moment using the transformation matrix
|
||||
transformation = (3.0/4.0) * area * transformation * moment * LA::transpose(transformation);
|
||||
transformation = (1.0/4.0) * area * transformation * moment * LA::transpose(transformation);
|
||||
|
||||
// Translate the 2nd order moment to the center of the sphere.
|
||||
FT x0 = t.center().x();
|
||||
|
|
@ -550,7 +632,7 @@ assemble_covariance_matrix_3(InputIterator first,
|
|||
|
||||
// Transform the standard 2nd order moment using the transformation matrix
|
||||
transformation = length * transformation * moment * LA::transpose(transformation);
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
// and add to covariance matrix
|
||||
covariance[0] += transformation[0][0];
|
||||
covariance[1] += transformation[1][0];
|
||||
|
|
@ -558,7 +640,7 @@ assemble_covariance_matrix_3(InputIterator first,
|
|||
covariance[3] += transformation[2][0];
|
||||
covariance[4] += transformation[2][1];
|
||||
covariance[5] += transformation[2][2];
|
||||
std::cout<<covariance[0]<<" "<<covariance[1]<<" "<<covariance[2]<<" "<<covariance[3]<<" "<<covariance[4]<<" "<<covariance[5]<<std::endl;
|
||||
|
||||
mass += length;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ typedef Kernel::Iso_rectangle_2 Iso_rectangle_2;
|
|||
typedef Kernel::Segment_2 Segment_2;
|
||||
typedef Kernel::Vector_2 Vector_2;
|
||||
|
||||
// case with only one square in container
|
||||
// case with only one rectangle in container
|
||||
// the fitting line must be y = 1/2
|
||||
void test_1()
|
||||
{
|
||||
|
||||
std::list<Iso_rectangle_2> Iso_rectangles;
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(0.0,0.0),Point_2(4.0,4.0)));
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(0.0,0.0),Point_2(5.0,4.0)));
|
||||
// Iso_rectangles.push_back(Iso_rectangle_2(Point_2(4.0,0.0),Point_2(5.0,1.0)));
|
||||
|
||||
// fit a line
|
||||
|
|
@ -51,14 +51,14 @@ void test_1()
|
|||
}
|
||||
}
|
||||
|
||||
// case with only one square vs two rectangles that it is composed of
|
||||
// case with only one rectangle vs two rectangles that it is composed of
|
||||
// in container
|
||||
// the fitting line must be the same
|
||||
void test_2()
|
||||
{
|
||||
std::cout<<"Test 2"<<std::endl;
|
||||
std::list<Iso_rectangle_2> Iso_rectangles;
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(5.6,19.2)));
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(11.6,19.2)));
|
||||
// Iso_rectangles.push_back(Iso_rectangle_2(Point_2(4.0,0.0),Point_2(5.0,1.0)));
|
||||
|
||||
// fit a line
|
||||
|
|
@ -77,8 +77,8 @@ void test_2()
|
|||
// fit a line
|
||||
// call all versions of the function
|
||||
std::list<Iso_rectangle_2> Iso_rectangles1;
|
||||
Iso_rectangles1.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(3.6,19.2)));
|
||||
Iso_rectangles1.push_back(Iso_rectangle_2(Point_2(3.6,15.2),Point_2(5.6,19.2)));
|
||||
Iso_rectangles1.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(6.6,19.2)));
|
||||
Iso_rectangles1.push_back(Iso_rectangle_2(Point_2(6.6,15.2),Point_2(11.6,19.2)));
|
||||
std::cout << "fit 2D line to two small rectangles...";
|
||||
Kernel k1;
|
||||
Line_2 line1;
|
||||
|
|
@ -97,68 +97,58 @@ void test_2()
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// case with a point set on a segment vs the segment
|
||||
// the fitting line must be the same segment
|
||||
void test_5(const unsigned int nb_points)
|
||||
// case with only one rectangle vs two rectangles horizontally splitting the previous one in half
|
||||
// the fitting line must be the same
|
||||
void test_3()
|
||||
{
|
||||
std::cout<<"Test 5"<<std::endl;
|
||||
// create points on a horizontal segment
|
||||
Point_2 p(2.0,0.0);
|
||||
Point_2 q(5.0,5.0);
|
||||
|
||||
std::cout << "generate " << nb_points <<
|
||||
" 2D points on a horizontal line...";
|
||||
std::list<Point_2> points;
|
||||
points_on_segment_2(p,q,100,std::back_inserter(points));
|
||||
std::cout << "done " << std::endl;
|
||||
std::cout<<"Test 3"<<std::endl;
|
||||
std::list<Iso_rectangle_2> Iso_rectangles;
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(11.6,19.2)));
|
||||
// Iso_rectangles.push_back(Iso_rectangle_2(Point_2(4.0,0.0),Point_2(5.0,1.0)));
|
||||
|
||||
// fit a line
|
||||
std::cout << "fit 2D line to points...";
|
||||
// call all versions of the function
|
||||
std::cout << "fit 2D line to bigger rectangle...";
|
||||
Kernel k;
|
||||
Line_2 line;
|
||||
Point_2 centroid;
|
||||
|
||||
// call all versions of the function
|
||||
FT quality;
|
||||
Kernel k;
|
||||
quality = linear_least_squares_fitting_2(points.begin(),points.end(),line);
|
||||
quality = linear_least_squares_fitting_2(points.begin(),points.end(),line,centroid);
|
||||
quality = linear_least_squares_fitting_2(points.begin(),points.end(),line,centroid,k);
|
||||
|
||||
std::cout << "done (quality: " << quality << ")" <<" line: "<<line<< std::endl;
|
||||
|
||||
std::list<Segment_2> segments;
|
||||
segments.push_back(Segment_2(p,q));
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,centroid,CGAL::PCA_dimension_2_tag());
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,centroid,k,CGAL::PCA_dimension_2_tag());
|
||||
std::cout << "done (quality: " << quality << ") Line: " << line<<" centroid: "<<centroid<<std::endl;
|
||||
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 2D line to segment...";
|
||||
std::list<Iso_rectangle_2> Iso_rectangles1;
|
||||
Iso_rectangles1.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(11.6,17.2)));
|
||||
Iso_rectangles1.push_back(Iso_rectangle_2(Point_2(1.6,17.2),Point_2(11.6,19.2)));
|
||||
std::cout << "fit 2D line to two small rectangles...";
|
||||
Kernel k1;
|
||||
Line_2 line1;
|
||||
Point_2 centroid1;
|
||||
FT quality1;
|
||||
quality1 = linear_least_squares_fitting_2(segments.begin(),segments.end(),line1);
|
||||
quality1 = linear_least_squares_fitting_2(segments.begin(),segments.end(),line1,centroid1);
|
||||
quality1 = linear_least_squares_fitting_2(segments.begin(),segments.end(),line1,centroid1,k1);
|
||||
quality1 = linear_least_squares_fitting_2(segments.begin(),segments.end(),line1,centroid1,k1,false);
|
||||
std::cout << "done (quality: " << quality1 << ")" <<" line: "<<line1<< std::endl;
|
||||
quality1 = linear_least_squares_fitting_2(Iso_rectangles1.begin(),Iso_rectangles1.end(),line1,CGAL::PCA_dimension_2_tag());
|
||||
quality1 = linear_least_squares_fitting_2(Iso_rectangles1.begin(),Iso_rectangles1.end(),line1,centroid1,CGAL::PCA_dimension_2_tag());
|
||||
quality1 = linear_least_squares_fitting_2(Iso_rectangles1.begin(),Iso_rectangles1.end(),line1,centroid1,k1,CGAL::PCA_dimension_2_tag());
|
||||
std::cout << "done (quality: " << quality1 << ") Line: " << line1<<" centroid: "<<centroid1<<std::endl;
|
||||
|
||||
|
||||
if(!(std::abs(-1.0*line.a()/line.b() - -1.0*line1.a()/line1.b()) <= THRESHOLD && std::abs(line.c()/line.b() - line1.c()/line1.b()) <= THRESHOLD && std::abs(quality1 - quality) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure" << std::endl;
|
||||
exit(1); // failure
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
std::cout << "Test 2D linear_least_squares_fitting_rectangles" << std::endl;
|
||||
|
||||
test_1();
|
||||
// test_2();
|
||||
test_2();
|
||||
test_3();
|
||||
|
||||
|
||||
return 0; // success
|
||||
|
|
|
|||
|
|
@ -0,0 +1,246 @@
|
|||
// test for the linear_least_square_fitting() functions.
|
||||
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/copy_n.h>
|
||||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
#include <CGAL/point_generators_3.h>
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <stdlib.h>
|
||||
#define THRESHOLD 0.001
|
||||
// types
|
||||
|
||||
typedef CGAL::Cartesian<double> Kernel;
|
||||
typedef Kernel::FT FT;
|
||||
|
||||
typedef Kernel::Line_3 Line_3;
|
||||
typedef Kernel::Plane_3 Plane_3;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Segment_3 Segment_3;
|
||||
typedef Kernel::Vector_3 Vector_3;
|
||||
typedef Kernel::Direction_3 Direction_3;
|
||||
|
||||
// case with only one segment in container
|
||||
// the fitting line must be the same
|
||||
void test_1()
|
||||
{
|
||||
std::list<Segment_3> segments;
|
||||
segments.push_back(Segment_3(Point_3(3.0,3.0,3.0),Point_3(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...";
|
||||
Kernel k;
|
||||
Line_3 line;
|
||||
Point_3 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
std::cout << "done (quality: " << quality << ") line: " <<line<< std::endl;
|
||||
|
||||
// if(!(std::abs(-1.0*line.a()/line.b() - 1) <= THRESHOLD && std::abs(line.c()/line.b()) <= THRESHOLD && 1 - quality <= THRESHOLD))
|
||||
// line.has_on(Point_3(2.0,2.0,2.0)) &&
|
||||
if(!(line.has_on(Point_3(2.0,2.0,2.0)) && (double)line.to_vector().x() - 1/std::sqrt(3.0) <=THRESHOLD && (double)line.to_vector().y() - 1.0/std::sqrt(3.0) <= THRESHOLD && (double)line.to_vector().z() - 1.0/std::sqrt(3.0) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure" << 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"<<std::endl;
|
||||
std::list<Segment_3> segments;
|
||||
segments.push_back(Segment_3(Point_3(2.0,2.0,2.0),Point_3(1.5,1.5,1.5)));
|
||||
segments.push_back(Segment_3(Point_3(1.0,1.0,1.0),Point_3(1.5,1.5,1.5)));
|
||||
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 3D line...";
|
||||
Kernel k;
|
||||
Line_3 line;
|
||||
Point_3 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
std::cout << "done (quality: " << quality << ")" << std::endl;
|
||||
|
||||
if(!(line.has_on(Point_3(2.0,2.0,2.0)) && (double)line.to_vector().x() - 1/std::sqrt(3.0) <=THRESHOLD && (double)line.to_vector().y() - 1.0/std::sqrt(3.0) <= THRESHOLD && (double)line.to_vector().z() - 1.0/std::sqrt(3.0) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure" << 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"<<std::endl;
|
||||
std::list<Segment_3> segments;
|
||||
segments.push_back(Segment_3(Point_3(2.0,2.0,2.0),Point_3(1.75,1.75,1.75)));
|
||||
segments.push_back(Segment_3(Point_3(1.75,1.75,1.75),Point_3(1.50,1.50,1.50)));
|
||||
segments.push_back(Segment_3(Point_3(1.50,1.50,1.50),Point_3(1.25,1.25,1.25)));
|
||||
segments.push_back(Segment_3(Point_3(1.25,1.25,1.25),Point_3(1.0,1.0,1.0)));
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 3D line...";
|
||||
Kernel k;
|
||||
Line_3 line;
|
||||
Point_3 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
std::cout.precision(20);
|
||||
std::cout << "done (quality: " << quality << ")" <<" line: "<<line<<std::endl;
|
||||
|
||||
if(!(line.point(0)==Point_3(1.5,1.5,1.5) && (double)line.to_vector().x() - 1/std::sqrt(3.0) <=THRESHOLD && (double)line.to_vector().y() - 1.0/std::sqrt(3.0) <= THRESHOLD && (double)line.to_vector().z() - 1.0/std::sqrt(3.0) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure " <<std::endl;
|
||||
exit(1); // failure Direction_3(0.57735,0.57735,0.57735)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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"<<std::endl;
|
||||
Point_3 p = Point_3(1.5,6.0,12.34);
|
||||
Point_3 q = Point_3(1.12,7.21,4.3);
|
||||
std::list<Segment_3> segments;
|
||||
segments.push_back(Segment_3(p,q));
|
||||
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 3D line to segment...";
|
||||
Kernel k;
|
||||
Line_3 line;
|
||||
Point_3 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
std::cout << "done (quality: " << quality << ")" <<" line: "<<line<< std::endl;
|
||||
|
||||
std::list<Point_3> 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...";
|
||||
Kernel k1;
|
||||
Line_3 line1;
|
||||
Point_3 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());
|
||||
quality1 = linear_least_squares_fitting_3(points.begin(),points.end(),line1,centroid1,k1,CGAL::PCA_dimension_0_tag());
|
||||
std::cout << "done (quality: " << quality1 << ")" <<" line: "<<line1<<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<Segment_3> segments;
|
||||
segments.push_back(Segment_3(Point_3(3.0,3.0,3.0),Point_3(1.0,1.0,1.0)));
|
||||
|
||||
|
||||
// fit a plane
|
||||
// call all versions of the function
|
||||
std::cout<<"Test 5"<<std::endl;
|
||||
std::cout << "fit 3D plane...";
|
||||
Kernel k;
|
||||
Plane_3 plane;
|
||||
Point_3 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
std::cout << "done (quality: " << quality << ") plane: " <<plane<< std::endl;
|
||||
|
||||
if(!plane.has_on(segments[0].supporting_line()))
|
||||
// if(!(line.has_on(Point_3(2.0,2.0,2.0)) && (double)line.to_vector().x() - 1/std::sqrt(3.0) <=THRESHOLD && (double)line.to_vector().y() - 1.0/std::sqrt(3.0) <= THRESHOLD && (double)line.to_vector().z() - 1.0/std::sqrt(3.0) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure" << std::endl;
|
||||
exit(1); // failure
|
||||
}
|
||||
}
|
||||
|
||||
void test_6() {
|
||||
std::vector<Segment_3> segments;
|
||||
segments.push_back(Segment_3(Point_3(3.0,3.0,3.0),Point_3(1.0,1.0,1.0)));
|
||||
|
||||
|
||||
// call all versions of the function
|
||||
std::cout<<"Test 6"<<std::endl;
|
||||
Kernel k;
|
||||
Plane_3 plane;
|
||||
Line_3 line;
|
||||
Point_3 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,centroid,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,centroid,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,k,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),plane,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,k,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,centroid,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,k,CGAL::PCA_dimension_1_tag());
|
||||
quality = linear_least_squares_fitting_3(segments.begin(),segments.end(),line,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
}
|
||||
int main()
|
||||
{
|
||||
std::cout << "Test 3D linear_least_squares_fitting_segments" << std::endl;
|
||||
|
||||
test_1();
|
||||
test_2();
|
||||
|
||||
// test_3();
|
||||
test_4();
|
||||
|
||||
// test_5();
|
||||
// test_3D_point_set(100);
|
||||
|
||||
test_6();
|
||||
return 0; // success
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
// test for the linear_least_square_fitting() functions.
|
||||
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/copy_n.h>
|
||||
#include <CGAL/linear_least_squares_fitting_2.h>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <stdlib.h>
|
||||
#define THRESHOLD 0.001
|
||||
// types
|
||||
|
||||
typedef CGAL::Cartesian<double> Kernel;
|
||||
typedef Kernel::FT FT;
|
||||
|
||||
typedef Kernel::Line_2 Line_2;
|
||||
typedef Kernel::Point_2 Point_2;
|
||||
typedef Kernel::Triangle_2 Triangle_2;
|
||||
typedef Kernel::Iso_rectangle_2 Iso_rectangle_2;
|
||||
typedef Kernel::Segment_2 Segment_2;
|
||||
typedef Kernel::Vector_2 Vector_2;
|
||||
|
||||
// case with one rectangle in container vs it split into two triangles
|
||||
// the fitting line must be the same.
|
||||
void test_1()
|
||||
{
|
||||
std::cout<<"Test 1"<<std::endl;
|
||||
std::list<Iso_rectangle_2> Iso_rectangles;
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(11.6,19.2)));
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 2D line to bigger rectangle...";
|
||||
Kernel k;
|
||||
Line_2 line;
|
||||
Point_2 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,centroid,CGAL::PCA_dimension_2_tag());
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,centroid,k,CGAL::PCA_dimension_2_tag());
|
||||
std::cout << "done (quality: " << quality << ") Line: " << line<<" centroid: "<<centroid<<std::endl;
|
||||
|
||||
|
||||
std::list<Triangle_2> Triangles1;
|
||||
Triangles1.push_back(Triangle_2(Point_2(1.6,15.2),Point_2(1.6,19.2),Point_2(11.6,19.2)));
|
||||
Triangles1.push_back(Triangle_2(Point_2(1.6,15.2),Point_2(11.6,19.2),Point_2(11.6,15.2)));
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 2D line to two small triangles...";
|
||||
Kernel k1;
|
||||
Line_2 line1;
|
||||
Point_2 centroid1;
|
||||
FT quality1;
|
||||
quality1 = linear_least_squares_fitting_2(Triangles1.begin(),Triangles1.end(),line1,CGAL::PCA_dimension_2_tag());
|
||||
quality1 = linear_least_squares_fitting_2(Triangles1.begin(),Triangles1.end(),line1,centroid1,CGAL::PCA_dimension_2_tag());
|
||||
quality1 = linear_least_squares_fitting_2(Triangles1.begin(),Triangles1.end(),line1,centroid1,k1,CGAL::PCA_dimension_2_tag());
|
||||
std::cout << "done (quality: " << quality1 << ") Line: " << line1<<" centroid: "<<centroid1<<std::endl;
|
||||
|
||||
|
||||
if(!(std::abs(-1.0*line.a()/line.b() - -1.0*line1.a()/line1.b()) <= THRESHOLD && std::abs(line.c()/line.b() - line1.c()/line1.b()) <= THRESHOLD && std::abs(quality1 - quality) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure" << std::endl;
|
||||
exit(1); // failure
|
||||
}
|
||||
}
|
||||
|
||||
// case with one rectangle in container vs it split into four triangles
|
||||
// the fitting line must be the same.
|
||||
void test_2()
|
||||
{
|
||||
std::cout<<"Test 2"<<std::endl;
|
||||
std::list<Iso_rectangle_2> Iso_rectangles;
|
||||
Iso_rectangles.push_back(Iso_rectangle_2(Point_2(1.6,15.2),Point_2(11.6,19.2)));
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 2D line to bigger rectangle...";
|
||||
Kernel k;
|
||||
Line_2 line;
|
||||
Point_2 centroid;
|
||||
FT quality;
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,centroid,CGAL::PCA_dimension_2_tag());
|
||||
quality = linear_least_squares_fitting_2(Iso_rectangles.begin(),Iso_rectangles.end(),line,centroid,k,CGAL::PCA_dimension_2_tag());
|
||||
std::cout << "done (quality: " << quality << ") Line: " << line<<" centroid: "<<centroid<<std::endl;
|
||||
|
||||
|
||||
std::list<Triangle_2> Triangles1;
|
||||
Triangles1.push_back(Triangle_2(Point_2(1.6,15.2),Point_2(1.6,19.2),Point_2(6.6,17.2)));
|
||||
Triangles1.push_back(Triangle_2(Point_2(11.6,19.2),Point_2(11.6,15.2),Point_2(6.6,17.2)));
|
||||
Triangles1.push_back(Triangle_2(Point_2(1.6,19.2),Point_2(11.6,19.2),Point_2(6.6,17.2)));
|
||||
Triangles1.push_back(Triangle_2(Point_2(1.6,15.2),Point_2(11.6,15.2),Point_2(6.6,17.2)));
|
||||
|
||||
// fit a line
|
||||
// call all versions of the function
|
||||
std::cout << "fit 2D line to four small triangles...";
|
||||
Kernel k1;
|
||||
Line_2 line1;
|
||||
Point_2 centroid1;
|
||||
FT quality1;
|
||||
quality1 = linear_least_squares_fitting_2(Triangles1.begin(),Triangles1.end(),line1,CGAL::PCA_dimension_2_tag());
|
||||
quality1 = linear_least_squares_fitting_2(Triangles1.begin(),Triangles1.end(),line1,centroid1,CGAL::PCA_dimension_2_tag());
|
||||
quality1 = linear_least_squares_fitting_2(Triangles1.begin(),Triangles1.end(),line1,centroid1,k1,CGAL::PCA_dimension_2_tag());
|
||||
std::cout << "done (quality: " << quality1 << ") Line: " << line1<<" centroid: "<<centroid1<<std::endl;
|
||||
|
||||
|
||||
if(!(std::abs(-1.0*line.a()/line.b() - -1.0*line1.a()/line1.b()) <= THRESHOLD && std::abs(line.c()/line.b() - line1.c()/line1.b()) <= THRESHOLD && std::abs(quality1 - quality) <= THRESHOLD))
|
||||
{
|
||||
std::cout << "failure" << std::endl;
|
||||
exit(1); // failure
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Test 2D linear_least_squares_fitting_triangles" << std::endl;
|
||||
|
||||
test_1();
|
||||
test_2();
|
||||
|
||||
return 0; // success
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
// Example program for the linear_least_square_fitting function on a set of circles in 2D
|
||||
|
||||
#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;
|
||||
|
||||
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));
|
||||
|
||||
Line_2 line;
|
||||
Point_2 c;
|
||||
K k;
|
||||
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,c,CGAL::PCA_dimension_1_tag());
|
||||
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,k,CGAL::PCA_dimension_1_tag());
|
||||
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_2(circles.begin(),circles.end(),line,c,k,CGAL::PCA_dimension_1_tag());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// Example program for the linear_least_square_fitting function on set of cuboids 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::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)));
|
||||
|
||||
Line_3 line;
|
||||
K k;
|
||||
Point_3 c;
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,c,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
Plane_3 plane;
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,c,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// Example program for the linear_least_square_fitting function
|
||||
|
||||
#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;
|
||||
|
||||
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));
|
||||
|
||||
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());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,c,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,c,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,k,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,c,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),line,c,k,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,c,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,c,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,k,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,c,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(spheres.begin(),spheres.end(),plane,c,k,CGAL::PCA_dimension_2_tag());
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// 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;
|
||||
Point_3 c;
|
||||
K k;
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),line,c,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
Plane_3 plane;
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,k,CGAL::PCA_dimension_3_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(tetrahedrons.begin(),tetrahedrons.end(),plane,c,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// Example program for the linear_least_square_fitting function on set of triangles 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::Triangle_3 Triangle_3;
|
||||
|
||||
int main()
|
||||
{
|
||||
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)));
|
||||
|
||||
Line_3 line;
|
||||
Point_3 c;
|
||||
K k;
|
||||
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,c,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,c,k,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,c,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),line,c,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
Plane_3 plane;
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,CGAL::PCA_dimension_0_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,k,CGAL::PCA_dimension_0_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,c,k,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,c,k,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,c,k,CGAL::PCA_dimension_0_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,c,CGAL::PCA_dimension_2_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,c,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(triangles.begin(),triangles.end(),plane,c,CGAL::PCA_dimension_0_tag());
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue