pixelmap-multiview-python 0.1.0__tar.gz → 0.1.1__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.
Files changed (29) hide show
  1. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/CHANGELOG.md +12 -0
  2. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/Cargo.lock +3 -3
  3. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/Cargo.toml +2 -2
  4. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/PKG-INFO +22 -5
  5. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/README.md +20 -3
  6. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/pyproject.toml +1 -1
  7. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/_model.py +21 -4
  8. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/_pixelmap_multiview.pyi +2 -0
  9. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/src/model.rs +41 -9
  10. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/tests/test_export.py +46 -0
  11. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/.github/workflows/ci.yml +0 -0
  12. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/.github/workflows/release.yml +0 -0
  13. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/.gitignore +0 -0
  14. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/LICENSE +0 -0
  15. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/__init__.py +0 -0
  16. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/_errors.py +0 -0
  17. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/_events.py +0 -0
  18. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/_io.py +0 -0
  19. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/python/pixelmap_multiview/py.typed +0 -0
  20. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/src/convert.rs +0 -0
  21. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/src/errors.rs +0 -0
  22. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/src/events.rs +0 -0
  23. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/src/job.rs +0 -0
  24. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/src/lib.rs +0 -0
  25. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/tests/conftest.py +0 -0
  26. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/tests/test_events.py +0 -0
  27. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/tests/test_inputs.py +0 -0
  28. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/tests/test_job.py +0 -0
  29. {pixelmap_multiview_python-0.1.0 → pixelmap_multiview_python-0.1.1}/tests/test_run.py +0 -0
@@ -4,6 +4,18 @@ 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.1 - 2026-10-04
8
+
9
+ ### Added
10
+
11
+ - `Model.save` writes two more formats: `.glb`, binary glTF 2.0 with the texture atlas
12
+ embedded, and `.html`, one self-contained page that shows the textured model in 3D in
13
+ a browser. A new `title` keyword names the page.
14
+
15
+ ### Changed
16
+
17
+ - Built against `pixelmap_multiview` 0.1.1, which provides the GLB and HTML writers.
18
+
7
19
  ## 0.1.0 - 2026-09-26
8
20
 
9
21
  First release, built against `pixelmap_multiview` 0.1.0.
@@ -272,7 +272,7 @@ dependencies = [
272
272
 
273
273
  [[package]]
274
274
  name = "pixelmap-multiview-py"
275
- version = "0.1.0"
275
+ version = "0.1.1"
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.0"
285
+ version = "0.1.1"
286
286
  source = "registry+https://github.com/rust-lang/crates.io-index"
287
- checksum = "c1c63a4cc624ec8f88f17b94d3d5d6feff911b659b7d9e4a0ab30a0824f58c12"
287
+ checksum = "7e34495b7bc4024b66ad01458350950effc7dec766a2aaea572179d2f9f71c5b"
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.0"
3
+ version = "0.1.1"
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.1"
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.0
3
+ Version: 0.1.1
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.** `model.save()` writes `.obj` (textured),
96
- `.x3d` (textured) or `.ply` (vertex colours), turned half a revolution about x so that
97
- viewers show the model upright.
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
 
@@ -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.** `model.save()` writes `.obj` (textured),
68
- `.x3d` (textured) or `.ply` (vertex colours), turned half a revolution about x so that
69
- viewers show the model upright.
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
 
@@ -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",
@@ -221,19 +221,32 @@ class Model:
221
221
 
222
222
  # -- writing out ----------------------------------------------------------
223
223
 
224
- def save(self, path: Union[str, os.PathLike]) -> list[Path]:
225
- """Writes the model for MeshLab, Blender, CloudCompare and the like.
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 or .ply "
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&apos;s &lt;statue&gt; &amp; 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")