Debian Codegraph @

doc/_static/install_selector.js

raw
1 // Interactive install selector for the COLMAP landing page.
2 //
3 // Renders a pytorch.org-style grid: the user picks an operating system, an
4 // install method, and a compute backend (CUDA vs CPU), and the widget shows the
5 // exact command or download link. The script is loaded on every page but only
6 // activates when the landing page's mount point (#colmap-install-selector) is
7 // present.
8 (function () {
9 "use strict";
10
11 // Helpers to build the per-cell result shown in the output box.
12 function cmd(text, note) {
13 return { kind: "command", text: text, note: note || null };
14 }
15 function link(text, url, note) {
16 return { kind: "link", text: text, url: url, note: note || null };
17 }
18
19 // Install matrix: MATRIX[os].methods keeps the display order; MATRIX[os].cells
20 // maps method -> { cuda, cpu }, where each entry is a result object or null
21 // (unavailable / disabled).
22 var MATRIX = {
23 linux: {
24 label: "Linux",
25 methods: ["pip", "conda", "docker", "binary", "source"],
26 cells: {
27 pip: {
28 cuda: cmd("pip install pycolmap-cuda12"),
29 cpu: cmd("pip install pycolmap"),
30 },
31 conda: {
32 cuda: null,
33 cpu: cmd("conda install -c conda-forge colmap"),
34 },
35 docker: {
36 cuda: cmd(
37 "docker pull colmap/colmap:latest",
38 "Run with GPU flags (NVIDIA Container Toolkit) to enable CUDA."
39 ),
40 cpu: cmd(
41 "docker pull colmap/colmap:latest",
42 "The image is CUDA-based but also runs CPU-only."
43 ),
44 },
45 binary: {
46 cuda: null,
47 cpu: link(
48 "Distribution packages (Repology)",
49 "https://repology.org/metapackage/colmap/versions",
50 "Distro packages ship without CUDA. For GPU support, build from source."
51 ),
52 },
53 source: {
54 cuda: link(
55 "Build from source (with CUDA)",
56 "https://colmap.github.io/install.html#debian-ubuntu",
57 "Install the CUDA toolkit, then configure COLMAP with CUDA enabled."
58 ),
59 cpu: link(
60 "Build from source",
61 "https://colmap.github.io/install.html#debian-ubuntu"
62 ),
63 },
64 },
65 },
66 macos: {
67 label: "macOS",
68 methods: ["binary", "pip", "conda", "brew", "docker", "source"],
69 cells: {
70 binary: {
71 cuda: null,
72 cpu: link(
73 "Download from GitHub Releases",
74 "https://github.com/colmap/colmap/releases",
75 "Use the colmap-arm64-macos package."
76 ),
77 },
78 pip: { cuda: null, cpu: cmd("pip install pycolmap") },
79 conda: { cuda: null, cpu: cmd("conda install -c conda-forge colmap") },
80 brew: { cuda: null, cpu: cmd("brew install colmap") },
81 docker: {
82 cuda: null,
83 cpu: cmd(
84 "docker pull colmap/colmap:latest",
85 "GPU acceleration is not available on macOS."
86 ),
87 },
88 source: {
89 cuda: null,
90 cpu: link(
91 "Build from source",
92 "https://colmap.github.io/install.html#mac"
93 ),
94 },
95 },
96 },
97 windows: {
98 label: "Windows",
99 methods: ["binary", "pip", "conda", "vcpkg", "docker"],
100 cells: {
101 binary: {
102 cuda: link(
103 "Download from GitHub Releases",
104 "https://github.com/colmap/colmap/releases",
105 "Use the colmap-x64-windows-cuda package."
106 ),
107 cpu: link(
108 "Download from GitHub Releases",
109 "https://github.com/colmap/colmap/releases",
110 "Use the colmap-x64-windows-nocuda package."
111 ),
112 },
113 pip: {
114 cuda: null,
115 cpu: cmd(
116 "pip install pycolmap",
117 "Windows wheels are CPU-only. For GPU, use the binary package or vcpkg."
118 ),
119 },
120 conda: { cuda: null, cpu: cmd("conda install -c conda-forge colmap") },
121 vcpkg: {
122 cuda: cmd("vcpkg install colmap[cuda,tests]:x64-windows"),
123 cpu: cmd("vcpkg install colmap:x64-windows"),
124 },
125 docker: {
126 cuda: cmd(
127 "docker pull colmap/colmap:latest",
128 "Requires WSL2 with the NVIDIA Container Toolkit for GPU support."
129 ),
130 cpu: cmd("docker pull colmap/colmap:latest"),
131 },
132 },
133 },
134 };
135
136 var OS_ORDER = ["linux", "macos", "windows"];
137 var METHOD_LABELS = {
138 pip: "pip",
139 conda: "Conda",
140 docker: "Docker",
141 binary: "Binary",
142 brew: "Homebrew",
143 vcpkg: "vcpkg",
144 source: "Source",
145 };
146 var COMPUTE_ORDER = ["cuda", "cpu"];
147 var COMPUTE_LABELS = { cuda: "CUDA (GPU)", cpu: "CPU" };
148
149 function escapeHtml(s) {
150 return String(s)
151 .replace(/&/g, "&")
152 .replace(/</g, "&lt;")
153 .replace(/>/g, "&gt;")
154 .replace(/"/g, "&quot;");
155 }
156
157 // Current selection.
158 var state = { os: "linux", method: "pip", compute: "cuda" };
159
160 function computesFor(os, method) {
161 var cell = MATRIX[os].cells[method];
162 return COMPUTE_ORDER.filter(function (c) {
163 return cell && cell[c];
164 });
165 }
166
167 // Coerce the selection into a valid (os, method, compute) triple.
168 function normalize() {
169 if (!MATRIX[state.os]) state.os = "linux";
170 var methods = MATRIX[state.os].methods;
171 if (methods.indexOf(state.method) === -1) state.method = methods[0];
172 var avail = computesFor(state.os, state.method);
173 if (avail.indexOf(state.compute) === -1) state.compute = avail[0];
174 }
175
176 function button(label, active, disabled, onClick) {
177 var btn = document.createElement("button");
178 btn.type = "button";
179 btn.className =
180 "cis__btn" +
181 (active ? " cis__btn--active" : "") +
182 (disabled ? " cis__btn--disabled" : "");
183 btn.textContent = label;
184 if (disabled) {
185 btn.setAttribute("aria-disabled", "true");
186 btn.disabled = true;
187 } else {
188 btn.addEventListener("click", onClick);
189 }
190 btn.setAttribute("aria-pressed", active ? "true" : "false");
191 return btn;
192 }
193
194 function row(root, labelText, options) {
195 var r = document.createElement("div");
196 r.className = "cis__row";
197 var lbl = document.createElement("div");
198 lbl.className = "cis__label";
199 lbl.textContent = labelText;
200 var opts = document.createElement("div");
201 opts.className = "cis__options";
202 options.forEach(function (o) {
203 opts.appendChild(o);
204 });
205 r.appendChild(lbl);
206 r.appendChild(opts);
207 root.appendChild(r);
208 }
209
210 function render(root) {
211 normalize();
212 root.innerHTML = "";
213
214 // OS row.
215 row(
216 root,
217 "OS",
218 OS_ORDER.map(function (os) {
219 return button(MATRIX[os].label, state.os === os, false, function () {
220 state.os = os;
221 render(root);
222 });
223 })
224 );
225
226 // Method row.
227 row(
228 root,
229 "Package",
230 MATRIX[state.os].methods.map(function (m) {
231 return button(METHOD_LABELS[m], state.method === m, false, function () {
232 state.method = m;
233 render(root);
234 });
235 })
236 );
237
238 // Compute row (disable unavailable backends for the current os+method).
239 var avail = computesFor(state.os, state.method);
240 row(
241 root,
242 "Compute",
243 COMPUTE_ORDER.map(function (c) {
244 var disabled = avail.indexOf(c) === -1;
245 return button(
246 COMPUTE_LABELS[c],
247 state.compute === c,
248 disabled,
249 function () {
250 state.compute = c;
251 render(root);
252 }
253 );
254 })
255 );
256
257 // Output box.
258 var result = MATRIX[state.os].cells[state.method][state.compute];
259 var out = document.createElement("div");
260 out.className = "cis__output";
261
262 if (result && result.kind === "command") {
263 var box = document.createElement("div");
264 box.className = "cis__cmd";
265 var code = document.createElement("code");
266 code.innerHTML =
267 '<span class="cis__prompt">$</span> ' + escapeHtml(result.text);
268 var copy = document.createElement("button");
269 copy.type = "button";
270 copy.className = "cis__copy";
271 copy.textContent = "Copy";
272 copy.addEventListener("click", function () {
273 var done = function () {
274 copy.textContent = "Copied!";
275 setTimeout(function () {
276 copy.textContent = "Copy";
277 }, 1500);
278 };
279 if (navigator.clipboard && navigator.clipboard.writeText) {
280 navigator.clipboard.writeText(result.text).then(done, function () {});
281 } else {
282 done();
283 }
284 });
285 box.appendChild(code);
286 box.appendChild(copy);
287 out.appendChild(box);
288 } else if (result && result.kind === "link") {
289 var a = document.createElement("a");
290 a.className = "cis__link";
291 a.href = result.url;
292 a.textContent = result.text;
293 a.rel = "noopener";
294 out.appendChild(a);
295 }
296
297 if (result && result.note) {
298 var note = document.createElement("p");
299 note.className = "cis__note";
300 note.textContent = result.note;
301 out.appendChild(note);
302 }
303
304 root.appendChild(out);
305 }
306
307 function init() {
308 var root = document.getElementById("colmap-install-selector");
309 if (!root) return;
310 root.classList.add("cis");
311 render(root);
312 }
313
314 if (document.readyState === "loading") {
315 document.addEventListener("DOMContentLoaded", init);
316 } else {
317 init();
318 }
319 })();