Reputation: 418
Here's a simple CGAL .off
read application. I was trying to read ModelNet40/airplane/train/airplane_0001.off
and ModelNet40/airplane/train/airplane_0002.off
respectively, but ModelNet40/airplane/train/airplane_0002.off
gives a surface_mesh
with 0 vertices and 0 faces.
Those two off file are from ModelNet40 without any modifications.
# console output for airplane_0001.off
Initial Vertices: 90714
Initial Edges: 193500
# console output for airplane_0002.off
Initial Vertices: 0
Initial Edges: 0
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)
import open3d as o3d
path = "ModelNet40/airplane/train/airplane_0002.off"
mesh = o3d.io.read_triangle_mesh(path)
print(mesh)
I tested both files using open3d.io.read_triangle_mesh(path)
in python and both of them are ok, but it gives 0 vertices and 0 faces in CGAL.
Result in 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.
Upvotes: 0
Views: 176
Reputation: 1235
You cannot just use operator>>()
because your mesh has isolated vertices and non-manifold edges. You must instead read a polygon soup, orient the triangles and if necessary duplicate edges so that you obtain a 2-manifold, potentially wirh border edges. Have a look at this example in the User Manual.
Or use directly read_polygon_mesh()
Upvotes: 1