-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
191 lines (178 loc) · 7.29 KB
/
setup.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env python
import setuptools
from setuptools import setup, find_packages
from setuptools.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
import os
import numpy
import platform
import sys
import urllib
try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve
import zipfile
import glob
import shutil
extra_include_dirs = [numpy.get_include(), '../functions/']
extra_library_dirs = []
extra_compile_args = []
extra_link_args = []
extra_libraries = ['survos_cuda']
if platform.system() == 'Windows':
extra_compile_args += ['/DWIN32']
elif platform.system() == 'Darwin':
extra_compile_args += [ '-O2', '-Wall']
extra_library_dirs += ['.']
extra_libraries += ['m']
else:
extra_compile_args += [ '-O2', '-Wall', '-std=c99']
extra_library_dirs += ['.']
extra_libraries += ['m']
base_path = os.path.abspath(os.path.dirname(__file__))
source_path = os.path.join(base_path, 'survos', 'lib', 'qpbo_src')
def apply_QPBO_fix(qpbo_dir):
content = []
with open(os.path.join(qpbo_dir,'instances.inc'),"r") as f:
content = f.readlines()
content.insert(8, "template <>")
content.insert(9, "inline void QPBO<int>::get_type_information(const char*& type_name, const char*& type_format);")
content.insert(10, "template <>")
content.insert(11, "inline void QPBO<float>::get_type_information(const char*& type_name, const char*& type_format);")
content.insert(12, "template <>")
content.insert(13, "inline void QPBO<double>::get_type_information(const char*& type_name, const char*& type_format);")
with open(os.path.join(qpbo_dir,'instances.inc'),"w") as f:
f .writelines(content)
def get_qpbo():
if os.path.isdir(source_path):
return
else:
os.mkdir(source_path)
qpbo_version = 'QPBO-v1.4.src'
qpbo_file = '{}.zip'.format(qpbo_version)
urlretrieve('http://pub.ist.ac.at/~vnk/software/{}'.format(qpbo_file), qpbo_file)
with zipfile.ZipFile(qpbo_file) as zf:
zf.extractall(source_path)
for f in glob.glob(os.path.join(source_path, qpbo_version, '*')):
shutil.move(f, os.path.dirname(os.path.dirname(f)))
os.rmdir(os.path.join(source_path, qpbo_version))
os.remove(qpbo_file)
#Apply patch for Mac
if platform.system() == 'Darwin':
apply_QPBO_fix(source_path)
get_qpbo()
qpbo_directory = source_path
files = ["QPBO.cpp", "QPBO_extra.cpp", "QPBO_maxflow.cpp",
"QPBO_postprocessing.cpp"]
files = [os.path.join(qpbo_directory, f) for f in files]
extra_include_dirs += [qpbo_directory]
print(extra_include_dirs)
extensions = [
Extension("survos.lib._channels",
sources = ["survos/lib/_channels.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._preprocess",
sources = ["survos/lib/_preprocess.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._convolutions",
sources = ["survos/lib/_convolutions.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._dist",
sources = ["survos/lib/_dist.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._features",
sources = ["survos/lib/_features.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._rag",
sources = ["survos/lib/_rag.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._spencoding",
sources = ["survos/lib/_spencoding.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._superpixels",
sources = ["survos/lib/_superpixels.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._supersegments",
sources = ["survos/lib/_supersegments.pyx",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
Extension("survos.lib._qpbo",
sources = ["survos/lib/_qpbo.pyx",
"survos/lib/qpbo_src/QPBO.cpp",
"survos/lib/qpbo_src/QPBO_extra.cpp",
"survos/lib/qpbo_src/QPBO_maxflow.cpp",
"survos/lib/qpbo_src/QPBO_postprocessing.cpp",
],
include_dirs = extra_include_dirs,
library_dirs = extra_library_dirs,
extra_compile_args = extra_compile_args,
libraries = extra_libraries,
extra_link_args = extra_link_args),
]
setup(
name = 'survos',
version = "1.5.3",
description = '(Su)per (R)egion (Vo)lume (S)egmentation workbench',
license='GPL',
packages = find_packages(),
include_package_data=True,
install_requires=['numpy','scipy','matplotlib'],
zip_safe = False,
ext_modules = cythonize(extensions, language='c++'),
package_data={'survos.images':['survos/images/*.png',],
'survos.images.PNG':['survos/images/PNG/*.png',],
'survos.images.SVG':['survos/images/SVG/*.svg',],
'survos.launcher':['survos/launcher/*.qcs',],
},
entry_points={
'console_scripts': [
'SuRVoS=survos.launcher.survos_launcher:main'
],
},
)