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



问题

下面是一个简单的CGAL.off读取应用程序。我试图分别读取ModelNet40/airplane/train/airplane_0001.offModelNet40/airplane/train/airplane_0002.off,但ModelNet40/airplane/train/airplane_0002.off给出了一个具有0个顶点和0个面的surface_mesh

这两个关闭文件来自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代码

抽取.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.

不能只使用operator>>(),因为网格具有孤立的顶点和非流形边。相反,您必须阅读多边形汤,确定三角形的方向,并在必要时复制边,以便获得一个2倍的、可能是硬边的边界边。请参阅用户手册中的此示例。

或直接使用read_polygon_mesh()

相关内容

  • 没有找到相关文章

最新更新