Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Meshing implicit surfaces creates inside out meshes.

Subject: CGAL users discussion list

List archive

[cgal-discuss] Meshing implicit surfaces creates inside out meshes.


Chronological Thread 
  • From: Raphael Grimm <>
  • To: <>
  • Subject: [cgal-discuss] Meshing implicit surfaces creates inside out meshes.
  • Date: Tue, 12 Jun 2018 11:31:19 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:tJtCARWh0p/TTBvjK2lfd8jWAj7V8LGtZVwlr6E/grcLSJyIuqrYYxyCt8tkgFKBZ4jH8fUM07OQ7/i9HzRYqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba9yIRmssQndqtQdjJd/JKo21hbHuGZDdf5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXMTRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KptVRTmijoINyQh/W/XlMJ+kaFVrhyvqBNw34HUYZqYNPVicq7HYd4WWWRMU8RXWidcAo28dYwPD+8ZMOhEtYb9v1sOogGgCgmoGejhyyVIhn7z3a0/zu8sFhvG0xY4H9IOqnvbstH1OL0dUeCvzanIyDDDYuhV2Tf89IjEaA4uruyRXb9pd8fa1EchFwTAjlqKqIzlOSuY1ucMs2iH9eZvS/+gi3MhpgpsoTav3t8hhpTXio8R0FzI6Ct0zJwrKdC2VUJ3e92pHIZIuy2HOIZ6X9kuTm9ytCs5ybAKo562cSYMxZ863RDQceaHfJKN4h/7VOaePzN4hHV9dbKkmxm97VGsyujmWcm11FZKqTdFksXVunAO1hzT9tGLRudg8ku7wjaAyxzc5vtHIUA1iarXMYAuzaMtlpYLsETDGDH5mFnugaOLaEkp/vKk5/npb7n8uJOROZJ4hhv9P6gzgsC/BP43MgkKX2iV4+S807jj8FXjQLpQlv02krPWv47eJcgBqa65GQ5V0oMm6xukDDem0cgYkWMZI11YZRKLl5LpNE3WIPDkEfe/hEyhnytkx//cOr3tG4jCLnnYkLj9YLZ98FVcxREozdFf4pJUEqsOLOjyWk/3rtzYDwU2Pxa6w+b9W51B0dZKUm2GBuqVMbjZrESTzuMpOeiFIoEP7mXTMf8gssTnlX8wlFtVUrOo2J5fPGqxBvRvLkHfbmDth9IpEmYW+AcyUbq52xW5TTdPaiPqDOoH7TYhBdf+VNaRdsWWmLWEmRyDMNhTb2FCBEqLFCa6dISYHfoAdXDLe5Mzonk/TbGkDrQZ+1S2rgarmblmMqzZ9jBK7cu+hugw3PXakFQJzRIxD8mZ1DrXHXp/lSYNTj4y271j5E981hLbiO5jiPceFt1Pof5FT1ViOA==

Hi,
i am meshing implicit surfaces and sometimes the result is inside out (the vertex order of triangles is wrong).

I attached three meshes and the code to show what i mean:
 *  'sphere_r_const_1_1.000000.off' is correct
 *  'sphere_r_const_2_1.000000.off' is inside out
 *  'sphere_r_const_4096_1.000000.off' is correct

In both cases i meshed a unit sphere.
The only difference when creating the spheres is the squared radius i passed to 'Sphere_3' when creating my 'CGAL::Implicit_mesh_domain_3'.
The first sphere got the exact squared radius '1' and the second the larger value '2' and the third the value '4096'.
Hence i the issue can't be a too large bounding sphere.

Why does this happen and how can i prevent this?

Best regards,

Raphael

--
Karlsruhe Institute of Technology (KIT)
Institute for Anthropomatics and Robotics (IAR)
High Performance Humanoid Technologies (H2T)

Raphael Grimm (M.Sc.)
Research Scientist

Adenauerring 2
Building 50.20, Room 334
76131 Karlsruhe, Germany

Phone: +49 721 608-47133
Fax: +49 721 608-48270
Email:

Web: http://h2t.anthropomatik.kit.edu/

KIT - The Research University in the Helmholtz Association

Attachment: sphere_r_const_1_1.000000.off
Description: model/geomview-off

Attachment: sphere_r_const_2_1.000000.off
Description: model/geomview-off

#include <iostream>
#include <fstream>
#include <chrono>

#include <boost/filesystem.hpp>

#include <CGAL/Surface_mesh.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Mesh_triangulation_3.h>
#include <CGAL/Mesh_criteria_3.h>
#include <CGAL/Implicit_mesh_domain_3.h>
#include <CGAL/make_mesh_3.h>
#include <CGAL/IO/facets_in_complex_3_to_triangle_mesh.h>

#define base_dir "example_output/cgal/mesh_implicit_spheres/"

static constexpr std::size_t n = 5;

int main()
{
    boost::filesystem::create_directories(base_dir);

    std::size_t it = 0;
    auto generate = [&](double r, auto rfunction, std::string name)
    {
        std::cout << "sphere " << it++ << " r = " << r << std::endl;

        const std::string file = base_dir "/sphere_" + name + "_" + std::to_string(r) + ".off";

        const auto beg = std::chrono::high_resolution_clock::now();

        using ResultType = CGAL::Surface_mesh<typename CGAL::Epick::Point_3>;
        // defining the surface
        using Point_3   = typename CGAL::Epick::Point_3 ;
        auto fn = [r](Point_3 p)
        {
            return CGAL::squared_distance(p, Point_3(CGAL::ORIGIN))-r;
        };

        using impl_mesh = CGAL::Implicit_mesh_domain_3<decltype(fn), CGAL::Epick>;
        impl_mesh impl(fn, CGAL::Epick::Sphere_3(CGAL::ORIGIN, rfunction(r)));

        using Traits = typename CGAL::Mesh_triangulation_3<impl_mesh, CGAL::Default, CGAL::Sequential_tag>::type;
        using C3t3 = typename CGAL::Mesh_complex_3_in_triangulation_3<Traits>;

        // defining meshing criteria
        CGAL::Mesh_criteria_3<Traits> criteria(
            CGAL::parameters::facet_angle            = 30,
            CGAL::parameters::facet_size             = 0.1,
            CGAL::parameters::facet_distance         = 0.025,
            CGAL::parameters::cell_radius_edge_ratio = 2,
            CGAL::parameters::cell_size              = 0.1
        );
        // meshing surface
        C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(impl, criteria);

        ResultType mesh;
        CGAL::facets_in_complex_3_to_triangle_mesh(c3t3, mesh);

        const auto end = std::chrono::high_resolution_clock::now();
        const auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(end - beg);
        std::cout << "    time: " << delta.count() << " ms" << std::endl;

        std::ofstream{file} << mesh;
    };

//    auto r_pow_2_add_1 = [](auto r){return r * r + 1;};
//    auto r_mul_2_pow_2 = [](auto r){return (2*r) * (2*r);};


    auto r_const = [](auto r){return [r](auto){return r;};};

//    generate(1, r_const(0.5), "r_const_0.5"); //crashes
    generate(1, r_const(1), "r_const_1");
    generate(1, r_const(2), "r_const_2");
    generate(1, r_const(4096), "r_const_4096");
//    generate(1, r_const(4), "r_const_4");
//    generate(1, r_const(8), "r_const_8");

//    for(std::size_t i = 0; i < 21; ++i)
//    {
//        generate(1 + 0.05*i, r_pow_2_add_1, "r_pow_2_add_1");
//        generate(1 + 0.05*i, r_mul_2_pow_2, "r_mul_2_pow_2");
//    }
//    for(std::size_t i = 0; i < 20; ++i)
//    {
//        generate(1 - 0.05*i, r_pow_2_add_1, "r_pow_2_add_1");
//        generate(1 - 0.05*i, r_mul_2_pow_2, "r_mul_2_pow_2");
//    }
    return 0;
}

Attachment: sphere_r_const_4096_1.000000.off
Description: model/geomview-off

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature




Archive powered by MHonArc 2.6.18.

Top of Page