CGAL.jl icon indicating copy to clipboard operation
CGAL.jl copied to clipboard

Implement boolean set operations 2D

Open mathieu17g opened this issue 3 years ago • 7 comments

I would like to implement boolean set operation 2D. What do I have to do beyond declaring all functions present in header files with args and doctring ?

EDIT: I have found https://github.com/rgcv/libcgal-julia repository. I understand that I have to implement de wrapping there.

mathieu17g avatar Mar 14 '22 07:03 mathieu17g

Hi,

Yes, you'll see that the julia side of things is relatively superficial with some added conversions. Arguably, the bulk of it is in the libcgal-julia C++ wrapper that leverages libcxxwrap.

There is no straightforward answer other than to look at CGAL's documentation, see what functions and data structures/classes interest you, and map them, somewhat via a trial-and-error process, and test them.

I've been detached from this package a while now, but have been meaning to take another look at it. Plenty of things need to be done:

  • Update dependencies
  • Fix potential issues from the updates
  • Review updated dependencies to see if mapping became easier
  • Test against newer julia versions
  • Review CI
  • Build against libcxxwrap-julia's STL facilities (easier to map std::vectors than julia arrays outright)

The list could grow endlessly, but hopefully you'll understand why I haven't started re-tackling the package yet. Hopefully I'll find some time to sit down and take a proper look at the ecosystem again.

rgcv avatar Mar 15 '22 20:03 rgcv

Thanks for the guideline. I have looked into CxxWrap.jl. For now I have compiled the libcgal_julia_... libraries locally. I go on now by trying to make a locally working CGAL.jl to test some modifications before starting to contribute to your work.

The list could grow endlessly, but hopefully you'll understand why I haven't started re-tackling the package yet.

That's worrying. Could you elaborate ? I was betting that it would be faster to contribute to your work than to rewrite some of CGAL algorithms in Julia especially those using arrangements.

mathieu17g avatar Mar 16 '22 05:03 mathieu17g

That's worrying. Could you elaborate ?

Yes, I've since left academia and got a job. Sort of have been focusing more on that, and when I have free time, maintaining the package isn't someone that comes to the forefront of my mind. Though, when I'm reminded of it, there's a lot of stuff that I wish could be done about it. Ideally, this would first be a 1-to-1 mapping of CGAL, mounting some julian flourishes on top to make it more convenient.

The https://github.com/JuliaGeometry org has quite a few comprehensive list of packages that may also help out, though I'm not sure if there's anything to do with arrangements. Assuming you've checked there, I'm afraid I have lost some touch with the whole ecosystem so I'm not really up to speed on what's shiny and new or has built up enough of a repertoire that could fit your needs.

rgcv avatar Mar 16 '22 20:03 rgcv

@rgcv for information, I have finally managed to build a copy of CGAL_jll and libcgal_julia_jll based on CGAL 5.3.1 after a lot of trial and error:

(CGAL) pkg> st
    Project CGAL v0.5.3
     Status `~/.julia/dev/CGAL/Project.toml`
 [1f15a43c] CxxWrap v0.12.0
 [ae029012] Requires v1.3.0
 [a133c068] CGAL2_jll v5.3.1+0 `https://github.com/mathieu17g/CGAL2_jll.jl#main`
 [e0ff6fd9] libcgal2_julia_jll v0.18.7+0 `https://github.com/mathieu17g/libcgal2_jll.jl#main`

I'm now facing issues at the CGAL.jl stage. It does not precompile. The error messages are pretty limited for me now, but I have to get better acquainted with CxxWrap.jl. Here is below the error message if you have any advice to get into it. If not, I guess I may have first to duplicate CGAL_jll and libcgal_julia_jll based on CGAL 5.3.0 and start from there.

julia> using CGAL
[ Info: Precompiling CGAL [15fcbb24-5a00-427b-98c5-e32879a22884]
ERROR: LoadError: TypeError: in Type{...} expression, expected UnionAll, got a value of type Core.SimpleVector
Stacktrace:
  [1] top-level scope
    @ none:1
  [2] eval
    @ ./boot.jl:373 [inlined]
  [3] makereftype(#unused#::Type{CGAL.VoronoiDiagram2{CGAL.DelaunayTriangulation2}}, mod::Module)
    @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/ptbgM/src/CxxWrap.jl:660
  [4] wrap_reference_converters(julia_mod::Module)
    @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/ptbgM/src/CxxWrap.jl:676
  [5] wrapfunctions(jlmod::Module)
    @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/ptbgM/src/CxxWrap.jl:712
  [6] wrapmodule(so_path::String, funcname::Symbol, m::Module, flags::Nothing)
    @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/ptbgM/src/CxxWrap.jl:732
  [7] top-level scope
    @ ~/.julia/dev/CGAL/src/CGAL.jl:47
  [8] include
    @ ./Base.jl:418 [inlined]
  [9] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base ./loading.jl:1318
 [10] top-level scope
    @ none:1
 [11] eval
    @ ./boot.jl:373 [inlined]
 [12] eval(x::Expr)
    @ Base.MainInclude ./client.jl:453
 [13] top-level scope
    @ none:1
in expression starting at /Users/Mathieu/.julia/dev/CGAL/src/CGAL.jl:1

Could you explain to me the reason why you introduced Khepri?

mathieu17g avatar Apr 02 '22 05:04 mathieu17g

There seems to be an issue wrapping your libcgal_julia C++ lib. I haven't been keeping up with CxxWrap so I'm not sure what changed there that might cause the lib to break. Though, if v0.12 is being pulled, I'm guessing you compiled libcgal_julia against libcxxwrap_julia v0.9? If that isn't the case, I'd advise you to revise the dependency versions, try and rebuild libcgal_julia with the appropriate version and see if the error persists. If it does, I recommend checking what changed from libcxxwrap_julia v0.8 to v0.9. libcgal_julia is probably due some tweaking.

Could you explain to me the reason why you introduced Khepri?

Yes, this package (CGAL.jl) was birthed amidst my thesis work, The idea was to have this support Khepri.jl, an Algorithmic Design tool. To that end, I added some loosely coupled glue code that would allow for simple conversion to and fro Khepri types. However, that shouldn't impact you unless you are importing Khepri.

rgcv avatar Apr 02 '22 11:04 rgcv

Thanks for the hints. I have built against libcxxwrap_julia v0.9. Maybe it comes from CGAL-5.3.0 to CGAL-5.3.1 upgrade. Anyway, I have to better understand the C++ part in libcgal-julia.

mathieu17g avatar Apr 02 '22 13:04 mathieu17g

Hello, after a lengthy investigation using libcxxwrap_julia v0.9.1 and various versions of CGAL:

  • I built libcgal-julia locally but with boost version 1.78, the only version available via homebrew on macOS. CGAL.jl was working with this locally compiled version of libcgal-julia
  • While analyzing the differences between the version built via BinaryBuilder (with boost v1.76, GMP v6.2.1, and MPFR v4.1.1) and my local one, I was stuck trying to understand why libcxxwrap_julia got no jl_datatype_t value for VoronoiDiagram2 symbol with BinaryBuilder compiled version of libcgal-julia. I could not figure out how to use gdb to inspect the libcxxwrap_julia execution.
  • I came back to tinkering with CMake flags in build_tarballs.jl, falling back to apple Apple clang v10.0.0 from v12.0.0, ~and it worked~. I can't remember why I changed the Apple clang version. ~Therefore, the issue ERROR: LoadError: TypeError: in Type{...} expression, expected UnionAll, got a value of type Core.SimpleVector may simply come from boost v1.76 being only tested with Apple clang v10.0.0 (see https://www.boost.org/users/history/version_1_76_0.html)~

EDIT: It was a flash in the pan. It still does not work. I had forgotten to point back to the JLL version of libcgal-julia in CGAL.jl. It still does not work. I probably have to go back trying to debug the libcxxwrap_julia execution to find out what goes wrong in compilation with BinaryBuilder.jl cross-compiler...

Well, now:

  • ~I have something working now for macOS~
  • I have understood the hard way not to be sloppy with dependencies tested configurations, including compiler versions.
  • I have bettered my understanding of BinaryBuilder.jl, BinaryBuilderBase.jl, Cxxwrap.jl and libcxxwrap_julia

Next:

  • I will make some tests with my new working CGAL.jl regarding my geometry computations needs
  • I had some issues with boost, GMP, and MPFR dependencies version incompatibilities through BinaryBuilder.jl. I have had to modify BinaryBuilderBase.jl to sort it out. I will have to report an issue on BinaryBuilder.jl
  • I will relaunch building for all target platforms you had selected in your last version of build_tarballs.jl on Yggdrasil.jl to see if everything is working.

mathieu17g avatar May 02 '22 13:05 mathieu17g