Skip to content

Commit

Permalink
Merge pull request #45 from Carifio24/gltf-scatter-test-point-locations
Browse files Browse the repository at this point in the history
Test point locations of glTF scatter export
  • Loading branch information
Carifio24 authored Aug 22, 2024
2 parents 7e13ba3 + d72294d commit 77152bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions glue_ar/common/tests/gltf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ def unpack_points(gltf: GLTF,
current_point = []
for value in iter_unpack(format, data):
if len(current_point) < 3:
current_point.append(value)
current_point.append(value[0])
else:
unpacked.append(tuple(current_point))
current_point = [value]
current_point = [value[0]]

unpacked.append(tuple(current_point))

return unpacked
Expand Down
22 changes: 20 additions & 2 deletions glue_ar/common/tests/test_scatter_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from glue_ar.common.export import export_viewer
from glue_ar.common.scatter_export_options import ARScatterExportOptions
from glue_ar.common.shapes import sphere_points_count, sphere_triangles, sphere_triangles_count
from glue_ar.common.tests.gltf_helpers import count_indices, count_vertices
from glue_ar.utils import export_label_for_layer, hex_to_components, xyz_bounds
from glue_ar.common.tests.gltf_helpers import count_indices, count_vertices, unpack_vertices
from glue_ar.utils import export_label_for_layer, hex_to_components, mask_for_bounds, xyz_bounds, xyz_for_layer


class TestScatterGLTF:
Expand Down Expand Up @@ -115,3 +115,21 @@ def test_basic_export(self):
assert accessor.componentType == ComponentType.FLOAT.value
assert accessor.count == points_count
assert accessor.type == AccessorType.VEC3.value

mask = mask_for_bounds(self.viewer.state, layer.state, bounds)
data = xyz_for_layer(self.viewer.state, layer.state,
preserve_aspect=self.viewer.state.native_aspect,
mask=mask,
scaled=True)
data = data[:, [1, 2, 0]]

# Unpack the center of each sphere mesh matches the
# corresponding data point
tolerance = 1e-7
for index, mesh in enumerate(model.meshes):
buffer_view = model.bufferViews[mesh.primitives[0].attributes.POSITION]
points = unpack_vertices(gltf, model.buffers[0], buffer_view)
n_points = len(points)
center = tuple(sum(p[i] for p in points) / n_points for i in range(3))
data_point = data[index]
assert all(abs(center[i] - data_point[i]) < tolerance for i in range(len(center)))

0 comments on commit 77152bf

Please sign in to comment.