#include <iostream>
#include <chrono>
#include <type_traits>
#include <typeinfo>
#include <CGAL/HDVF/Zp.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_persistence.h>
#include <CGAL/OSM/OSM.h>
#include <CGAL/HDVF/hdvf_tools.h>
#include <CGAL/HDVF/Mesh_object_io.h>
#include <CGAL/HDVF/Cub_object_io.h>
#include "arguments.h"
#ifndef CUST_FILTRATION
using DegType = double ;
#else
using DegType = double ;
#endif
#ifdef CUST_FILTRATION
template<typename ComplexType>
std::function<DegType(int)> deg_fun (const ComplexType& complex)
{
std::function<DegType(int)> deg_fun_f = [&complex](int i)
{
const std::vector<double> Xi(complex.get_vertex_coords(i)) ;
return Xi.at(0)+Xi.at(2) ;
} ;
return deg_fun_f ;
}
#endif
template <typename MeshType, typename ComplexType>
void mesh_complex_output(const MeshType& mesh, const ComplexType& complex, const Options& options)
{
if (options.with_output)
{
std::cout << "----> mesh informations" << std::endl ;
mesh.print_infos() ;
std::cout << "----> complex informations" << std::endl ;
complex.print_complex();
}
}
template<typename CoefficientType, typename ComplexType, typename DegType, typename FiltrationType >
{
HDVFType& hdvf(*(new HDVFType(complex, f, options.HDVF_opt, options.with_vtk_export)));
std::cout << "----> START computing persistent homology" << std::endl ;
hdvf.compute_perfect_hdvf() ;
std::cout << "------> END computing persistent homology" << std::endl ;
if (options.with_output)
{
std::cout << "----> perHDVF" << std::endl ;
hdvf.print_hdvf_persistence_info(std::cout);
std::cout << "----> reduction" << std::endl ;
hdvf.print_reduction() ;
std::cout << "----> persistent diagram" << std::endl ;
std::cout << hdvf ;
}
if (options.with_export)
{
std::cout << "----> exporting..." << std::endl ;
std::string file(options.outfile_root+"_reduction.txt") ;
std::ofstream out ( file, std::ios::out | std::ios::trunc);
if ( not 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 << "----> perHDVF" << std::endl ;
hdvf.print_hdvf_persistence_info(out);
out << "----> reduction" << std::endl ;
hdvf.print_reduction(out) ;
out.close() ;
std::string file_per(options.outfile_root+"_per.txt") ;
std::ofstream out_per ( file_per, std::ios::out | std::ios::trunc);
if ( not out_per . good () ) {
std::cerr << "hdvf: with_export. Fatal Error:\n " << file << " not found.\n";
throw std::runtime_error("File Parsing Error: File not found");
}
out_per << "----> persistent diagram" << std::endl ;
out_per << hdvf ;
out_per.close() ;
}
return hdvf ;
}
template<typename CoefficientType, typename ComplexType, typename DegType, typename FiltrationType>
FiltrationType& build_filtration(const ComplexType& complex, const Options& options)
{
std::function<DegType(size_t)> deg_function ;
#ifndef CUST_FILTRATION
if (options.star_filtr == StarFiltrStd::FiltrX)
else if (options.star_filtr == StarFiltrStd::FiltrY)
else if (options.star_filtr == StarFiltrStd::FiltrZ)
else
{
std::cout << "Unknown lower start filtration" << std::endl ;
throw("Unknown lower start filtration") ;
}
#else
deg_function = (
deg_fun(complex)) ;
#endif
std::cout << "----> START building filtration" << std::endl ;
std::cout << "------> END building filtration" << std::endl ;
return f ;
}
template <typename CoefficientType>
void main_code (const Options &options)
{
if (options.in_format == InputFormat::SIMP)
{
std::cout << "not yet..." << std::endl ;
throw("not yet") ;
}
else if (options.in_format == InputFormat::OFF)
{
FiltrationType& f(build_filtration<CoefficientType, ComplexType, DegType, FiltrationType>(complex, options)) ;
mesh_complex_output<CGAL::HDVF::Mesh_object_io, ComplexType>(mesh, complex, options) ;
HDVFType& hdvf(per_HDVF_comput<CoefficientType,ComplexType,DegType, FiltrationType>(complex,f, options)) ;
if (options.with_vtk_export)
{
std::cout << "----> exporting to vtk" << std::endl ;
}
}
else if ((options.in_format == InputFormat::PGM) || (options.in_format == InputFormat::CUB))
{
typename ComplexType::typeComplexCube primal_dual(ComplexType::PRIMAL) ;
if (options.primal)
{
if (options.in_format == InputFormat::PGM)
else
}
else
{
if (options.in_format == InputFormat::PGM)
else
primal_dual = ComplexType::DUAL ;
}
ComplexType complex(mesh, primal_dual);
mesh_complex_output<CGAL::HDVF::Cub_object_io, ComplexType>(mesh, complex, options) ;
FiltrationType& f(build_filtration<CoefficientType, ComplexType, DegType, FiltrationType>(complex, options)) ;
HDVFType& hdvf(per_HDVF_comput<CoefficientType,ComplexType,DegType,FiltrationType>(complex,f, options)) ;
if (options.with_vtk_export)
{
std::cout << "----> exporting to vtk" << std::endl ;
}
}
}
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 ;
#ifndef SCALAR
if (options.scalar == 0)
{
using CoefficientType = int ;
main_code<CoefficientType>(options) ;
}
else if (options.scalar == 2)
{
main_code<CoefficientType>(options) ;
}
else
{
std::cerr << "Z" << options.scalar << " not instantiated, use the #define at line 27" << std::endl ;
}
#else
#endif
}
return 0 ;
}
The class Cub_object_io is an intermediate IO class, used to load binary volumes and produce cubical ...
Definition: Cub_object_io.h:44
bool read_cub(const std::string &filename, bool khalimsky=false)
Definition: Cub_object_io.h:173
bool read_pgm(const std::string &filename, bool khal=false)
Definition: Cub_object_io.h:97
The class Cubical_chain_complex represents (topological) chain complexes associated to cubical comple...
Definition: Cubical_chain_complex.h:93
The class Filtration_lower_star implements the lower star filtration on a given complex implementing ...
Definition: Filtration_lower_star.h:103
The class Hdvf_persistence computes persistent homology using HDVFs.
Definition: Hdvf_persistence.h:145
The class Mesh_object_io is an intermediate IO class, used to load triangular/tetraedral meshes and p...
Definition: Mesh_object_io.h:201
std::vector< std::vector< double > > get_nodes()
Definition: Mesh_object_io.h:321
bool read_off(const std::string &filename)
Definition: Mesh_object_io.h:369
The class Simplicial_chain_complex refines the Abstract_simplicial_chain_complex class by assigning c...
Definition: Simplicial_chain_complex.h:42
The class Zp implements the concept Ring with the field .
Definition: Zp.h:39
The concept Filtration describes the requirements for persistent filtrations associated to persistent...
Definition: Filtration.h:25
void hdvf_persistence_geometric_chain_complex_output_vtk(Hdvf_persistence< CoefType, ComplexType, DegType, FiltrationType > &per_hdvf, ComplexType &complex, string filename="per", bool co_faces=false)
Exports all the HDVF_persistence information of a geometric chain complex to vtk files.
Definition: Geometric_chain_complex_tools.h:132
std::function< double(const std::vector< double > &)> f_y
For lower star filtration along y: function mapping coordinates to y.
Definition: Filtration_lower_star.h:49
std::function< double(const std::vector< double > &)> f_x
For lower star filtration along x: function mapping coordinates to x.
Definition: Filtration_lower_star.h:43
std::function< double(size_t)> deg_fun(const ComplexType &complex, std::function< double(const vector< double > &)> &f)
Degree function from a coordinates to scalar map.
Definition: Filtration_lower_star.h:62
std::function< double(const std::vector< double > &)> f_z
For lower star filtration along z: function mapping coordinates to z.
Definition: Filtration_lower_star.h:55