glyg / cgal4py

A fork of Meagan Lang's cgal4py repository, adapted to python 3
2 stars 1 forks source link

building 'cgal4py.delaunay.delaunay2' extension #1 #1

Closed krober10nd closed 4 years ago

krober10nd commented 4 years ago

Hey,

I tried getting in contact with Megan, but to not avail. This software represents practically the only package for parallel delaunay triangulation in python!

When building by source on Mac with -std=gnu++14 using gcc, I receive the following error. I suspect it's related to the length of unint64_t and long long on my Mac OSX but it's odd. On my ubuntu machine, it compiles fine.

any idea how to fix it? Thanks

building 'cgal4py.delaunay.delaunay2' extension gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/miniconda3/include -arch x86_64 -I/Applications/miniconda3/include -arch x86_64 -DNPY_NO_DEPRECATED_API -DCGAL_EIGEN3_ENABLED=1 -Icgal4py/delaunay -I./cgal4py/delaunay -I/Applications/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/usr/local/Cellar/eigen/3.3.7/include/eigen3 -I/usr/local/Cellar/boost/1.72.0 -I/Applications/miniconda3/include/python3.7m -c cgal4py/delaunay/delaunay2.cpp -o build/temp.macosx-10.9-x86_64-3.7/cgal4py/delaunay/delaunay2.o -std=gnu++14 cgal4py/delaunay/delaunay2.cpp:22501:44: error: no matching member function for call to 'serialize_info2idx' pyx_v_idx_inf = pyx_v_self->T->serialize_info2idx(pyx_v_n, pyx_v_m, pyx_v_d, (&(*__Pyx_BufPtrStrided2d(pyx_t_5numpy_uint...


cgal4py/delaunay/c_delaunay2.hpp:944:5: note: candidate function template not viable: no known conversion from '__pyx_t_5numpy_uint64_t *'
(aka 'unsigned long *') to 'unsigned long long ' for 4th argument
I serialize_info2idx(I &n, I &m, int32_t &d,
^
cgal4py/delaunay/delaunay2.cpp:22629:11: error: no matching function for call to 'sortSerializedTess'
sortSerializedTess<uint64_t>((&(__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint64_t *, __pyx_pybuffernd_cells.rcbuffer->pybuffer.buf, __pyx_t_18...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgal4py/delaunay/c_tools.hpp:201:6: note: candidate function template not viable: no known conversion from '__pyx_t_5numpy_uint64_t *' (aka 'unsigned long *')
to 'unsigned long long *' for 1st argument
void sortSerializedTess(I *cells, I *neigh,
^
2 errors generated.
glyg commented 4 years ago

Hi Keith,

Looks like the numpy unsigned 64 int and the cpp unsigned long long can't talk to each other - I don't know why. I've abandoned the idea to interface cgal and python with cython, and we are now using pybind11 for that, see for example here - it 'just' calls the point creation algorithm, but the code is much closer to CGAL examples, and it's easier to setup (less boiler plate) than Cython

If you can look into the __init__.py file above , you'll see how it is imported like a regular module, provided you build the extension, which is managed in setup.py.

This software represents practically the only package for parallel delaunay triangulation in python!

Yeah I know, I searched too :-/ If you're interested, we could setup an independant package based on pybind11 - just Delaunay triangulation for now, but setting up a clear (modern) workflow to interface CGAL to Python is surely something interesting.

tell me what you think

Best

Guillaume

krober10nd commented 4 years ago

Hey Guillaume,

Yes, I prefer using pybind11 over cython these days. I was browsing the cgal4py code and noticed it would have taken forever to learn. The amount of boilerplate code is tremendous.

I recently took up a project building 2 and 3D tria. meshes for seismological studies and it requires some pretty large meshes, which is what brought me here. I would definitely be interested in setting up a clear workflow interface to CGAL (to just Dela.).

I guess we could start by following the script you linked to? In general, just simply calling dela. and getting back an element connectivity table would be extremely helpful. In fact MATLAB does this already but we can't see their code.

Also, there's another python package cgal-swig-bindings, but they don't have any way to simply return the element face table and it's also filled with a bunch of extremely complex functionality.

Thanks for the quick response! Let me see what I can do today. I can start a repo and invite you.

glyg commented 4 years ago

Hey Keith,

Cool! Sure go ahead and create a repo! I agree with you that simply passing points as a numpy ndarray and getting connectivity back is already super usefull. Maybe we can copy the structure of scipy's Delaunay class? https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html#scipy.spatial.Delaunay

I'm aware of the the SWIG bindings, but SWIG is a nightmare to use... I am not sure it is maintained very effectively either...

krober10nd commented 4 years ago

Sweet, yes, I got the same impression from the CGAL-swig bindings. I followed along your example with using pybind11 and cmake...just the roots here. I will work on it today. I'll give you push permission.

https://github.com/krober10nd/simple_cgal

glyg commented 4 years ago

Great, I'll update the README here to point to this project!

I'll check on the code - tell me if you need anything

krober10nd commented 4 years ago

I finished up for today. Added support for 2d and 3d meshing from python using CGAL. Give it points, returns connectivity table.

Needs some cleaning but it works.