From 000a4f9be02fec03ec0bcd5f52533f7f0ad6a314 Mon Sep 17 00:00:00 2001 From: Esteban DUGUEPEROUX Date: Sat, 6 Apr 2024 13:28:11 +0200 Subject: [PATCH] Add geogram --- recipes/geogram/all/conandata.yml | 19 ++ recipes/geogram/all/conanfile.py | 122 ++++++++ ...E_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch | 0 .../geogram/all/test_package/CMakeLists.txt | 11 + recipes/geogram/all/test_package/conanfile.py | 27 ++ recipes/geogram/all/test_package/input.ply | 16 + .../geogram/all/test_package/test_package.cpp | 278 ++++++++++++++++++ recipes/geogram/config.yml | 5 + 8 files changed, 478 insertions(+) create mode 100644 recipes/geogram/all/conandata.yml create mode 100644 recipes/geogram/all/conanfile.py create mode 100644 recipes/geogram/all/patches/0001-Map-VORPALINE_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch create mode 100644 recipes/geogram/all/test_package/CMakeLists.txt create mode 100644 recipes/geogram/all/test_package/conanfile.py create mode 100644 recipes/geogram/all/test_package/input.ply create mode 100644 recipes/geogram/all/test_package/test_package.cpp create mode 100644 recipes/geogram/config.yml diff --git a/recipes/geogram/all/conandata.yml b/recipes/geogram/all/conandata.yml new file mode 100644 index 00000000000000..7b711e00ba237b --- /dev/null +++ b/recipes/geogram/all/conandata.yml @@ -0,0 +1,19 @@ +sources: + "1.9.0": + url: + - "https://github.com/BrunoLevy/geogram/releases/download/v1.9.0/geogram_1.9.0.tar.gz" + sha256: "09c0e28ffc08fdab1f2214ee32e49610d64972d052e890d3cc6dcb6bd25b5fc0" + "1.8.8": + url: + - "https://github.com/BrunoLevy/geogram/releases/download/v1.8.8/geogram_1.8.8.tar.gz" + sha256: "698bc9ad9d58139fe9fdf3eab0596f5b418c4edd593eee960de98c0ab646d47e" +patches: + "1.1.0": + - patch_file: "patches/0001-fix-cmake.patch" + patch_description: "correct the order of cmake min and project" + patch_type: "backport" + patch_source: "https://github.com/owner/package/pulls/42" + - patch_file: "patches/0002-fix-linux.patch" + patch_description: "add missing header to support linux" + patch_type: "portability" + patch_source: "https://github.com/owner/package/issues/0" diff --git a/recipes/geogram/all/conanfile.py b/recipes/geogram/all/conanfile.py new file mode 100644 index 00000000000000..2d52bf8d206a7e --- /dev/null +++ b/recipes/geogram/all/conanfile.py @@ -0,0 +1,122 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.microsoft import check_min_vs, is_msvc +from conan.tools.scm import Version +import os + +required_conan_version = ">=1.53.0" + +class GeogramConan(ConanFile): + name = "geogram" + description = "A programming library with geometric algorithms" + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/BrunoLevy/geogram" + topics = ("graphics programming", "mesh generation", "geometry processing", "graphics libraries", "mesh processing") + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_graphics": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_graphics": True, + } + + package_type = "library" + short_paths = True + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + if self.options.with_graphics: + # self.requires("xorg/system") + self.requires("glfw/3.3.8") + # self.requires("imgui/cci.20230105+1.89.2.docking") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["VORPALINE_BUILD_DYNAMIC"] = self.options.shared + tc.variables["GEOGRAM_WITH_GRAPHICS"] = self.options.with_graphics + tc.variables["GEOGRAM_LIB_ONLY"] = False + # To use glfw from conan cache + tc.variables["GEOGRAM_USE_SYSTEM_GLFW3"] = True + # tc.variables["GEOGRAM_SUB_BUILD"] = True + tc.variables["GEOGRAM_WITH_LEGACY_NUMERICS"] = False + + tc.generate() + + tc = CMakeDeps(self) + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.verbose = True + cmake.build(cli_args=["--verbose"], build_tool_args=["-j 10"]) + # cmake.build() + + def package(self): + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + + # some files extensions and folders are not allowed. Please, read the FAQs to get informed. + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) + rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "Geogram") + + if self.options.with_graphics: + self.cpp_info.components["geogram_gfx"].includedirs = ["include/geogram1"] + self.cpp_info.components["geogram_gfx"].libs = ["geogram_gfx"] + self.cpp_info.components["geogram_gfx"].requires = ["geogram", "glfw::glfw"] + self.cpp_info.components["geogram_gfx"].set_property("cmake_target_name", "Geogram::geogram") + + # self.cpp_info.components["geogram_num_3rdparty"].includedirs = ["include/geogram1"] + # self.cpp_info.components["geogram_num_3rdparty"].libs = ["geogram_num_3rdparty"] + # self.cpp_info.components["geogram_num_3rdparty"].set_property("cmake_target_name", "Geogram::geogram_num_3rdparty") + + self.cpp_info.components["geogram"].includedirs = ["include/geogram1"] + self.cpp_info.components["geogram"].libs = ["geogram"] + self.cpp_info.components["geogram"].set_property("cmake_target_name", "Geogram::geogram") + if not self.options.shared: + openmp_flags = [] + if is_msvc(self): + openmp_flags = ["-openmp"] + elif self.settings.compiler in ("gcc", "clang"): + openmp_flags = ["-fopenmp"] + elif self.settings.compiler == "apple-clang": + openmp_flags = ["-Xpreprocessor", "-fopenmp"] + self.cpp_info.components["geogram"].sharedlinkflags = openmp_flags + self.cpp_info.components["geogram"].exelinkflags = openmp_flags + + # If they are needed on Linux, m, pthread and dl are usually needed on FreeBSD too + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("m") + self.cpp_info.system_libs.append("pthread") + self.cpp_info.system_libs.append("dl") diff --git a/recipes/geogram/all/patches/0001-Map-VORPALINE_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch b/recipes/geogram/all/patches/0001-Map-VORPALINE_BUILD_DYNAMIC-to-BUILD_SHARED_LIBS.patch new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/recipes/geogram/all/test_package/CMakeLists.txt b/recipes/geogram/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..5ac37a6f45e89b --- /dev/null +++ b/recipes/geogram/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) + +project(test_package CXX) + +find_package(Geogram REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +# don't link to ${CONAN_LIBS} or CONAN_PKG::package +target_link_libraries(${PROJECT_NAME} PRIVATE Geogram::geogram) +# In case the target project need a specific C++ standard +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) \ No newline at end of file diff --git a/recipes/geogram/all/test_package/conanfile.py b/recipes/geogram/all/test_package/conanfile.py new file mode 100644 index 00000000000000..ba3e8338516838 --- /dev/null +++ b/recipes/geogram/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +# It will become the standard on Conan 2.x +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package input.ply") + self.run(bin_path, env="conanrun") diff --git a/recipes/geogram/all/test_package/input.ply b/recipes/geogram/all/test_package/input.ply new file mode 100644 index 00000000000000..87ba8546d03d83 --- /dev/null +++ b/recipes/geogram/all/test_package/input.ply @@ -0,0 +1,16 @@ +ply +format ascii 1.0 +comment this is our first comment +element vertex 3 +property float x +property float y +property float z +element face 1 +property list uchar int vertex_indices +comment this is our last comment +end_header +-1 0 0 +000 1 0 +1 0000 0 +3 1 00000 2 +3 1 0 2 diff --git a/recipes/geogram/all/test_package/test_package.cpp b/recipes/geogram/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..e9635273e4b88a --- /dev/null +++ b/recipes/geogram/all/test_package/test_package.cpp @@ -0,0 +1,278 @@ +// Copied from https://github.com/BrunoLevy/geogram/blob/main/src/tests/test_RVC/main.cpp +/* + * Copyright (c) 2000-2022 Inria + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the ALICE Project-Team nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Contact: Bruno Levy + * + * https://www.inria.fr/fr/bruno-levy + * + * Inria, + * Domaine de Voluceau, + * 78150 Le Chesnay - Rocquencourt + * FRANCE + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace { + + using namespace GEO; + + /** + * \brief Creates a surfacic mesh from a cube. + * \param[out] M the resulting mesh + */ + void initialize_mesh_with_box(Mesh& M) { + M.clear(); + M.vertices.set_dimension(3); + + const double d = 1.0; + + M.vertices.create_vertex(vec3(-d, -d, -d).data()); + M.vertices.create_vertex(vec3(-d, -d, d).data()); + M.vertices.create_vertex(vec3(-d, d, -d).data()); + M.vertices.create_vertex(vec3(-d, d, d).data()); + M.vertices.create_vertex(vec3(d, -d, -d).data()); + M.vertices.create_vertex(vec3(d, -d, d).data()); + M.vertices.create_vertex(vec3(d, d, -d).data()); + M.vertices.create_vertex(vec3(d, d, d).data()); + + M.facets.create_quad(7,6,2,3); + M.facets.create_quad(1,3,2,0); + M.facets.create_quad(5,7,3,1); + M.facets.create_quad(4,6,7,5); + M.facets.create_quad(4,5,1,0); + M.facets.create_quad(6,4,0,2); + + M.facets.connect(); + } + + void center_scale_mesh(Mesh& M, vec3 center, double radius) { + double xyz_min[3]; + double xyz_max[3]; + get_bbox(M, xyz_min, xyz_max); + double scale = 2.0*radius / Geom::distance(xyz_min, xyz_max, 3); + vec3 g = 0.5*(vec3(xyz_min) + vec3(xyz_max)); + for(index_t i=0; i degree(M.vertices.nb(),0); + for(index_t f=0; fset_quiet(false); + GEO::CmdLine::import_arg_group("standard"); + GEO::CmdLine::import_arg_group("algo"); + GEO::CmdLine::declare_arg_percent("size", 10.0, "elements size, in bbox diagonal percent"); + GEO::CmdLine::declare_arg("shrink", 0.9, "cells shrink"); + GEO::CmdLine::declare_arg("border_only", false, "output only RVC facets on the border"); + + std::vector filenames; + if(!GEO::CmdLine::parse(argc, argv, filenames, "points_filename ")) { + return 1; + } + + if(filenames.size() != 1 && filenames.size() != 2) { + return 1; + } + + GEO::Mesh points; + GEO::MeshIOFlags flags; + flags.reset_element(GEO::MESH_FACETS); + flags.reset_element(GEO::MESH_CELLS); + GEO::mesh_load(filenames[0], points, flags); + GEO::mesh_repair(points); + + double diag = GEO::bbox_diagonal(points); + double size = GEO::CmdLine::get_arg_percent("size",diag); + double shrink = GEO::CmdLine::get_arg_double("shrink"); + bool border_only = GEO::CmdLine::get_arg_bool("border_only"); + + // Since we compute restricted Voronoi cells one cell at a + // time, the mesh argument of the restricted Voronoi diagram + // is not used. + GEO::Mesh dummy_mesh; + + // Create a Delaunay API that encapsulates a Kd-tree + GEO::Delaunay_var delaunay = Delaunay::create(3,"NN"); + delaunay->set_vertices(points.vertices.nb(), points.vertices.point_ptr(0)); + + GEO::RestrictedVoronoiDiagram_var RVD = + GEO::RestrictedVoronoiDiagram::create(delaunay, &dummy_mesh); + + GEO::Mesh cell; + GEO::Mesh clipped; + GEO::Attribute facet_id; + if(border_only) { + facet_id.bind(clipped.facets.attributes(),"id"); + } + + if(filenames.size() == 2) { + mesh_load(filenames[1],cell); + } else { + initialize_mesh_with_box(cell); + } + + if(!mesh_vertices_are_degree_3(cell)) { + Logger::err("RVC") << "Mesh vertices are not all of degree 3" << std::endl; + exit(-1); + } + + if(mesh_facets_are_planar(cell)) { + Logger::out("RVC") << "Mesh facets are planar (good)" << std::endl; + } else { + Logger::warn("RVC") << "Mesh facets are not planar" << std::endl; + } + + std::ofstream out("RVC.obj"); + index_t offset = 1; + + index_t progress_divider = + (points.vertices.nb() > 10000) ? 100 : 1; + + GEO::ProgressTask task("RVC.obj",points.vertices.nb()/progress_divider); + // For each point, create a cube centered on the point + // and clip it with the Voronoi cell of the point. + for(GEO::index_t i=0; icompute_RVC(i,cell,clipped,facet_id.is_bound()); + + if(shrink != 1.0) { + shrink_mesh(clipped, shrink); + } + + // Append the generated mesh to the output mesh. + for(index_t j=0; j= 0) { + continue; + } + out << "f "; + for(index_t c=clipped.facets.corners_begin(f); c