c++ CGAL:读取文件导致0个顶点和0个面

dm7nw8vv  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(355)

问题

下面是一个简单的CGAL .off读取应用程序。我试图分别读取ModelNet40/airplane/train/airplane_0001.offModelNet40/airplane/train/airplane_0002.off,但是ModelNet40/airplane/train/airplane_0002.off给出了一个surface_mesh,其中0个顶点和0个面。
这两个文件来自ModelNet40,没有任何修改。

# console output for airplane_0001.off
Initial Vertices: 90714
Initial Edges: 193500
# console output for airplane_0002.off
Initial Vertices: 0
Initial Edges: 0

问题CGAL代码

decimation.cpp

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
// Simplification function
#include <CGAL/Surface_mesh_simplification/edge_collapse.h>
// Visitor base
#include <CGAL/Surface_mesh_simplification/Edge_collapse_visitor_base.h>
// Stop-condition policy
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_predicate.h>
#include <iostream>
#include <fstream>
typedef CGAL::Simple_cartesian<double>                                  Kernel;
typedef Kernel::Point_3                                                 Point_3;
typedef CGAL::Surface_mesh<Point_3>                                     Surface_mesh;
typedef boost::graph_traits<Surface_mesh>::halfedge_descriptor          halfedge_descriptor;
typedef boost::graph_traits<Surface_mesh>::vertex_descriptor            vertex_descriptor;
namespace SMS = CGAL::Surface_mesh_simplification;
typedef SMS::Edge_profile<Surface_mesh>                                 Profile;

int main(int argc, char ** argv)
{
    Surface_mesh surface_mesh;
    const std::string filename = CGAL::data_file_path(argv[1]);
    std::cout << filename << std::endl;
    std::ifstream is(filename);
    if(!is || !(is >> surface_mesh))
    {
        std::cerr << "Failed to read input mesh: " << filename << std::endl;
        return EXIT_FAILURE;
    }
    if(!CGAL::is_triangle_mesh(surface_mesh))
    {
        std::cerr << "Input geometry is not triangulated." << std::endl;
        return EXIT_FAILURE;
    }
    std::cout << "Initial Vertices: " << surface_mesh.number_of_vertices() << std::endl
              << "Initial Edges: " << surface_mesh.number_of_edges() << std::endl;

    return EXIT_SUCCESS;
}

CMakeLists.txt

project(modelnet40)
cmake_minimum_required(VERSION 3.23.0)
set(CMAKE_BUILD_TYPE Release)

find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt5)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(OpenGL)

include_directories(${OPENGL_INCLUDE_DIR})

add_executable(modelnet40 decimation.cpp)

set(CMAKE_CXX_FLAGS "-DCGAL_USE_BASIC_VIEWER")
target_link_libraries(modelnet40 CGAL::CGAL CGAL::CGAL_Basic_viewer)

在Python中测试

import open3d as o3d
path = "ModelNet40/airplane/train/airplane_0002.off"
mesh = o3d.io.read_triangle_mesh(path)
print(mesh)

我在python中使用open3d.io.read_triangle_mesh(path)测试了这两个文件,它们都很好,但是在CGAL中给出了0个顶点和0个面。
Python中的结果

# console for airplane_0001.off
TriangleMesh with 90714 points and 104773 triangles.
# console for airplane_0002.off
TriangleMesh with 94335 points and 118614 triangles.
41zrol4v

41zrol4v1#

你不能只使用operator>>(),因为你的网格有孤立的顶点和非流形的边。你必须读取一个多边形汤,定向三角形,如果必要的话复制边,这样你就可以得到一个2-流形,可能有边界边。在用户手册中可以看到这个例子。
或者直接使用read_polygon_mesh()

相关问题