CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.93k stars 1.38k forks source link

sdf_values: Crash when computing sdf values of some meshes #1092

Closed mickey9294 closed 8 years ago

mickey9294 commented 8 years ago

I'm using CGAL-4.8 to compute sdf values of a 3D mesh shape according to Computation of SDF Values. But when I compute some of meshes the program crashes, and throws a Precondition_exception. I can't figure out what's going on. The mesh files are in the attachments. Since off file cannot be uploaded, I change the format of three mesh files from .off to .txt. Please change them back to .off file after downloading. And the code I use is as below:

#include <iostream>
#include <cstdlib>
#include <string>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/mesh_segmentation.h>
#include <CGAL/property_map.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::Halfedge_around_facet_const_circulator Halfedge_facet_circulator;

using namespace CGAL;
using namespace std;

void sdf(const char *filename);

int main()
{
    sdf("error_meshes/225.off");

    system("PAUSE");
    return 0;
}

void sdf(const char *filename)
{
    // create and read Polyhedron
    Polyhedron mesh;
    string a(filename);

    std::ifstream input(filename);
    if (!input || !(input >> mesh) || mesh.empty())
    {
        std::cerr << "Not a valid off file." << std::endl; 
        return;
    }
    // create a property-map
    typedef std::map<Polyhedron::Facet_const_handle, double> Facet_double_map;
    Facet_double_map internal_map;
    boost::associative_property_map<Facet_double_map> sdf_property_map(internal_map);

    //std::pair<double, double> min_max = CGAL::sdf_values(mesh, sdf_vertex_map);
    // compute SDF values
    //std::pair<double, double> min_max_sdf = CGAL::sdf_values(mesh, sdf_property_map);
    // It is possible to compute the raw SDF values and post-process them using
    // the following lines:
    const std::size_t number_of_rays = 100;  // cast 25 rays per facet
    const double cone_angle = 45.0 / 180.0 * CGAL_PI; // set cone opening-angle
    CGAL::sdf_values(mesh, sdf_property_map, cone_angle, number_of_rays, false);
    std::pair<double, double> min_max_sdf =
        CGAL::sdf_values_postprocessing(mesh, sdf_property_map);
    // print minimum & maximum SDF values
    std::cout << "minimum SDF: " << min_max_sdf.first
        << " maximum SDF: " << min_max_sdf.second << std::endl;
    // print SDF values
    for (Polyhedron::Facet_const_iterator facet_it = mesh.facets_begin();
        facet_it != mesh.facets_end(); ++facet_it)
    {
        std::cout << sdf_property_map[facet_it] << std::endl;
    }
    std::cout << std::endl;
}

205.txt 225.txt 245.txt

Attention: When running the demo, please change the format of 205.txt, 225.txt and 245.txt to 205.off, 225.off and 245.off, and put them in the project directory!

sloriot commented 8 years ago

The models all contain degenerate faces which is why you see the precondition failing (it should tell you that a triangle is degenerated). From what I saw, it comes from 2 edges that are of length 0 in each mesh.

sloriot commented 8 years ago

I opened #1094 as a feature request and closed this issue