#include <iostream>
#include <chrono>
#include <type_traits>
#include <typeinfo>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/HDVF/Hdvf_traits_3.h>
#include <CGAL/HDVF/Simplex.h>
#include <CGAL/HDVF/Simplicial_chain_complex.h>
#include <CGAL/HDVF/Cubical_chain_complex.h>
#include <CGAL/HDVF/Geometric_chain_complex_tools.h>
#include <CGAL/HDVF/Hdvf.h>
#include <CGAL/OSM/OSM.h>
#include <CGAL/OSM/Sparse_chain.h>
#include <CGAL/HDVF/Mesh_object_io.h>
#include <CGAL/HDVF/Cub_object_io.h>
#include <CGAL/HDVF/Hdvf_tools.h>
#include "arguments.h"
using Traits = HDVF::Hdvf_traits_3<Kernel>;
template <typename MeshType, typename Complex>
void mesh_complex_output(
const MeshType& mesh,
const Complex& complex,
const Options& options)
{
if (options.with_output)
{
std::cout << "----> mesh informations" << std::endl ;
mesh.print_infos() ;
std::cout << "----> complex informations" << std::endl;
std::cout << complex;
}
}
template <typename Complex>
HDVF::Hdvf<Complex>& HDVF_comput (
const Complex& complex,
const Options &options)
{
HDVF::Hdvf<Complex>& hdvf(*(new HDVF::Hdvf<Complex>(complex, options.HDVF_opt)));
std::vector<HDVF::Cell_pair> pairs ;
if (!options.random)
pairs = hdvf.compute_perfect_hdvf(options.verbose);
else
pairs = hdvf.compute_rand_perfect_hdvf(options.verbose);
if (options.with_output)
{
std::cout << "----> pairs found by computePerfectHDVF" << std::endl ;
std::cout << pairs ;
std::cout << "----> reduction" << std::endl ;
hdvf.write_reduction() ;
}
if (options.with_export)
{
std::string file(options.outfile_root+"_reduction.txt") ;
std::ofstream out ( file, std::ios::out | std::ios::trunc);
if ( ! out . good () ) {
std::cerr << "hdvf: with_export. Fatal Error:\n " << file << " not found.\n";
throw std::runtime_error("File Parsing Error: File not found");
}
out << "----> pairs found by computePerfectHDVF" << std::endl ;
out << pairs ;
out << "----> reduction" << std::endl ;
hdvf.write_reduction(out) ;
out.close() ;
}
return hdvf ;
}
template <typename Coefficient_ring>
void main_code (const Options &options)
{
if (options.in_format == InputFormat::SIMP)
{
using Complex = HDVF::Abstract_simplicial_chain_complex<Coefficient_ring> ;
using HDVF_type = HDVF::Hdvf<Complex> ;
HDVF::Mesh_object_io<Traits> mesh ;
mesh.read_simp(options.in_file) ;
mesh_complex_output<HDVF::Mesh_object_io<Traits>,
Complex>(mesh, complex, options) ;
HDVF_type hdvf(HDVF_comput<Complex>(complex, options)) ;
}
else if (options.in_format == InputFormat::OFF)
{
using Complex = HDVF::Simplicial_chain_complex<Coefficient_ring, Traits> ;
using HDVF_type = HDVF::Hdvf<Complex> ;
HDVF::Mesh_object_io<Traits> mesh ;
mesh.read_off(options.in_file) ;
mesh_complex_output<HDVF::Mesh_object_io<Traits>,
Complex>(mesh, complex, options) ;
HDVF_type hdvf(HDVF_comput<Complex>(complex, options)) ;
if (options.loop)
{
auto output_vtk_simp = [options](HDVF_type &hdvf,
Complex& complex)
{
CGAL::IO::write_VTK(hdvf, complex, options.outfile_root, options.co_faces) ;
} ;
HDVF::interaction_loop<Complex>(hdvf, complex, output_vtk_simp) ;
}
else if (options.with_vtk_export)
{
std::cout << "----> exporting to vtk" << std::endl ;
CGAL::IO::write_VTK(hdvf, complex, options.outfile_root, options.co_faces) ;
}
}
else if ((options.in_format == InputFormat::PGM) || (options.in_format == InputFormat::CUB))
{
using Complex = HDVF::Cubical_chain_complex<Coefficient_ring, Traits> ;
using HDVF_type = HDVF::Hdvf<Complex> ;
HDVF::Cub_object_io<Traits> mesh ;
typename Complex::Cubical_complex_primal_dual primal_dual(Complex::PRIMAL) ;
if (options.primal)
{
if (options.in_format == InputFormat::PGM)
mesh.read_pgm(options.in_file, true) ;
else
mesh.read_cub(options.in_file, true) ;
}
else
{
if (options.in_format == InputFormat::PGM)
mesh.read_pgm(options.in_file, false) ;
else
mesh.read_cub(options.in_file, false) ;
primal_dual = Complex::DUAL ;
}
Complex complex(mesh, primal_dual);
mesh_complex_output<HDVF::Cub_object_io<Traits>,
Complex>(mesh, complex, options) ;
HDVF_type hdvf(HDVF_comput<Complex>(complex, options)) ;
if (options.loop)
{
auto output_vtk_cub = [options](HDVF_type &hdvf,
Complex& complex)
{
CGAL::IO::write_VTK(hdvf, complex, options.outfile_root, options.co_faces) ;
} ;
HDVF::interaction_loop<Complex>(hdvf, complex, output_vtk_cub) ;
}
else if (options.with_vtk_export)
{
std::cout << "----> exporting to vtk" << std::endl ;
CGAL::IO::write_VTK(hdvf, complex, options.outfile_root, options.co_faces) ;
}
}
}
int main(int argc, char **argv)
{
if (argc <= 2)
usage() ;
else
{
for (int i=0;i<argc; ++i)
std::cout << "arg " << i << " : " << argv[i] << std::endl ;
Options options(read_arguments_hdvf(argc, argv)) ;
std::cout << "options:" << std::endl << options ;
std::cout << "TEST" << std::endl ;
std::cout << "before: " << gamma.is_null() << std::endl ;
gamma.set_coefficient(2, 1) ;
std::cout << "after: " << gamma.is_null() << std::endl ;
gamma.set_coefficient(2, 0) ;
std::cout << "after2: " << gamma.is_null() << std::endl ;
std::cout << "END TEST" << std::endl ;
#ifndef SCALAR
if (options.scalar == 0)
{
main_code<Coefficient_ring>(options) ;
}
else if (options.scalar == 2)
{
main_code<Coefficient_ring>(options) ;
}
else
{
std::cerr << "Z" << options.scalar << " not instantiated, use the #define at line 27" << std::endl ;
}
#else
#endif
}
return 0 ;
}
The class Sparse_chain implements the concept SparseChain, that is, sparse vectors (encoding homologi...
Definition: Sparse_chain.h:52
The concept HDVF describes the requirements for Homological Discrete Vector Fields (HDVF for short) ,...
Definition: HDVF.h:128
Complex::Coefficient_ring Coefficient_ring
Type of coefficients used to compute homology.
Definition: HDVF.h:139
unspecified_type Complex
Type of underlying chain complex (a model of AbstractChainComplex).
Definition: HDVF.h:136
Definition: Abstract_simplicial_chain_complex.h:25