-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_c.py
161 lines (138 loc) · 4.65 KB
/
setup_c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension
from setuptools.command.build_ext import build_ext
import numpy
import os
import glob
# Get the numpy include directory.
numpy_include_dir = numpy.get_include()
# Extensions
# pykdtree (kd tree)
pykdtree = Extension(
'im2mesh.utils.libkdtree.pykdtree.kdtree',
sources=[
'im2mesh/utils/libkdtree/pykdtree/kdtree.c',
'im2mesh/utils/libkdtree/pykdtree/_kdtree_core.c'
],
language='c',
extra_compile_args=['-std=c99', '-O3', '-fopenmp'],
extra_link_args=['-lgomp'],
)
# mcubes (marching cubes algorithm)
mcubes_module = Extension(
'im2mesh.utils.libmcubes.mcubes',
sources=[
'im2mesh/utils/libmcubes/mcubes.pyx',
'im2mesh/utils/libmcubes/pywrapper.cpp',
'im2mesh/utils/libmcubes/marchingcubes.cpp'
],
language='c++',
extra_compile_args=['-std=c++11'],
include_dirs=[numpy_include_dir]
)
# triangle hash (efficient mesh intersection)
triangle_hash_module = Extension(
'im2mesh.utils.libmesh.triangle_hash',
sources=[
'im2mesh/utils/libmesh/triangle_hash.pyx'
],
libraries=['m'] # Unix-like specific
)
# mise (efficient mesh extraction)
mise_module = Extension(
'im2mesh.utils.libmise.mise',
sources=[
'im2mesh/utils/libmise/mise.pyx'
],
)
# simplify (efficient mesh simplification)
simplify_mesh_module = Extension(
'im2mesh.utils.libsimplify.simplify_mesh',
sources=[
'im2mesh/utils/libsimplify/simplify_mesh.pyx'
]
)
# voxelization (efficient mesh voxelization)
voxelize_module = Extension(
'im2mesh.utils.libvoxelize.voxelize',
sources=[
'im2mesh/utils/libvoxelize/voxelize.pyx'
],
libraries=['m'] # Unix-like specific
)
# DMC extensions
dmc_pred2mesh_module = CppExtension(
'im2mesh.dmc.ops.cpp_modules.pred2mesh',
sources=[
'im2mesh/dmc/ops/cpp_modules/pred_to_mesh_.cpp',
]
)
dmc_cuda_module = CUDAExtension(
'im2mesh.dmc.ops._cuda_ext',
sources=[
'im2mesh/dmc/ops/src/extension.cpp',
'im2mesh/dmc/ops/src/curvature_constraint_kernel.cu',
'im2mesh/dmc/ops/src/grid_pooling_kernel.cu',
'im2mesh/dmc/ops/src/occupancy_to_topology_kernel.cu',
'im2mesh/dmc/ops/src/occupancy_connectivity_kernel.cu',
'im2mesh/dmc/ops/src/point_triangle_distance_kernel.cu',
]
)
# added to compile pointnet2_op_lib
this_dir = os.path.dirname(os.path.abspath(__file__))
_ext_src_root = os.path.join("im2mesh","utils", "pointnet2_ops_lib","pointnet2_ops", "_ext-src")
_ext_sources = glob.glob(os.path.join(_ext_src_root, "src", "*.cpp")) + glob.glob(
os.path.join(_ext_src_root, "src", "*.cu")
)
_ext_headers = glob.glob(os.path.join(_ext_src_root, "include", "*"))
pointnet2_cuda_module = CUDAExtension(
name="im2mesh.utils.pointnet2_ops_lib.pointnet2_ops._ext",
sources=_ext_sources,
extra_compile_args={
"cxx": ["-O3"],
"nvcc": ["-O3", "-Xfatbin", "-compress-all"],
},
include_dirs=[os.path.join(this_dir, _ext_src_root, "include")],
)
libpcd_src_root = os.path.join("im2mesh","utils", "lib_pointcloud_distance", )
libpcd_ext_sources = glob.glob(os.path.join(libpcd_src_root, "src", "*.cpp")) + glob.glob(
os.path.join(libpcd_src_root, "src", "*.cu")
)
lib_pointcloud_distance_module = CUDAExtension(
name="im2mesh.utils.lib_pointcloud_distance._ext",
sources=libpcd_ext_sources,
extra_compile_args={
"cxx": ["-O3", '-std=c++11'],
"nvcc": ["-O3", "-Xfatbin", "-compress-all"],
},
include_dirs=[os.path.join(libpcd_src_root, "include")],
)
MSN_utils_src_root = os.path.join("im2mesh","point_completion", "MSN_utils", )
MSN_utils_ext_sources = glob.glob(os.path.join(MSN_utils_src_root, "src", "*.cpp")) + glob.glob(
os.path.join(MSN_utils_src_root, "src", "*.cu")
)
lib_pointcloud_distance_module = CUDAExtension(
name="im2mesh.point_completion.MSN_utils._ext",
sources=MSN_utils_ext_sources,
extra_compile_args={
"cxx": ["-O3", '-std=c++11'],
"nvcc": ["-O3", "-Xfatbin", "-compress-all"],
},
include_dirs=[os.path.join(MSN_utils_src_root, "include")],
)
# Gather all extension modules
ext_modules = [
pykdtree,
]
setup(
ext_modules=cythonize(ext_modules),
include_dirs=[numpy.get_include()],
cmdclass={
'build_ext': build_ext
}
)