pixelmap-multiview-python 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/CHANGELOG.md +27 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/Cargo.lock +5 -5
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/Cargo.toml +2 -2
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/PKG-INFO +43 -15
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/README.md +41 -13
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/pyproject.toml +1 -1
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/__init__.py +3 -2
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/_events.py +3 -3
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/_io.py +6 -4
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/_model.py +21 -4
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/_pixelmap_multiview.pyi +2 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/src/model.rs +41 -9
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/tests/test_export.py +46 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/.github/workflows/ci.yml +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/.github/workflows/release.yml +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/.gitignore +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/LICENSE +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/_errors.py +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/py.typed +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/src/convert.rs +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/src/errors.rs +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/src/events.rs +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/src/job.rs +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/src/lib.rs +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/tests/conftest.py +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/tests/test_events.py +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/tests/test_inputs.py +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/tests/test_job.py +0 -0
- {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/tests/test_run.py +0 -0
|
@@ -4,6 +4,33 @@ All notable changes to this package are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package follows
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 0.1.2 - 2026-11-17
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Built against `pixelmap_multiview` 0.1.2 and pixelmap 0.3.1. Mapping each pair of
|
|
12
|
+
photos takes about 40% fewer region comparisons, so `reconstruct` is faster: on
|
|
13
|
+
4128x3096 photos one pair at `high` went from 5.9 s to 4.3 s.
|
|
14
|
+
- **The same photos, quality and `seed` no longer give the model 0.1.1 gave.** Runs are
|
|
15
|
+
still deterministic, but the solver reaches a different, equally good correspondence.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Gaps in the depth maps and the mesh. Some pairs' correspondence had straight unmapped
|
|
20
|
+
bands, one grid cell wide, running through it; pixelmap 0.3.1 no longer leaves them.
|
|
21
|
+
|
|
22
|
+
## 0.1.1 - 2026-10-04
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- `Model.save` writes two more formats: `.glb`, binary glTF 2.0 with the texture atlas
|
|
27
|
+
embedded, and `.html`, one self-contained page that shows the textured model in 3D in
|
|
28
|
+
a browser. A new `title` keyword names the page.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Built against `pixelmap_multiview` 0.1.1, which provides the GLB and HTML writers.
|
|
33
|
+
|
|
7
34
|
## 0.1.0 - 2026-09-26
|
|
8
35
|
|
|
9
36
|
First release, built against `pixelmap_multiview` 0.1.0.
|
|
@@ -263,16 +263,16 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
|
|
263
263
|
|
|
264
264
|
[[package]]
|
|
265
265
|
name = "pixelmap"
|
|
266
|
-
version = "0.3.
|
|
266
|
+
version = "0.3.1"
|
|
267
267
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
268
|
-
checksum = "
|
|
268
|
+
checksum = "68c5a7639712187ae7cc9671dcb9b02247971d965c8bef954b2e0b4fc580967c"
|
|
269
269
|
dependencies = [
|
|
270
270
|
"rayon",
|
|
271
271
|
]
|
|
272
272
|
|
|
273
273
|
[[package]]
|
|
274
274
|
name = "pixelmap-multiview-py"
|
|
275
|
-
version = "0.1.
|
|
275
|
+
version = "0.1.2"
|
|
276
276
|
dependencies = [
|
|
277
277
|
"numpy",
|
|
278
278
|
"pixelmap_multiview",
|
|
@@ -282,9 +282,9 @@ dependencies = [
|
|
|
282
282
|
|
|
283
283
|
[[package]]
|
|
284
284
|
name = "pixelmap_multiview"
|
|
285
|
-
version = "0.1.
|
|
285
|
+
version = "0.1.2"
|
|
286
286
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
287
|
-
checksum = "
|
|
287
|
+
checksum = "32b6d01388114dc917063953f308c86e5652c5d27f2607125930c7205e5a7491"
|
|
288
288
|
dependencies = [
|
|
289
289
|
"nalgebra",
|
|
290
290
|
"pixelmap",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pixelmap-multiview-py"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
rust-version = "1.83"
|
|
6
6
|
description = "Python bindings for the pixelmap_multiview crate"
|
|
@@ -18,7 +18,7 @@ crate-type = ["cdylib"]
|
|
|
18
18
|
[dependencies]
|
|
19
19
|
# `pixelmap` and `nalgebra` are reached through this crate's re-exports, so they are
|
|
20
20
|
# always the versions it was built against.
|
|
21
|
-
pixelmap_multiview = "0.1"
|
|
21
|
+
pixelmap_multiview = "0.1.2"
|
|
22
22
|
pyo3 = { version = "0.29", features = ["abi3-py39", "extension-module"] }
|
|
23
23
|
numpy = "0.29"
|
|
24
24
|
# The crate does no I/O, so encoding the texture atlas is ours to do.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pixelmap-multiview-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Classifier: Development Status :: 4 - Beta
|
|
5
5
|
Classifier: Intended Audience :: Science/Research
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -18,7 +18,7 @@ Provides-Extra: dev
|
|
|
18
18
|
Provides-Extra: images
|
|
19
19
|
License-File: LICENSE
|
|
20
20
|
Summary: 3D reconstruction from three or more photos: camera registration, dense depth, fusion and texturing
|
|
21
|
-
Keywords: computer-vision,photogrammetry,3d-reconstruction,structure-from-motion,sfm,mesh
|
|
21
|
+
Keywords: computer-vision,photogrammetry,3d-reconstruction,structure-from-motion,sfm,mesh,gltf
|
|
22
22
|
Author-email: Per Brendelökken <per@brendelokken.se>
|
|
23
23
|
Requires-Python: >=3.9
|
|
24
24
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
@@ -70,6 +70,7 @@ model = pmv.reconstruct(photos, quality="medium", focal_35mm=focal)
|
|
|
70
70
|
|
|
71
71
|
print(model) # <pixelmap_multiview.Model 23314 vertices, 45708 triangles, 4 of 4 photos>
|
|
72
72
|
model.save("out/statue.obj") # + statue.mtl + statue_texture.png, for MeshLab or Blender
|
|
73
|
+
model.save("out/statue.html") # open it in a browser and turn the model around
|
|
73
74
|
```
|
|
74
75
|
|
|
75
76
|
`load_photos` turns each photo upright according to its EXIF orientation and scales it
|
|
@@ -92,9 +93,25 @@ of uint8 arrays `(H, W, 3)`, `(H, W, 4)` or `(H, W)`, or Pillow images, all the
|
|
|
92
93
|
|
|
93
94
|
All of these are in one frame. The first camera of the best pair sits at the origin
|
|
94
95
|
looking along +z with +y down the image, and the distance between that pair's cameras is
|
|
95
|
-
the unit of length. **Nothing is metric.**
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
the unit of length. **Nothing is metric.**
|
|
97
|
+
|
|
98
|
+
## Saving
|
|
99
|
+
|
|
100
|
+
`model.save(path)` picks the format from the suffix:
|
|
101
|
+
|
|
102
|
+
| Suffix | Writes | Opens in |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| `.obj` | textured Wavefront OBJ, plus `<stem>.mtl` and `<stem>_texture.png` | MeshLab, Blender, CloudCompare |
|
|
105
|
+
| `.x3d` | textured X3D, plus `<stem>_texture.png` | MeshLab, X3D viewers |
|
|
106
|
+
| `.glb` | binary glTF 2.0, one file with the texture embedded | Blender, Windows 3D Viewer, three.js, most game engines |
|
|
107
|
+
| `.html` | one web page with the textured model embedded, shown in 3D | any browser |
|
|
108
|
+
| `.ply` | ASCII PLY with a colour per vertex | viewers that do not load textures |
|
|
109
|
+
|
|
110
|
+
It returns every file it wrote. The `.html` page is titled after the file's stem unless you
|
|
111
|
+
pass `title="..."`. The model is embedded in the page, but the viewer, Google's
|
|
112
|
+
`<model-viewer>`, is fetched from cdn.jsdelivr.net, so opening the page needs a network
|
|
113
|
+
connection. Every format is turned half a revolution about x so that viewers show the
|
|
114
|
+
model upright; the arrays on `model` are not turned.
|
|
98
115
|
|
|
99
116
|
## Following along and stopping
|
|
100
117
|
|
|
@@ -156,20 +173,31 @@ For a good capture:
|
|
|
156
173
|
- Let neighbouring photos overlap generously.
|
|
157
174
|
- Keep one camera at one zoom setting throughout.
|
|
158
175
|
|
|
159
|
-
##
|
|
176
|
+
## Time complexity
|
|
160
177
|
|
|
161
|
-
Mapping the pairs dominates: N photos take N(N−1)/2 pixelmap runs
|
|
162
|
-
|
|
178
|
+
Mapping the pairs dominates: N photos take N(N−1)/2 pixelmap runs, one after another, so
|
|
179
|
+
the time grows with the square of the number of photos. Four photos make 6 pairs; the 23
|
|
180
|
+
photos of the statue make 253. One pair of 4:3 photos takes, by the long side of the
|
|
181
|
+
photos:
|
|
163
182
|
|
|
164
183
|
| Quality | 800 px | 1200 px | 1800 px |
|
|
165
184
|
|---------|--------|---------|---------|
|
|
166
|
-
| low | 0.
|
|
167
|
-
| medium |
|
|
168
|
-
| high |
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
185
|
+
| low | 0.22 s | 0.23 s | 0.22 s |
|
|
186
|
+
| medium | 0.98 s | 0.96 s | 0.97 s |
|
|
187
|
+
| high | 2.16 s | 2.90 s | 4.08 s |
|
|
188
|
+
|
|
189
|
+
So the statue at `medium` spends about four minutes mapping pairs. These are medians of
|
|
190
|
+
three runs of `pixelmap-multiview --time-pair` from `pixelmap_multiview` 0.1.2, on a
|
|
191
|
+
six-core Intel Core i7-9750H laptop. Expect other machines to be proportionally faster or
|
|
192
|
+
slower.
|
|
193
|
+
|
|
194
|
+
pixelmap scales both photos down to a fixed working width before matching them: 400 px
|
|
195
|
+
for `low`, 800 px for `medium` and 1600 px for `high`. It never scales them up, so at
|
|
196
|
+
`low` and `medium` the size of the input barely changes the time. `high` only works at its
|
|
197
|
+
full width with photos at least 1600 px across, which is why it slows down as they grow;
|
|
198
|
+
at the 1200 px `load_photos` gives by default it works at 1200 px. Larger photos also give
|
|
199
|
+
more precise geometry after matching. Runs are deterministic: the same photos, quality and
|
|
200
|
+
`seed` give the same model.
|
|
173
201
|
|
|
174
202
|
## Development
|
|
175
203
|
|
|
@@ -42,6 +42,7 @@ model = pmv.reconstruct(photos, quality="medium", focal_35mm=focal)
|
|
|
42
42
|
|
|
43
43
|
print(model) # <pixelmap_multiview.Model 23314 vertices, 45708 triangles, 4 of 4 photos>
|
|
44
44
|
model.save("out/statue.obj") # + statue.mtl + statue_texture.png, for MeshLab or Blender
|
|
45
|
+
model.save("out/statue.html") # open it in a browser and turn the model around
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
`load_photos` turns each photo upright according to its EXIF orientation and scales it
|
|
@@ -64,9 +65,25 @@ of uint8 arrays `(H, W, 3)`, `(H, W, 4)` or `(H, W)`, or Pillow images, all the
|
|
|
64
65
|
|
|
65
66
|
All of these are in one frame. The first camera of the best pair sits at the origin
|
|
66
67
|
looking along +z with +y down the image, and the distance between that pair's cameras is
|
|
67
|
-
the unit of length. **Nothing is metric.**
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
the unit of length. **Nothing is metric.**
|
|
69
|
+
|
|
70
|
+
## Saving
|
|
71
|
+
|
|
72
|
+
`model.save(path)` picks the format from the suffix:
|
|
73
|
+
|
|
74
|
+
| Suffix | Writes | Opens in |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| `.obj` | textured Wavefront OBJ, plus `<stem>.mtl` and `<stem>_texture.png` | MeshLab, Blender, CloudCompare |
|
|
77
|
+
| `.x3d` | textured X3D, plus `<stem>_texture.png` | MeshLab, X3D viewers |
|
|
78
|
+
| `.glb` | binary glTF 2.0, one file with the texture embedded | Blender, Windows 3D Viewer, three.js, most game engines |
|
|
79
|
+
| `.html` | one web page with the textured model embedded, shown in 3D | any browser |
|
|
80
|
+
| `.ply` | ASCII PLY with a colour per vertex | viewers that do not load textures |
|
|
81
|
+
|
|
82
|
+
It returns every file it wrote. The `.html` page is titled after the file's stem unless you
|
|
83
|
+
pass `title="..."`. The model is embedded in the page, but the viewer, Google's
|
|
84
|
+
`<model-viewer>`, is fetched from cdn.jsdelivr.net, so opening the page needs a network
|
|
85
|
+
connection. Every format is turned half a revolution about x so that viewers show the
|
|
86
|
+
model upright; the arrays on `model` are not turned.
|
|
70
87
|
|
|
71
88
|
## Following along and stopping
|
|
72
89
|
|
|
@@ -128,20 +145,31 @@ For a good capture:
|
|
|
128
145
|
- Let neighbouring photos overlap generously.
|
|
129
146
|
- Keep one camera at one zoom setting throughout.
|
|
130
147
|
|
|
131
|
-
##
|
|
148
|
+
## Time complexity
|
|
132
149
|
|
|
133
|
-
Mapping the pairs dominates: N photos take N(N−1)/2 pixelmap runs
|
|
134
|
-
|
|
150
|
+
Mapping the pairs dominates: N photos take N(N−1)/2 pixelmap runs, one after another, so
|
|
151
|
+
the time grows with the square of the number of photos. Four photos make 6 pairs; the 23
|
|
152
|
+
photos of the statue make 253. One pair of 4:3 photos takes, by the long side of the
|
|
153
|
+
photos:
|
|
135
154
|
|
|
136
155
|
| Quality | 800 px | 1200 px | 1800 px |
|
|
137
156
|
|---------|--------|---------|---------|
|
|
138
|
-
| low | 0.
|
|
139
|
-
| medium |
|
|
140
|
-
| high |
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
| low | 0.22 s | 0.23 s | 0.22 s |
|
|
158
|
+
| medium | 0.98 s | 0.96 s | 0.97 s |
|
|
159
|
+
| high | 2.16 s | 2.90 s | 4.08 s |
|
|
160
|
+
|
|
161
|
+
So the statue at `medium` spends about four minutes mapping pairs. These are medians of
|
|
162
|
+
three runs of `pixelmap-multiview --time-pair` from `pixelmap_multiview` 0.1.2, on a
|
|
163
|
+
six-core Intel Core i7-9750H laptop. Expect other machines to be proportionally faster or
|
|
164
|
+
slower.
|
|
165
|
+
|
|
166
|
+
pixelmap scales both photos down to a fixed working width before matching them: 400 px
|
|
167
|
+
for `low`, 800 px for `medium` and 1600 px for `high`. It never scales them up, so at
|
|
168
|
+
`low` and `medium` the size of the input barely changes the time. `high` only works at its
|
|
169
|
+
full width with photos at least 1600 px across, which is why it slows down as they grow;
|
|
170
|
+
at the 1200 px `load_photos` gives by default it works at 1200 px. Larger photos also give
|
|
171
|
+
more precise geometry after matching. Runs are deterministic: the same photos, quality and
|
|
172
|
+
`seed` give the same model.
|
|
145
173
|
|
|
146
174
|
## Development
|
|
147
175
|
|
|
@@ -9,7 +9,7 @@ description = "3D reconstruction from three or more photos: camera registration,
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
authors = [{ name = "Per Brendelökken", email = "per@brendelokken.se" }]
|
|
12
|
-
keywords = ["computer-vision", "photogrammetry", "3d-reconstruction", "structure-from-motion", "sfm", "mesh"]
|
|
12
|
+
keywords = ["computer-vision", "photogrammetry", "3d-reconstruction", "structure-from-motion", "sfm", "mesh", "gltf"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|
|
15
15
|
"Intended Audience :: Science/Research",
|
|
@@ -105,8 +105,9 @@ STAGES: list[tuple[str, str]] = _pixelmap_multiview.STAGES
|
|
|
105
105
|
class Quality(str, enum.Enum):
|
|
106
106
|
"""How much work pixelmap puts into each pair of photos.
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
0.
|
|
108
|
+
Mapping the pairs takes most of a run's time, since there are N(N-1)/2 of them. One
|
|
109
|
+
pair of 1200 px photos takes roughly 0.2 s at ``LOW``, 1 s at ``MEDIUM`` and 2.9 s at
|
|
110
|
+
``HIGH`` on a six-core laptop.
|
|
110
111
|
"""
|
|
111
112
|
|
|
112
113
|
LOW = "low"
|
|
@@ -32,9 +32,9 @@ class Event:
|
|
|
32
32
|
Attributes:
|
|
33
33
|
stage: The stage it came from, one of the names in :data:`STAGES`.
|
|
34
34
|
progress: How far through the whole run this is, ``0.0``-``1.0``, with each stage
|
|
35
|
-
weighted by
|
|
36
|
-
progress — a log line or a dropped view — which a progress bar should
|
|
37
|
-
rather than move backwards for.
|
|
35
|
+
weighted by how long it typically takes. ``None`` for events that say nothing
|
|
36
|
+
about progress — a log line or a dropped view — which a progress bar should
|
|
37
|
+
ignore rather than move backwards for.
|
|
38
38
|
message: The event as one line for a log.
|
|
39
39
|
"""
|
|
40
40
|
|
{pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/python/pixelmap_multiview/_io.py
RENAMED
|
@@ -22,10 +22,12 @@ def load_photos(
|
|
|
22
22
|
"""Reads photos for :func:`reconstruct`, with the focal length EXIF records.
|
|
23
23
|
|
|
24
24
|
Each photo is turned upright as its EXIF orientation says, converted to RGB, and
|
|
25
|
-
scaled down so that its longer side is at most ``max_size`` pixels.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
scaled down so that its longer side is at most ``max_size`` pixels. Smaller photos
|
|
26
|
+
take less memory, but the geometry that follows is less precise, so ``max_size``
|
|
27
|
+
trades memory against detail. Matching time stays about the same at ``"low"`` and
|
|
28
|
+
``"medium"``, because pixelmap scales photos down to a fixed working width. ``"high"``
|
|
29
|
+
works at up to 1600 px and never scales up, so below that, smaller photos make it
|
|
30
|
+
faster. 1200 is what the crate's measurements were taken at.
|
|
29
31
|
|
|
30
32
|
Requires Pillow: ``pip install pixelmap-multiview-python[images]``.
|
|
31
33
|
|
|
@@ -221,19 +221,32 @@ class Model:
|
|
|
221
221
|
|
|
222
222
|
# -- writing out ----------------------------------------------------------
|
|
223
223
|
|
|
224
|
-
def save(
|
|
225
|
-
|
|
224
|
+
def save(
|
|
225
|
+
self, path: Union[str, os.PathLike], *, title: Optional[str] = None
|
|
226
|
+
) -> list[Path]:
|
|
227
|
+
"""Writes the model for MeshLab, Blender, CloudCompare, web browsers and so on.
|
|
226
228
|
|
|
227
229
|
The format follows the suffix:
|
|
228
230
|
|
|
229
231
|
- ``.obj``: textured Wavefront OBJ, with a ``.mtl`` material library and the atlas
|
|
230
232
|
as ``<stem>_texture.png`` next to it.
|
|
231
233
|
- ``.x3d``: textured X3D, with the atlas as ``<stem>_texture.png`` next to it.
|
|
234
|
+
- ``.glb``: binary glTF 2.0, one file with the atlas embedded, for Blender, the
|
|
235
|
+
Windows 3D Viewer, three.js and most game engines.
|
|
236
|
+
- ``.html``: one self-contained web page that shows the textured model in 3D, to
|
|
237
|
+
be turned with the mouse or a finger. The model is embedded in the page, but
|
|
238
|
+
the viewer, Google's ``<model-viewer>``, is fetched from cdn.jsdelivr.net, so
|
|
239
|
+
opening it needs a network connection.
|
|
232
240
|
- ``.ply``: ASCII PLY with a colour per vertex, for viewers that do not load
|
|
233
241
|
textures.
|
|
234
242
|
|
|
235
243
|
The model is turned half a revolution about x so that viewers show it upright.
|
|
236
244
|
|
|
245
|
+
Args:
|
|
246
|
+
path: Where to write the model; its suffix picks the format.
|
|
247
|
+
title: The page title for ``.html``, the file's stem by default. The other
|
|
248
|
+
formats ignore it.
|
|
249
|
+
|
|
237
250
|
Returns:
|
|
238
251
|
Every file written, the one named first.
|
|
239
252
|
"""
|
|
@@ -253,12 +266,16 @@ class Model:
|
|
|
253
266
|
path: self._inner.x3d(texture.name),
|
|
254
267
|
texture: self._inner.atlas_png(),
|
|
255
268
|
}
|
|
269
|
+
elif suffix == ".glb":
|
|
270
|
+
files = {path: self._inner.glb()}
|
|
271
|
+
elif suffix == ".html":
|
|
272
|
+
files = {path: self._inner.html(path.stem if title is None else title)}
|
|
256
273
|
elif suffix == ".ply":
|
|
257
274
|
files = {path: self._inner.ply()}
|
|
258
275
|
else:
|
|
259
276
|
raise ValueError(
|
|
260
|
-
f"cannot tell the format from {path.name!r}; use a .obj, .x3d
|
|
261
|
-
f"suffix"
|
|
277
|
+
f"cannot tell the format from {path.name!r}; use a .obj, .x3d, .glb, "
|
|
278
|
+
f".html or .ply suffix"
|
|
262
279
|
)
|
|
263
280
|
|
|
264
281
|
for target, data in files.items():
|
|
@@ -50,6 +50,8 @@ class Model:
|
|
|
50
50
|
def mtl(self, texture_file: str) -> bytes: ...
|
|
51
51
|
def ply(self) -> bytes: ...
|
|
52
52
|
def x3d(self, texture_file: str) -> bytes: ...
|
|
53
|
+
def glb(self) -> bytes: ...
|
|
54
|
+
def html(self, title: str) -> bytes: ...
|
|
53
55
|
def atlas_png(self) -> bytes: ...
|
|
54
56
|
|
|
55
57
|
class Job:
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
//! A finished reconstruction, handed to Python as arrays.
|
|
2
2
|
|
|
3
|
+
use std::io::{self, Write};
|
|
4
|
+
|
|
3
5
|
use numpy::ndarray::Array1;
|
|
4
6
|
use numpy::{IntoPyArray, PyArray1, PyArray2, PyArray3};
|
|
5
7
|
use pixelmap_multiview::export;
|
|
8
|
+
use pixelmap_multiview::pixelmap::Photo;
|
|
6
9
|
use pyo3::exceptions::PyRuntimeError;
|
|
7
10
|
use pyo3::prelude::*;
|
|
8
11
|
use pyo3::types::{PyBytes, PyDict};
|
|
@@ -41,6 +44,25 @@ fn written(
|
|
|
41
44
|
Ok(PyBytes::new(py, &buffer))
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
/// Encodes the texture atlas as PNG: the crate does no image encoding, and the GLB and
|
|
48
|
+
/// HTML writers take the atlas ready-encoded.
|
|
49
|
+
fn write_png(out: &mut impl Write, atlas: &Photo) -> io::Result<()> {
|
|
50
|
+
let mut encoder = png::Encoder::new(out, atlas.width() as u32, atlas.height() as u32);
|
|
51
|
+
encoder.set_color(png::ColorType::Rgba);
|
|
52
|
+
encoder.set_depth(png::BitDepth::Eight);
|
|
53
|
+
let mut writer = encoder.write_header()?;
|
|
54
|
+
writer.write_image_data(atlas.as_rgba())?;
|
|
55
|
+
writer.finish()?;
|
|
56
|
+
Ok(())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// The texture atlas as PNG, in memory.
|
|
60
|
+
fn png_bytes(atlas: &Photo) -> io::Result<Vec<u8>> {
|
|
61
|
+
let mut png = Vec::new();
|
|
62
|
+
write_png(&mut png, atlas)?;
|
|
63
|
+
Ok(png)
|
|
64
|
+
}
|
|
65
|
+
|
|
44
66
|
#[pymethods]
|
|
45
67
|
impl Model {
|
|
46
68
|
#[getter]
|
|
@@ -174,17 +196,27 @@ impl Model {
|
|
|
174
196
|
})
|
|
175
197
|
}
|
|
176
198
|
|
|
199
|
+
/// Binary glTF 2.0, with the atlas embedded.
|
|
200
|
+
fn glb<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
|
|
201
|
+
let (mesh, texture) = (&self.inner.mesh, &self.inner.texture);
|
|
202
|
+
written(py, |out| {
|
|
203
|
+
let png = png_bytes(&texture.atlas)?;
|
|
204
|
+
export::write_textured_glb(out, mesh, texture, &png)
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/// One self-contained HTML page showing the textured mesh in 3D, titled `title`.
|
|
209
|
+
fn html<'py>(&self, py: Python<'py>, title: &str) -> PyResult<Bound<'py, PyBytes>> {
|
|
210
|
+
let (mesh, texture) = (&self.inner.mesh, &self.inner.texture);
|
|
211
|
+
written(py, |out| {
|
|
212
|
+
let png = png_bytes(&texture.atlas)?;
|
|
213
|
+
export::write_textured_html(out, mesh, texture, &png, title)
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
177
217
|
/// The texture atlas as PNG.
|
|
178
218
|
fn atlas_png<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
|
|
179
219
|
let atlas = &self.inner.texture.atlas;
|
|
180
|
-
written(py, |out|
|
|
181
|
-
let mut encoder = png::Encoder::new(out, atlas.width() as u32, atlas.height() as u32);
|
|
182
|
-
encoder.set_color(png::ColorType::Rgba);
|
|
183
|
-
encoder.set_depth(png::BitDepth::Eight);
|
|
184
|
-
let mut writer = encoder.write_header()?;
|
|
185
|
-
writer.write_image_data(atlas.as_rgba())?;
|
|
186
|
-
writer.finish()?;
|
|
187
|
-
Ok(())
|
|
188
|
-
})
|
|
220
|
+
written(py, |out| write_png(out, atlas))
|
|
189
221
|
}
|
|
190
222
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"""Writing the model out for other tools, and reading photos in."""
|
|
2
2
|
|
|
3
|
+
import base64
|
|
4
|
+
import io
|
|
5
|
+
import json
|
|
6
|
+
import struct
|
|
7
|
+
|
|
3
8
|
import numpy as np
|
|
4
9
|
import pixelmap_multiview as pmv
|
|
5
10
|
import pytest
|
|
@@ -35,6 +40,47 @@ def test_x3d_refers_to_its_texture(model, tmp_path):
|
|
|
35
40
|
assert "scene_texture.png" in files[0].read_text()
|
|
36
41
|
|
|
37
42
|
|
|
43
|
+
def test_glb_is_one_file_with_the_atlas_embedded(model, tmp_path):
|
|
44
|
+
(path,) = model.save(tmp_path / "mesh.glb")
|
|
45
|
+
assert [f.name for f in tmp_path.iterdir()] == ["mesh.glb"]
|
|
46
|
+
data = path.read_bytes()
|
|
47
|
+
assert struct.unpack_from("<4sII", data) == (b"glTF", 2, len(data))
|
|
48
|
+
|
|
49
|
+
json_length, json_type = struct.unpack_from("<I4s", data, 12)
|
|
50
|
+
assert json_type == b"JSON"
|
|
51
|
+
gltf = json.loads(data[20 : 20 + json_length])
|
|
52
|
+
bin_start = 20 + json_length
|
|
53
|
+
bin_length, bin_type = struct.unpack_from("<I4s", data, bin_start)
|
|
54
|
+
assert bin_type == b"BIN\0"
|
|
55
|
+
binary = data[bin_start + 8 : bin_start + 8 + bin_length]
|
|
56
|
+
assert gltf["asset"]["version"] == "2.0"
|
|
57
|
+
|
|
58
|
+
(primitive,) = gltf["meshes"][0]["primitives"]
|
|
59
|
+
assert gltf["accessors"][primitive["indices"]]["count"] == 3 * len(model.triangles)
|
|
60
|
+
|
|
61
|
+
view = gltf["bufferViews"][gltf["images"][0]["bufferView"]]
|
|
62
|
+
png = binary[view["byteOffset"] : view["byteOffset"] + view["byteLength"]]
|
|
63
|
+
with Image.open(io.BytesIO(png)) as atlas:
|
|
64
|
+
assert np.array_equal(np.asarray(atlas.convert("RGBA")), model.texture.atlas)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_html_embeds_the_glb_and_is_titled(model, tmp_path):
|
|
68
|
+
(glb,) = model.save(tmp_path / "statue.glb")
|
|
69
|
+
(page,) = model.save(tmp_path / "statue.html")
|
|
70
|
+
# The page holds an ellipsis and a middle dot, which some platforms' default
|
|
71
|
+
# encodings would misread.
|
|
72
|
+
text = page.read_text(encoding="utf-8")
|
|
73
|
+
assert "<title>statue</title>" in text
|
|
74
|
+
payload = text.split("data:model/gltf-binary;base64,")[1].split('"')[0]
|
|
75
|
+
assert base64.b64decode(payload) == glb.read_bytes()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_html_title_is_escaped(model, tmp_path):
|
|
79
|
+
(page,) = model.save(tmp_path / "statue.html", title="Bob's <statue> & co")
|
|
80
|
+
text = page.read_text(encoding="utf-8")
|
|
81
|
+
assert "<title>Bob's <statue> & co</title>" in text
|
|
82
|
+
|
|
83
|
+
|
|
38
84
|
def test_an_unknown_suffix_is_refused(model, tmp_path):
|
|
39
85
|
with pytest.raises(ValueError, match=".obj"):
|
|
40
86
|
model.save(tmp_path / "mesh.stl")
|
{pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/.github/workflows/ci.yml
RENAMED
|
File without changes
|
{pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.2}/.github/workflows/release.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|