Skip to content

Instantly share code, notes, and snippets.

@afabri
Created October 25, 2023 09:45
Show Gist options
  • Save afabri/f435935346b0d7e917d515ba3513ac88 to your computer and use it in GitHub Desktop.
Save afabri/f435935346b0d7e917d515ba3513ac88 to your computer and use it in GitHub Desktop.
Example for read_VTK()
cmake_minimum_required(VERSION 3.1...3.23)
project(Stroman)
# CGAL and its components
find_package(CGAL REQUIRED)
create_single_source_cgal_program("readVTK.cpp")
find_package(VTK QUIET COMPONENTS vtkCommonCore vtkIOCore vtkIOLegacy vtkIOXML vtkFiltersCore vtkFiltersSources)
if (VTK_FOUND)
if(VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()
if ("${VTK_VERSION_MAJOR}" GREATER "5" OR VTK_VERSION VERSION_GREATER 5)
if(TARGET VTK::CommonCore)
set(VTK_LIBRARIES VTK::CommonCore VTK::IOCore VTK::IOLegacy VTK::IOXML VTK::FiltersCore VTK::FiltersSources)
endif()
if(VTK_LIBRARIES)
target_link_libraries(readVTK PRIVATE ${VTK_LIBRARIES})
target_compile_definitions(readVTK PRIVATE -DCGAL_USE_VTK -DNOMINMAX)
else()
message(STATUS "Tests that use VTK will not be compiled.")
endif()
endif()
endif() #VTK_FOUND
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/IO/VTK.h>
#include <array>
#include <vector>
#
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Mesh;
typedef std::vector<std::size_t> Face;
typedef std::vector<Face> Faces;
typedef std::vector<Point_3> Points;
int main(int argc, char* argv[])
{
Points points;
Faces faces;
CGAL::IO::read_VTK(argv[1], points, faces);
std::cout << points.size() << " " << faces.size() << std::endl;
CGAL::Polygon_mesh_processing::orient_polygon_soup(points, faces);
Mesh mesh;
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, faces, mesh);
CGAL::IO::write_polygon_mesh("mesh.off", mesh, CGAL::parameters::stream_precision(17));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment