Giter Site home page Giter Site logo

aalavandhaann / chenhan_cython Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 2.0 704 KB

Using cython instead of PyBind11 generated by Binder. Rather straightforward. I am giving up on Binder to generate the library for Windows. This attempt is to create PXD files and use autowrap to generate the PYX files. Looks promising so far.

License: GNU General Public License v3.0

C++ 91.42% Python 4.22% Cython 4.37%
python cython blender geodesics autowrap surface shortest-paths cpython mesh 3d 3d-modelling 3d-models geodesic-algorithm

chenhan_cython's Introduction

chenhancc

A Fast geodesic algorithm in python that spans across the surface through the polygons

Many Thanks

The original c++ source code was provided to me by Dr. Xin Shiqing (https://sites.google.com/site/xinshiqing/). My sincere thanks to him for his help

The algorithm is purely based on the paper of Shiqing who provided me with this wonderful c++ code as well. All I had to do was make some changes so it can be compiled as a python library. The timing or efficiency difference between the pure python implementation and c++ -> python conversion is atleast 210x times. </>

Xin SQ, Wang GJ. Improving Chen and Han's algorithm on the discrete geodesic problem. ACM Transactions on Graphics (TOG). 2009 Aug 1;28(4):104.

chenhan_cython

Using cython instead of PyBind11 generated by Binder. Rather straightforward. I am giving up on Binder to generate the pybind11 binding code for Windows. This attempt is to create PXD files and use autowrap to generate the PYX files. Looks promising so far.

Installation

Python Package Manager (PIP)

  • pip install py_chenhancc --user or
  • sudo pip install py_chenhancc (You need administration privileges)

Easy Install

easy_install --prefix $HOME/.local This is for ubuntu

Prerequesties

  • This code is compiled using cython and autowrap module to generate PYX files. There is no need to generate the PYX files yourself. It has been generated already for Windows and GCC systems

    *Github link for autowrap.

On any OS (Linux, OS X, MAC, Windows)

  • You can install using PIP
  • Do pip install py_chenhancc

ISSUES

  • Unix systems - Using pip install pip install py_chenhancc it would fail saying the command gcc failed with the compilation because of blah blah reason. I got it to work by exporting export CC=x86_64-linux-gnu-g++
  • Next if you notice it still fails after setting the above step ensure you have gcc version 4.9 atleast. Looks like gcc 4.8 is annoyed with std=c++14 flag in the compiler options. These two steps should figure you out.
  • Windows and Macintosh systems - I am finding it difficult to get my hands on a macintosh machine. Will soon test it and update all of you with what is necessary. If someone is kind enough to lend me a hand then please.

License

I haven't thought about it yet. The world is so strange that even free stuffs come at a cost. Did you notice that even for free licenses there are many variants to it? Anyways feel free to do things you want to after cloning the repository.

Demos

If you want to perform demos as shown in the screenshots above. Then after installing the sharedobject for chenhancc you should be also install another Blender plugin to see live paths on meshes. The link to the repository is here. Once you have installed the plugin then start clicking on the meshes and see paths between consecutive clicks.

Demos - Blender

You will find blender folder inside the demo folder. There is a blend file that can test a mesh loaded in the scene. Just ensure to load a mesh, select it with mouse and run the script (Alt-p). You should see a path between the selected vertices as supplied in the code in the text editor of Blender. In the below code change the svid and evid to change the vertex selection. svid is the seed vertex index, and evid is the target vertex index to which a path should be found.

#Replace the below Blender api imports with the framework of your choice. 
#The idea is to supply points, and face information for mesh representation
#inside the geodesics algorithm

#----------Blender based api modules import----------------
import bpy, bmesh;
from mathutils import Vector;
#----------End of Blender based api modules import----------------

from py_chenhancc import CBaseModel as BaseModel, CRichModel as RichModel, CPoint3D as Point3D, CFace as Face, CICHWithFurtherPriorityQueue as ICHWithFurtherPriorityQueue;


c = bpy.context;
m = c.active_object;
svid = 0;
evid = 20000;

def rotate(l, n):
    return l[n:] + l[:n];

def createPathMesh(points):
    myvertexlist = [[2,2,2],[4,4,4],[6,6,6],[8,8,8]]
    
    obName = "path_"+str(len(points));
    me = bpy.data.meshes.new(obName);
    ob = bpy.data.objects.new(obName, me);

    # Get a BMesh representation
    bm = bmesh.new();   # create an empty BMesh
    bm.from_mesh(me);   # fill it in from a Mesh

    # Modify the BMesh, can do anything here...
    for index, co in enumerate(points):
        v = bm.verts.new(co);
        v.index = index;
        
    bm.verts.ensure_lookup_table();
    
    for index, co in enumerate(points[1:]):
        v1 = bm.verts[index-1];
        v2 = bm.verts[index];
        e = bm.edges.new((v1, v2));
        
    
    # also add bm.edges and bm.faces

    # Finish up, write the bmesh back to the mesh
    bm.to_mesh(me);
    bm.free();  # free and prevent further access
    
    scn = bpy.context.scene;
    scn.objects.link(ob);
    scn.objects.active = ob;
    ob.select = True;


if(m):
    verts = [];
    faces = [];
    loops = m.data.loops;
    
    bmodel = RichModel();
    
    m.data.vertices[svid].select = True;
    m.data.vertices[evid].select = True;
    
    for v in m.data.vertices:
        p3d = Point3D(v.co.x, v.co.y, v.co.z);
        verts.append(p3d);
   
    for f in m.data.polygons:
        f_vids = [loops[lid].vertex_index for lid in f.loop_indices];        
        faces.append(Face(f_vids[0], f_vids[1], f_vids[2]));
    
    bmodel.LoadModel(verts, faces);
    bmodel.Preprocess();
    
    emethod = ICHWithFurtherPriorityQueue(bmodel, set([svid]));
    emethod.Execute();
    paths = emethod.FindSourceVertex(evid,[]);
    paths = rotate(paths, 1);
    
    path_verts = [];
    
    for epoint in paths:
        pt = epoint.Get3DPoint(bmodel);
        path_verts.append(Vector((pt.x, pt.y, pt.z)));
    createPathMesh(path_verts);
    print('DONE FOUND THE PATHS::: ');

chenhan_cython's People

Contributors

aalavandhaann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chenhan_cython's Issues

Cant install py-chenhancc package

Python Version: 3.8.2

Environment:
Package Version
autowrap 0.22.0
Cython 0.29.16
numpy 1.18.3
pip 20.0.2
setuptools 41.2.0

Error at "pip install py-chenhancc" :

Collecting py-chenhancc
  Using cached py_chenhancc-0.0.3.tar.gz (114 kB)
Requirement already satisfied: autowrap in c:\users\dk\documents\py_projekti\geodetka\venv\lib\site-packages (from py-chenhancc) (0.22.0)
Requirement already satisfied: Cython>=0.19 in c:\users\dk\documents\py_projekti\geodetka\venv\lib\site-packages (from autowrap->py-chenhancc) (0.29.16)
Installing collected packages: py-chenhancc
    Running setup.py install for py-chenhancc ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\dk\documents\py_projekti\geodetka\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dk\\AppData\\Local\\Temp\\pip-install-pwvvae1j\\py-chenhancc\\setup.py'"'"'; __file__='"'"'C:\\Users\\dk\\AppData\\Local\\Temp\\pip-install-pwvvae1j\\py-chenhancc\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\dk\AppData\Local\Temp\pip-record-ejgi8eiv\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\dk\documents\py_projekti\geodetka\venv\include\site\python3.8\py-chenhancc'
         cwd: C:\Users\dk\AppData\Local\Temp\pip-install-pwvvae1j\py-chenhancc\
    Complete output (53 lines):
    running install
    running build
    running build_ext
    building 'py_chenhancc' extension
    creating build
    creating build\temp.win-amd64-3.8
    creating build\temp.win-amd64-3.8\Release
    creating build\temp.win-amd64-3.8\Release\src
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\dk\documents\py_projekti\geodetka\venv\lib\site-packages\autowrap\data_files\autowrap -Ic:\users\dk\documents\py_projekti\geodetka\venv\lib\site-packages\autowrap\data_files -Ic:\users\dk\documents\py_projekti\geodetka\venv\include -IC:\Users\dk\AppData\Local\Programs\Python\Python38\include -IC:\Users\dk\AppData\Local\Programs\Python\Python38\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /EHsc /Tpsrc/py_chenhancc.cpp /Fobuild\temp.win-amd64-3.8\Release\src/py_chenhancc.obj -std=c++14
    cl : Command line warning D9002 : ignoring unknown option '-std=c++14'
    py_chenhancc.cpp
    C:\Users\dk\AppData\Local\Temp\pip-install-pwvvae1j\py-chenhancc\src\ICHWithFurtherPriorityQueue.hpp(189): warning C4244: '=': conversion from 'unsigned __int64' to 'double', possible loss of data
    src/py_chenhancc.cpp(21916): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21921): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21936): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21951): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21956): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21961): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21976): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(21991): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22006): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22021): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22026): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22029): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22032): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22035): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22038): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22041): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22044): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22047): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22050): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22053): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22056): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22059): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22062): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22065): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22068): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22071): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22074): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(22077): warning C4996: '_typeobject::tp_print': deprecated in 3.8
    src/py_chenhancc.cpp(23608): error C2039: 'exc_type': is not a member of '_ts'
    C:\Users\dk\AppData\Local\Programs\Python\Python38\include\cpython/pystate.h(51): note: see declaration of '_ts'
    src/py_chenhancc.cpp(23609): error C2039: 'exc_value': is not a member of '_ts'
    C:\Users\dk\AppData\Local\Programs\Python\Python38\include\cpython/pystate.h(51): note: see declaration of '_ts'
    src/py_chenhancc.cpp(23610): error C2039: 'exc_traceback': is not a member of '_ts'
    C:\Users\dk\AppData\Local\Programs\Python\Python38\include\cpython/pystate.h(51): note: see declaration of '_ts'
    src/py_chenhancc.cpp(23611): error C2039: 'exc_type': is not a member of '_ts'
    C:\Users\dk\AppData\Local\Programs\Python\Python38\include\cpython/pystate.h(51): note: see declaration of '_ts'
    src/py_chenhancc.cpp(23612): error C2039: 'exc_value': is not a member of '_ts'
    C:\Users\dk\AppData\Local\Programs\Python\Python38\include\cpython/pystate.h(51): note: see declaration of '_ts'
    src/py_chenhancc.cpp(23613): error C2039: 'exc_traceback': is not a member of '_ts'
    C:\Users\dk\AppData\Local\Programs\Python\Python38\include\cpython/pystate.h(51): note: see declaration of '_ts'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\dk\documents\py_projekti\geodetka\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dk\\AppData\\Local\\Temp\\pip-install-pwvvae1j\\py-chenhancc\\setup.py'"'"'; __file__='"'"'C:\\Users\\dk\\AppData\\Local\\Temp\\pip-install-pwvvae1j\\py-chenhancc\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\dk\AppData\Local\Temp\pip-record-ejgi8eiv\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\dk\documents\py_projekti\geodetka\venv\include\site\python3.8\py-chenhancc' Check the logs for full command output.

There should be some issue with with c++ 14
( Command line warning D9002 : ignoring unknown option '-std=c++14' )

Maybe something like this?
[https://github.com/tensorflow/tensorflow/issues/33618]

Any suggestion how to solve it?
Regards,
Dado

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.