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
|
__version__ = "2021.1.0"
__version_name__ = __version__
from distutils import util
import logging
import os
import sys
from .common import init, Backend
# sys.frozen is initialized by cx_Freeze and identifies a release package
isFrozen = getattr(sys, "frozen", False)
if not isFrozen:
# development mode: add git branch name (if any) to __version_name__
scriptPath = os.path.dirname(os.path.abspath(__file__))
headFilepath = os.path.join(scriptPath, "../.git/HEAD")
if os.path.exists(headFilepath):
with open(headFilepath, "r") as headFile:
data = headFile.readlines()
branchName = data[0].split('/')[-1].strip()
__version_name__ += "-" + branchName
# Allow override from env variable
__version_name__ = os.environ.get("REZ_MESHROOM_VERSION", __version_name__)
useMultiChunks = util.strtobool(os.environ.get("MESHROOM_USE_MULTI_CHUNKS", "True"))
def setupEnvironment(backend=Backend.STANDALONE):
"""
Setup environment for Meshroom to work in a prebuilt, standalone configuration.
Use 'MESHROOM_INSTALL_DIR' to simulate standalone configuration with a path to a Meshroom installation folder.
# Meshroom standalone structure
- Meshroom/
- aliceVision/
- bin/ # runtime bundled binaries (windows: exe + libs, unix: executables)
- lib/ # runtime bundled libraries (unix: libs)
- share/ # resource files
- aliceVision/
- COPYING.md # AliceVision COPYING file
- cameraSensors.db # sensor database
- vlfeat_K80L3.tree # voctree file
- lib/ # Python lib folder
- qtPlugins/
Meshroom # main executable
COPYING.md # Meshroom COPYING file
"""
init(backend)
def addToEnvPath(var, val, index=-1):
"""
Add paths to the given environment variable.
Args:
var (str): the name of the variable to add paths to
val (str or list of str): the path(s) to add
index (int): insertion index
"""
if not val:
return
paths = os.environ.get(var, "").split(os.pathsep)
if not isinstance(val, (list, tuple)):
val = [val]
if index == -1:
paths.extend(val)
elif index == 0:
paths = val + paths
else:
raise ValueError("addToEnvPath: index must be -1 or 0.")
os.environ[var] = os.pathsep.join(paths)
# setup root directory (override possible by setting "MESHROOM_INSTALL_DIR" environment variable)
rootDir = os.path.dirname(sys.executable) if isFrozen else os.environ.get("MESHROOM_INSTALL_DIR", None)
if rootDir:
os.environ["MESHROOM_INSTALL_DIR"] = rootDir
aliceVisionDir = os.path.join(rootDir, "aliceVision")
# default directories
aliceVisionBinDir = os.path.join(aliceVisionDir, "bin")
aliceVisionShareDir = os.path.join(aliceVisionDir, "share", "aliceVision")
qtPluginsDir = os.path.join(rootDir, "qtPlugins")
sensorDBPath = os.path.join(aliceVisionShareDir, "cameraSensors.db")
voctreePath = os.path.join(aliceVisionShareDir, "vlfeat_K80L3.SIFT.tree")
env = {
'PATH': aliceVisionBinDir,
'QT_PLUGIN_PATH': [qtPluginsDir],
'QML2_IMPORT_PATH': [os.path.join(qtPluginsDir, "qml")]
}
for key, value in env.items():
logging.info("Add to {}: {}".format(key, value))
addToEnvPath(key, value, 0)
variables = {
"ALICEVISION_SENSOR_DB": sensorDBPath,
"ALICEVISION_VOCTREE": voctreePath
}
for key, value in variables.items():
if key not in os.environ and os.path.exists(value):
logging.info("Set {}: {}".format(key, value))
os.environ[key] = value
else:
addToEnvPath("PATH", os.environ.get("ALICEVISION_BIN_PATH", ""))
|