cgal icon indicating copy to clipboard operation
cgal copied to clipboard

remesh_almost_planar_patches,What about returning an empty mesh

Open kuaiqushangzixiba opened this issue 2 years ago • 7 comments

Return empty mesh What is going on, I tried many mesh, some can return simplified mesh, some return empty mesh, some return the original input mesh, what is going on in the end? How can you guarantee that a simplified mesh is returned

bool success = PMP::remesh_almost_planar_patches(sm,
    out,
    nb_regions, nb_corners,
    CGAL::make_random_access_property_map(region_ids),
    CGAL::make_random_access_property_map(corner_id_map),
    CGAL::make_random_access_property_map(ecm),
    CGAL::parameters::patch_normal_map(normal_map));

kuaiqushangzixiba avatar Nov 09 '23 08:11 kuaiqushangzixiba

could you please provide an example mesh with parameters you used (and the example you used)? Did you check the bool returned value?

sloriot avatar Nov 09 '23 17:11 sloriot

like example diplodocus.off

    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\elephant-with-holes.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\man.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\building.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\bear.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\pig.stl");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\refined_elephant.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\bunny00.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\diplodocus.off");
    baishi("E:\\cppThree\\CGAL-5.6\\data\\meshes\\armadillo.off");

I tried a lot of ply, as well as off in the example folder, the return value 0 and 1, can't see any pattern, some will return itself, some will return a simplified mesh, some will return an empty mesh

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/remesh_planar_patches.h>
#include <CGAL/Polygon_mesh_processing/region_growing.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/random_perturbation.h>
#include <boost/property_map/vector_property_map.hpp>
#include <iostream>
#include <fstream>
#include <iostream>
#include <chrono>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <cstdio>
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Surface_mesh<Kernel::Point_3> Surface_mesh;

namespace PMP = CGAL::Polygon_mesh_processing;
int baishi(const std::string& filename)
{
    Surface_mesh sm;
    CGAL::IO::read_polygon_mesh(CGAL::data_file_path(filename), sm);

    std::cout << sm.number_of_vertices() << std::endl;
    std::vector<std::pair<unsigned, unsigned>> selfIntersections;
    PMP::self_intersections(sm, std::back_inserter(selfIntersections));
    std::cout << selfIntersections.size()  << std::endl;

    // declare vectors to store mesh properties
    std::vector<std::size_t> region_ids(num_faces(sm));
    std::vector<std::size_t> corner_id_map(num_vertices(sm), -1); // corner status of vertices
    std::vector<bool> ecm(num_edges(sm), false); // mark edges at the boundary of regions
    boost::vector_property_map<CGAL::Epick::Vector_3> normal_map; // normal of the supporting planes of the regions detected

    // detect planar regions in the mesh
    std::size_t nb_regions =
        PMP::region_growing_of_planes_on_faces(sm,
            CGAL::make_random_access_property_map(region_ids),
            CGAL::parameters::cosine_of_maximum_angle(0.89).
            region_primitive_map(normal_map).
            maximum_distance(0.0003));

    std::cout << nb_regions << "regions  ";

    // detect corner vertices on the boundary of planar regions
    std::size_t nb_corners =
        PMP::detect_corners_of_regions(sm,
            CGAL::make_random_access_property_map(region_ids),
            nb_regions,
            CGAL::make_random_access_property_map(corner_id_map),
            CGAL::parameters::cosine_of_maximum_angle(0.9).
            maximum_distance(0.0003).
            edge_is_constrained_map(CGAL::make_random_access_property_map(ecm)));
    std::cout << nb_corners << "corners  " << std::endl;
    //run the remeshing algorithm using filled properties
    Surface_mesh out;
    bool success = PMP::remesh_almost_planar_patches(sm,
        out,
        nb_regions, nb_corners,
        CGAL::make_random_access_property_map(region_ids),
        CGAL::make_random_access_property_map(corner_id_map),
        CGAL::make_random_access_property_map(ecm),
        CGAL::parameters::patch_normal_map(normal_map));

    CGAL::IO::write_polygon_mesh(filename.substr(0, filename.size() - 4) += "_test.ply", out);
    std::cout << success << std::endl;
    std::cout << out.number_of_vertices() << std::endl;
    std::cout << std::endl;
    return 0;
}

image

It seems that when bool is 1, it can be simplified with high probability (sometimes it can't), but how can we guarantee that boo is 1? Is there any requirement on the input ply?

kuaiqushangzixiba avatar Nov 10 '23 02:11 kuaiqushangzixiba

I noticed that remesh_planar_patches has input requirements and can't handle non-manifold vertices. Does remesh_almost_planar_patches also have input requirements?

kuaiqushangzixiba avatar Nov 13 '23 02:11 kuaiqushangzixiba

Also, the function only works if maximum_distance(0.0003) is very small, which makes it nearly impossible to handle any input mesh

kuaiqushangzixiba avatar Nov 13 '23 02:11 kuaiqushangzixiba

I will have a closer look at why the meshing part in failing as soon as I can. In the meantime, considering the input meshes you've been trying, the following package seems better suited (since they do not really have planar parts).

sloriot avatar Nov 13 '23 14:11 sloriot

Ok, looking forward to your progress

kuaiqushangzixiba avatar Dec 04 '23 07:12 kuaiqushangzixiba