Cosmetic changes

This commit is contained in:
Mael Rouxel-Labbé 2018-06-11 16:54:37 +02:00
parent 9d5a83ebf6
commit f8a3b552d3
13 changed files with 178 additions and 180 deletions

View File

@ -1,31 +1,32 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Optimal_bounding_box/optimal_bounding_box.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <iostream>
#include <fstream>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/Optimal_bounding_box/optimal_bounding_box.h>
#include <CGAL/subdivision_method_3.h>
#include <CGAL/Timer.h>
//#define OBB_DEBUG_BENCHMARK
#include <iostream>
#include <fstream>
#include <vector>
//#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
void
bench(const char* fname)
void bench(const char* fname)
{
std::vector<K::Point_3> sm_points, obb_points;
std::ifstream in(fname);
K::Point_3 p;
int i = 0;
while(in >> p){
while(in >> p)
{
if(i % 2 == 0) // avoid normals
{
sm_points.push_back(p);
}
++i;
}
@ -40,22 +41,19 @@ bench(const char* fname)
std::cout << "done" << '\n';
#ifdef OBB_DEBUG_BENCHMARK
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK
std::cout.precision(17);
for(int i =0; i < obb_points.size(); i++)
{
std::cout << obb_points[i] << std::endl;
}
CGAL::Surface_mesh<K::Point_3> mesh;
CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3], obb_points[4], obb_points[5],
obb_points[6], obb_points[7], mesh);
CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3],
obb_points[4], obb_points[5], obb_points[6], obb_points[7], mesh);
std::ofstream out("/tmp/result_obb.off");
out << mesh;
out.close();
#endif
}
int main(int argc, char* argv[])

View File

@ -1,28 +1,32 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/Optimal_bounding_box/fitness_function.h>
#include <CGAL/Optimal_bounding_box/helper.h>
#include <CGAL/Optimal_bounding_box/population.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/subdivision_method_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Timer.h>
#include <fstream>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
int main()
{
const char* fname = "data/elephant.off";
// 1) import a lot a mesh and subdivide it to create a big mesh
std::ifstream input(fname);
CGAL::Surface_mesh<K::Point_3> mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
if (!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
CGAL::Subdivision_method_3::CatmullClark_subdivision(mesh,
@ -40,11 +44,9 @@ int main()
MatrixX3d points_mat(nb_points, 3);
CGAL::Optimal_bounding_box::sm_to_matrix(mesh, points_mat);
// 3) create a population of simplices
CGAL::Optimal_bounding_box::Population<Linear_algebra_traits> pop(50);
CGAL::Timer timer;
timer.start();
@ -58,7 +60,5 @@ int main()
std::cout << "took " << timer.time() << " to compute the fitness of all vertices.\n";
std::cout << "value of fittest vertex= " << result << std::endl;
return 0;
}

View File

@ -1,21 +1,22 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/Optimal_bounding_box/population.h>
#include <CGAL/Optimal_bounding_box/optimal_bounding_box.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Timer.h>
#include <iostream>
#include <fstream>
#include <CGAL/Timer.h>
//#define OBB_DEBUG_BENCHMARK
//#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
bool assert_doubles(double d1, double d2, double epsilon)
{
return (d1 < d2 + epsilon && d1 > d2 - epsilon) ? true : false;
@ -49,10 +50,12 @@ void bench_finding_obb(std::string fname)
// import a mesh
CGAL::Surface_mesh<K::Point_3> mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
if (!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
// get mesh points
gather_mesh_points(mesh, sm_points);
@ -83,13 +86,12 @@ void bench_finding_obb(std::string fname)
std::cout << "found obb without convex hull: " << timer.time() << " seconds\n";
timer.reset();
#ifdef OBB_DEBUG_BENCHMARK
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK
CGAL::Surface_mesh<K::Point_3> result_mesh1;
CGAL::make_hexahedron(obb_points1[0], obb_points1[1], obb_points1[2], obb_points1[3],
obb_points1[4], obb_points1[5], obb_points1[6], obb_points1[7],
result_mesh1);
CGAL::Surface_mesh<K::Point_3> result_mesh2;
CGAL::make_hexahedron(obb_points2[0], obb_points2[1], obb_points2[2], obb_points2[3],
obb_points2[4], obb_points2[5], obb_points2[6], obb_points2[7],

View File

@ -1,14 +1,17 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Optimal_bounding_box/optimal_bounding_box.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <iostream>
#include <fstream>
#include <CGAL/Optimal_bounding_box/optimal_bounding_box.h>
#include <CGAL/subdivision_method_3.h>
#include <CGAL/Timer.h>
//#define OBB_DEBUG_BENCHMARK
#include <fstream>
#include <iostream>
//#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
@ -18,9 +21,10 @@ void bench_finding_obb(std::string fname)
// import a mesh
CGAL::Surface_mesh<K::Point_3> mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
if (!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
// export some times
@ -62,8 +66,7 @@ void bench_finding_obb(std::string fname)
outt.close();
#ifdef OBB_DEBUG_BENCHMARK
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_BENCHMARK
std::ofstream out1("data/obb_result1.off");
out1 << obb_points1;
out1.close();

View File

@ -1,2 +1 @@
To draw a graph with the benchmark times set the path-to-the-measurments in draw_benchmark_times.py if necessary,
and run the script with python 3.
To draw a graph with the benchmark times set the path-to-the-measurments in draw_benchmark_times.py if necessary, and run the script with python 3.

View File

@ -16,7 +16,6 @@
// $Id$
// SPDX-License-Identifier: GPL-3.0+
//
//
// Author(s) : Konstantinos Katrioplas
#ifndef CGAL_OPTIMAL_BOUNDING_BOX_EVOLUTION_H
@ -24,13 +23,20 @@
#include <CGAL/Optimal_bounding_box/population.h>
#include <CGAL/Optimal_bounding_box/nelder_mead_functions.h>
#include <CGAL/Optimal_bounding_box/fitness_function.h>
#include <CGAL/Random.h>
#include <CGAL/number_utils.h>
#include <boost/iterator/counting_iterator.hpp>
namespace CGAL {
namespace Optimal_bounding_box {
#include <algorithm>
#include <iostream>
#include <vector>
namespace CGAL {
namespace Optimal_bounding_box {
template <typename Linear_algebra_traits>
class Evolution
@ -40,19 +46,19 @@ class Evolution
typedef typename Linear_algebra_traits::Vector3d Vector3d;
public:
Evolution(Population<Linear_algebra_traits>& pop, MatrixXd& points) :
population(pop),
point_data(points)
Evolution(Population<Linear_algebra_traits>& pop, MatrixXd& points)
: population(pop), point_data(points)
{}
// simplex: 4 rotation matrices are its vertices
void nelder_mead(std::vector<Matrix3d>& simplex, std::size_t nelder_mead_iterations)
void nelder_mead(std::vector<Matrix3d>& simplex,
std::size_t nelder_mead_iterations)
{
CGAL_assertion(simplex.size() == 4); // tetrahedron
std::vector<double> fitness(4);
std::vector<std::size_t> indices( boost::counting_iterator<std::size_t>( 0 ),
boost::counting_iterator<std::size_t>( simplex.size() ) );
std::vector<std::size_t> indices(boost::counting_iterator<std::size_t>(0),
boost::counting_iterator<std::size_t>(simplex.size()));
for(std::size_t t = 0; t < nelder_mead_iterations; ++t)
{
@ -165,12 +171,12 @@ public:
for(std::size_t i = 0; i < ids4.size(); ++i)
group4[i] = population[ids4[i]];
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
check_det(group1);
check_det(group2);
check_det(group3);
check_det(group4);
#endif
#endif
// crossover I
Population<Linear_algebra_traits> offspringsA(size_first_group);
@ -185,10 +191,12 @@ public:
double fitnessA = compute_fitness<Linear_algebra_traits>(group1[i][j], point_data);
double fitnessB = compute_fitness<Linear_algebra_traits>(group2[i][j], point_data);
double threshold;
if(fitnessA < fitnessB)
threshold = 0.5 + bias;
else
threshold = 0.5 - bias;
if(r < threshold) // choose A
offspring[j] = group1[i][j];
else // choose B
@ -197,11 +205,11 @@ public:
offspringsA[i] = offspring;
}
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
std::cout << "offspringsA: \n" ;
check_det(offspringsA);
std::cin.get();
#endif
#endif
// crossover II
Population<Linear_algebra_traits> offspringsB(size_second_group);
@ -228,10 +236,10 @@ public:
offspringsB[i] = offspring;
}
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
std::cout << "offspringsB: \n" ;
check_det(offspringsB);
#endif
#endif
CGAL_assertion(offspringsA.size() == size_first_group);
CGAL_assertion(offspringsB.size() == size_second_group);
@ -239,14 +247,10 @@ public:
// next generatrion
for(std::size_t i = 0; i < size_first_group; ++i)
{
population[i] = offspringsA[i];
}
for(std::size_t i = 0; i < size_second_group; ++i)
{
population[size_first_group + i] = offspringsB[i];
}
}
void evolve(std::size_t generations)
@ -262,35 +266,35 @@ public:
for(std::size_t t = 0; t < generations; ++t)
{
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
std::cout << "generation= " << t << "\n";
#endif
#endif
genetic_algorithm();
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
//std::cout << "pop after genetic" << std::endl;
//pop.show_population();
//std::cout << std::endl;
#endif
#endif
for(std::size_t s = 0; s < population.size(); ++s)
nelder_mead(population[s], nelder_mead_iterations);
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
//std::cout << "pop after nelder mead: " << std::endl;
//pop.show_population();
//std::cout << std::endl;
Fitness_map<Linear_algebra_traits, Matrix3d, MatrixXd> fitness_map_debug(population, point_data);
Matrix3d R_now = fitness_map_debug.get_best();
std::cout << "det= " << Linear_algebra_traits::determinant(R_now) << std::endl;
#endif
#endif
// stopping criteria
Fitness_map<Linear_algebra_traits, Matrix3d, MatrixXd> fitness_map(population, point_data);
new_fit_value = fitness_map.get_best_fitness_value();
double difference = new_fit_value - prev_fit_value;
if(CGAL::abs(difference) < tolerance * new_fit_value)
stale++;
@ -313,10 +317,10 @@ private:
{
Comparator(const std::vector<double>& in) : fitness(in) {}
inline bool operator() (std::size_t& i, std::size_t& j)
{
inline bool operator() (std::size_t& i, std::size_t& j) {
return fitness[i] < fitness[j];
}
const std::vector<double>& fitness;
};
@ -325,8 +329,7 @@ private:
MatrixXd point_data;
};
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
template <typename Simplex>
void check_det(Population<Simplex>& pop)
{
@ -341,10 +344,7 @@ void check_det(Population<Simplex>& pop)
}
#endif
} // end namespace Optimal_bounding_box
} // end namespace CGAL
}} // end namespaces
#endif
#endif // CGAL_OPTIMAL_BOUNDING_BOX_EVOLUTION_H

View File

@ -16,18 +16,19 @@
// $Id$
// SPDX-License-Identifier: GPL-3.0+
//
//
// Author(s) : Konstantinos Katrioplas
#ifndef CGAL_OPTIMAL_BOUNDING_FITNESS_FUNCTION_H
#define CGAL_OPTIMAL_BOUNDING_FITNESS_FUNCTION_H
#include <CGAL/Bbox_3.h>
#include <vector>
#include <CGAL/Optimal_bounding_box/population.h>
#include <CGAL/assertions.h>
#include <limits>
namespace CGAL {
namespace Optimal_bounding_box {
template <typename Linear_algebra_traits, typename Vertex, typename Matrix>
@ -74,7 +75,8 @@ double compute_fitness(const Vertex& R, const Matrix& data)
template <typename Linear_algebra_traits, typename Vertex, typename Matrix>
struct Fitness_map
{
Fitness_map(Population<Linear_algebra_traits>& p, Matrix& points) : pop(p), points(points)
Fitness_map(Population<Linear_algebra_traits>& p, Matrix& points)
: pop(p), points(points)
{}
const Vertex get_best()
@ -109,14 +111,7 @@ struct Fitness_map
const Matrix& points;
};
}} // end namespaces
#endif //CGAL_FITNESS_FUNCTION_H
} // end namespace Optimal_bounding_box
} // end namespace CGAL
#endif // CGAL_OPTIMAL_BOUNDING_FITNESS_FUNCTION_H

View File

@ -19,18 +19,24 @@
//
// Author(s) : Konstantinos Katrioplas
#ifndef CGAL_OPTIMAL_BOUNDING_HELPER_H
#define CGAL_OPTIMAL_BOUNDING_HELPER_H
#ifndef CGAL_OPTIMAL_BOUNDING_BOX_HELPER_H
#define CGAL_OPTIMAL_BOUNDING_BOX_HELPER_H
#include <vector>
#include <fstream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/boost/graph/helpers.h>
#include <CGAL/number_utils.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <fstream>
#include <string>
#include <vector>
namespace CGAL {
namespace Optimal_bounding_box {
namespace Optimal_bounding_box {
template <typename Matrix, typename Point>
void fill_matrix(const std::vector<Point>& v_points, Matrix& points_mat)
@ -93,16 +99,15 @@ void matrix_to_mesh_and_draw(Matrix& data_points, std::string filename)
}
Mesh mesh;
CGAL::make_hexahedron(points[0], points[1], points[2], points[3], points[4], points[5],
points[6], points[7], mesh);
CGAL::make_hexahedron(points[0], points[1], points[2], points[3],
points[4], points[5], points[6], points[7], mesh);
std::ofstream out(filename);
out << mesh;
out.close();
}
}} // end namespaces
} // end namespace Optimal_bounding_box
} // end namespace CGAL
#endif
#endif // CGAL_OPTIMAL_BOUNDING_BOX_HELPER_H

View File

@ -16,7 +16,6 @@
// $Id$
// SPDX-License-Identifier: GPL-3.0+
//
//
// Author(s) : Konstantinos Katrioplas
#ifndef CGAL_OPTIMAL_BOUNDING_BOX_NEALDER_MEAD_FUNCTIONS_H
@ -25,8 +24,8 @@
#include <CGAL/assertions.h>
namespace CGAL {
namespace Optimal_bounding_box {
namespace Optimal_bounding_box {
template <typename Linear_algebra_traits, typename Matrix>
const Matrix reflection(const Matrix& S_centroid, const Matrix& S_worst)
@ -76,7 +75,7 @@ const Matrix nm_centroid(const Matrix& S1, const Matrix& S2, const Matrix& S3)
return Q / det;
}
}} // end namespaces
} // end namespace Optimal_bounding_box
} // end namespace CGAL
#endif

View File

@ -25,24 +25,30 @@
#include <CGAL/Optimal_bounding_box/population.h>
#include <CGAL/Optimal_bounding_box/evolution.h>
#include <CGAL/Optimal_bounding_box/helper.h>
#include <vector>
#include <CGAL/boost/graph/helpers.h>
#include <CGAL/assertions.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/Iso_cuboid_3.h>
#include <CGAL/boost/graph/helpers.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#ifdef OBB_BENCHMARKS
#include <CGAL/Timer.h>
#include <CGAL/Iso_cuboid_3.h>
#include <CGAL/Simple_cartesian.h>
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
#include <CGAL/Timer.h>
#endif
#if defined(CGAL_EIGEN3_ENABLED)
#include <CGAL/Eigen_linear_algebra_traits.h>
#endif
namespace CGAL {
namespace Optimal_bounding_box {
#include <iostream>
#include <iterator>
#include <vector>
namespace CGAL {
namespace Optimal_bounding_box {
// works on matrices only
/// \cond SKIP_IN_MANUAL
@ -127,21 +133,20 @@ void find_obb(const std::vector<Point>& points,
CGAL::Optimal_bounding_box::fill_matrix(points, points_mat);
}
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
CGAL::Timer timer;
#endif
std::size_t max_generations = 100;
Population<LinearAlgebraTraits> pop(50);
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
timer.start();
#endif
CGAL::Optimal_bounding_box::Evolution<LinearAlgebraTraits>
search_solution(pop, points_mat);
CGAL::Optimal_bounding_box::Evolution<LinearAlgebraTraits> search_solution(pop, points_mat);
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
timer.stop();
std::cout << "constructor: " << timer.time() << std::endl;
timer.reset();
@ -150,7 +155,7 @@ void find_obb(const std::vector<Point>& points,
search_solution.evolve(max_generations);
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
timer.stop();
std::cout << "evolve: " << timer.time() << std::endl;
timer.reset();
@ -159,7 +164,7 @@ void find_obb(const std::vector<Point>& points,
Matrix3d rotation = search_solution.get_best();
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
timer.stop();
std::cout << "get best: " << timer.time() << std::endl;
#endif
@ -167,14 +172,14 @@ void find_obb(const std::vector<Point>& points,
MatrixXd obb; // may be preallocated at compile time
obb.resize(8, 3);
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
timer.reset();
timer.start();
#endif
post_processing<LinearAlgebraTraits>(points_mat, rotation, obb);
#ifdef OBB_BENCHMARKS
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_BENCHMARKS
timer.stop();
std::cout << "post porcessing: " << timer.time() << std::endl;
#endif
@ -242,8 +247,7 @@ void find_obb(const PolygonMesh& pmesh,
find_obb(points, obb_points, la_traits, use_ch);
CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3],
obb_points[4], obb_points[5],
obb_points[6], obb_points[7], obbmesh);
obb_points[4], obb_points[5], obb_points[6], obb_points[7], obbmesh);
}
template <typename PolygonMesh>
@ -261,11 +265,7 @@ void find_obb(const PolygonMesh& pmesh,
find_obb(pmesh, obbmesh, la_traits, use_ch);
}
}} // end namespaces
#endif //CGAL_OPTIMAL_BOUNDING_BOX_OBB_H
} // end namespace Optimal_bounding_box
} // end namespace CGAL
#endif // CGAL_OPTIMAL_BOUNDING_BOX_OBB_H

View File

@ -22,13 +22,14 @@
#ifndef CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H
#define CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H
#include <vector>
#include <CGAL/assertions.h>
#include <CGAL/Random.h>
#include <vector>
namespace CGAL {
namespace Optimal_bounding_box {
namespace Optimal_bounding_box {
template<typename Linear_algebra_traits>
class Population
@ -37,7 +38,8 @@ class Population
typedef std::vector<Matrix> Simplex;
public:
Population(std::size_t size) : n(size), random_generator(CGAL::Random())
Population(std::size_t size)
: n(size), random_generator(CGAL::Random())
{
// reserve pop space
pop.reserve(n);
@ -52,9 +54,9 @@ public:
}
}
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
void show_population();
#endif
#endif
std::size_t size(){return n;}
@ -72,7 +74,6 @@ public:
}
private:
// create random population
void create_simplex(Simplex& simplex)
{
@ -110,8 +111,7 @@ private:
std::vector<Simplex> pop;
};
#ifdef OBB_DEBUG
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
template <typename Matrix>
void Population<Matrix>::show_population()
{
@ -130,14 +130,7 @@ void Population<Matrix>::show_population()
}
#endif
} // end namespace Optimal_bounding_box
} // end namespace CGAL
} } // end namespaces
#endif //CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H
#endif // CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H

View File

@ -1,9 +1,8 @@
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/Optimal_bounding_box/nelder_mead_functions.h>
#include <CGAL/Optimal_bounding_box/fitness_function.h>
#include <CGAL/assertions.h>
#include <iostream>
#include <fstream>
#include <CGAL/Eigen_linear_algebra_traits.h>
bool assert_doubles(double d1, double d2, double epsilon)
{

View File

@ -1,14 +1,15 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Eigen_linear_algebra_traits.h>
#include <CGAL/Optimal_bounding_box/population.h>
#include <CGAL/Optimal_bounding_box/optimal_bounding_box.h>
#include <CGAL/Optimal_bounding_box/helper.h>
#include <iostream>
#include <fstream>
#include <CGAL/Eigen_linear_algebra_traits.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
bool assert_doubles(double d1, double d2, double epsilon)
@ -195,7 +196,7 @@ void test_random_unit_tetra()
Point p4(0.166461, 0.149912, 0.364944);
CGAL::make_tetrahedron(p1, p2, p3, p4, mesh);
#ifdef OBB_DEBUG_TEST
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
std::ofstream out("data/random_unit_tetra.off");
out << mesh;
out.close();
@ -221,7 +222,7 @@ void test_random_unit_tetra()
CGAL_assertion(assert_doubles(R(2,1), 0.512847, epsilon));
CGAL_assertion(assert_doubles(R(2,2), 0.836992, epsilon));
#ifdef OBB_DEBUG_TEST
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
// postprocessing
CGAL::Eigen_dense_matrix<double> obb(8, 3);
CGAL::Optimal_bounding_box::post_processing(data_points, R, obb);
@ -235,7 +236,7 @@ void test_reference_tetrahedron(const char* fname)
CGAL::Surface_mesh<K::Point_3> mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
typedef CGAL::Eigen_linear_algebra_traits Linear_algebra_traits;
@ -255,7 +256,7 @@ void test_reference_tetrahedron(const char* fname)
CGAL_assertion_code(double epsilon = 1e-5);
CGAL_assertion(assert_doubles(Linear_algebra_traits::determinant(R), 1, epsilon));
#ifdef OBB_DEBUG_TEST
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
// postprocessing
MatrixXd obb(8, 3);
CGAL::Optimal_bounding_box::post_processing(points, R, obb);
@ -269,7 +270,7 @@ void test_long_tetrahedron(std::string fname)
CGAL::Surface_mesh<K::Point_3> mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
typedef CGAL::Eigen_linear_algebra_traits Linear_algebra_traits;
@ -300,7 +301,7 @@ void test_long_tetrahedron(std::string fname)
assert_doubles(R(1,2), -0.707106, epsilon));
CGAL_assertion(assert_doubles(R(2,2), 0.707107, epsilon));
#ifdef OBB_DEBUG_TEST
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
// postprocessing
MatrixXd obb(8, 3);
CGAL::Optimal_bounding_box::post_processing(points, R, obb);
@ -315,7 +316,7 @@ void test_find_obb_evolution(std::string fname)
SMesh mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
// get mesh points
std::vector<K::Point_3> sm_points;
@ -334,7 +335,7 @@ void test_find_obb_evolution(std::string fname)
CGAL_assertion_code(double vol = CGAL::Optimal_bounding_box::calculate_volume(obb_points));
CGAL_assertion(assert_doubles(vol, 0.883371, epsilon));
#ifdef OBB_DEBUG_TEST
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
/*
for(int i = 0; i < 8; ++i)
std::cout << obb_points[i].x() << " " << obb_points[i].y() << " " << obb_points[i].z() << "\n" ;
@ -353,16 +354,17 @@ void test_find_obb_mesh(std::string fname)
{
std::ifstream input(fname);
CGAL::Surface_mesh<K::Point_3> mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
if (!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
CGAL::Eigen_linear_algebra_traits la_traits;
CGAL::Surface_mesh< K::Point_3> obbmesh;
CGAL::Optimal_bounding_box::find_obb(mesh, obbmesh, la_traits, true);
#ifdef OBB_DEBUG_TEST
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
std::ofstream out("/tmp/result_elephant.off");
out << obbmesh;
out.close();
@ -373,16 +375,18 @@ void test_function_defaults_traits(std::string fname1, std::string fname2)
{
std::ifstream input1(fname1);
CGAL::Surface_mesh<K::Point_3> mesh1;
if (!input1 || !(input1 >> mesh1) || mesh1.is_empty()) {
if (!input1 || !(input1 >> mesh1) || mesh1.is_empty())
{
std::cerr << fname1 << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
std::ifstream input2(fname2);
CGAL::Surface_mesh<K::Point_3> mesh2;
if (!input2 || !(input2 >> mesh2) || mesh2.is_empty()) {
if (!input2 || !(input2 >> mesh2) || mesh2.is_empty())
{
std::cerr << fname2 << " is not a valid off file.\n";
exit(1);
std::exit(1);
}
// test one
@ -391,6 +395,7 @@ void test_function_defaults_traits(std::string fname1, std::string fname2)
typedef typename boost::graph_traits<SMesh>::vertex_descriptor vertex_descriptor;
typedef typename boost::property_map<SMesh, boost::vertex_point_t>::const_type PointPMap;
PointPMap pmap = get(boost::vertex_point, mesh1);
BOOST_FOREACH(vertex_descriptor v, vertices(mesh1))
sm_points.push_back(get(pmap, v));