You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CGAL读取ModelNet40的.off文件时部分文件返回0顶点0面

CGAL读取ModelNet40部分.off文件异常问题

问题现象

我编写了一个简单的CGAL .off文件读取程序,用于读取ModelNet40数据集的airplane_0001.off和airplane_0002.off文件(两个文件均未做任何修改):

  • 读取airplane_0001.off时一切正常,控制台输出:
    airplane_0001.off

    Initial Vertices: 90714
    Initial Edges: 193500

  • 读取airplane_0002.off时,surface_mesh的顶点数和边数均返回0,控制台输出:
    airplane_0002.off

    Initial Vertices: 0
    Initial Edges: 0

使用Python的Open3D测试这两个文件,均可正常读取并获取正确的网格数据:

  • airplane_0001.off输出:
    airplane_0001.off

    TriangleMesh with 90714 points and 104773 triangles.

  • airplane_0002.off输出:
    airplane_0002.off

    TriangleMesh with 94335 points and 118614 triangles.

相关代码

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)

内容的提问来源于stack exchange,提问作者K. Zhu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 17:46:08