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());
|
||||
|
||||
//Use only faces.
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),line,CGAL::PCA_dimension_2_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());
|
||||
|
||||
linear_least_squares_fitting_3(Iso_cuboids.begin(),Iso_cuboids.end(),plane,CGAL::PCA_dimension_2_tag());
|
||||
// fit edges
|
||||
linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),line,CGAL::PCA_dimension_1_tag());
|
||||
linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),plane,CGAL::PCA_dimension_1_tag());
|
||||
|
||||
// fit vertices
|
||||
linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),line,CGAL::PCA_dimension_0_tag());
|
||||
linear_least_squares_fitting_3(cuboids.begin(),cuboids.end(),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;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ typedef K::Plane_3 Plane_3;
|
|||
typedef K::Point_3 Point_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 {};
|
||||
|
||||
/*
|
||||
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ 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].z(), t[1].z(), t[2].z()};
|
||||
|
|
@ -380,7 +379,6 @@ 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,
|
||||
|
|
@ -545,7 +543,6 @@ 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();
|
||||
|
|
|
|||
|
|
@ -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 Object& object, // plane or line
|
||||
typename Kernel::Point_3& centroid,
|
||||
const Tag& tag,
|
||||
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