-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
254 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
partial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from typing import Tuple | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
def get_stl_data(filename: str) -> Tuple[npt.NDArray[np.float32], npt.NDArray[np.uint32]]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
solid Visualization Toolkit generated SLA File | ||
facet normal 0 0.93417234926898851 -0.35682211515159623 | ||
outer loop | ||
vertex 0 0.52573114633560181 -0.85065090656280518 | ||
vertex -0.52573114633560181 0.85065090656280518 0 | ||
vertex 0.52573114633560181 0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal 0 0.93417234926898851 0.35682211515159623 | ||
outer loop | ||
vertex 0 0.52573114633560181 0.85065090656280518 | ||
vertex 0.52573114633560181 0.85065090656280518 0 | ||
vertex -0.52573114633560181 0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal -0.35682211515159623 0 0.93417234926898851 | ||
outer loop | ||
vertex 0 0.52573114633560181 0.85065090656280518 | ||
vertex -0.85065090656280518 0 0.52573114633560181 | ||
vertex 0 -0.52573114633560181 0.85065090656280518 | ||
endloop | ||
endfacet | ||
facet normal 0.35682211515159623 -0 0.93417234926898851 | ||
outer loop | ||
vertex 0 0.52573114633560181 0.85065090656280518 | ||
vertex 0 -0.52573114633560181 0.85065090656280518 | ||
vertex 0.85065090656280518 0 0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal 0.35682211515159623 0 -0.93417234926898851 | ||
outer loop | ||
vertex 0 0.52573114633560181 -0.85065090656280518 | ||
vertex 0.85065090656280518 0 -0.52573114633560181 | ||
vertex 0 -0.52573114633560181 -0.85065090656280518 | ||
endloop | ||
endfacet | ||
facet normal -0.35682211515159623 0 -0.93417234926898851 | ||
outer loop | ||
vertex 0 0.52573114633560181 -0.85065090656280518 | ||
vertex 0 -0.52573114633560181 -0.85065090656280518 | ||
vertex -0.85065090656280518 0 -0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal 0 -0.93417234926898851 0.35682211515159623 | ||
outer loop | ||
vertex 0 -0.52573114633560181 0.85065090656280518 | ||
vertex -0.52573114633560181 -0.85065090656280518 0 | ||
vertex 0.52573114633560181 -0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal -0 -0.93417234926898851 -0.35682211515159623 | ||
outer loop | ||
vertex 0 -0.52573114633560181 -0.85065090656280518 | ||
vertex 0.52573114633560181 -0.85065090656280518 0 | ||
vertex -0.52573114633560181 -0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal -0.93417234926898851 0.35682211515159623 0 | ||
outer loop | ||
vertex -0.52573114633560181 0.85065090656280518 0 | ||
vertex -0.85065090656280518 0 -0.52573114633560181 | ||
vertex -0.85065090656280518 0 0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal -0.93417234926898851 -0.35682211515159623 -0 | ||
outer loop | ||
vertex -0.52573114633560181 -0.85065090656280518 0 | ||
vertex -0.85065090656280518 0 0.52573114633560181 | ||
vertex -0.85065090656280518 0 -0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal 0.93417234926898851 0.35682211515159623 0 | ||
outer loop | ||
vertex 0.52573114633560181 0.85065090656280518 0 | ||
vertex 0.85065090656280518 0 0.52573114633560181 | ||
vertex 0.85065090656280518 0 -0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal 0.93417234926898851 -0.35682211515159623 0 | ||
outer loop | ||
vertex 0.52573114633560181 -0.85065090656280518 0 | ||
vertex 0.85065090656280518 0 -0.52573114633560181 | ||
vertex 0.85065090656280518 0 0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal -0.57735026918962573 0.57735026918962573 0.57735026918962573 | ||
outer loop | ||
vertex 0 0.52573114633560181 0.85065090656280518 | ||
vertex -0.52573114633560181 0.85065090656280518 0 | ||
vertex -0.85065090656280518 0 0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal 0.57735026918962573 0.57735026918962573 0.57735026918962573 | ||
outer loop | ||
vertex 0 0.52573114633560181 0.85065090656280518 | ||
vertex 0.85065090656280518 0 0.52573114633560181 | ||
vertex 0.52573114633560181 0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal -0.57735026918962573 0.57735026918962573 -0.57735026918962573 | ||
outer loop | ||
vertex 0 0.52573114633560181 -0.85065090656280518 | ||
vertex -0.85065090656280518 0 -0.52573114633560181 | ||
vertex -0.52573114633560181 0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal 0.57735026918962573 0.57735026918962573 -0.57735026918962573 | ||
outer loop | ||
vertex 0 0.52573114633560181 -0.85065090656280518 | ||
vertex 0.52573114633560181 0.85065090656280518 0 | ||
vertex 0.85065090656280518 0 -0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal -0.57735026918962573 -0.57735026918962573 -0.57735026918962573 | ||
outer loop | ||
vertex 0 -0.52573114633560181 -0.85065090656280518 | ||
vertex -0.52573114633560181 -0.85065090656280518 0 | ||
vertex -0.85065090656280518 0 -0.52573114633560181 | ||
endloop | ||
endfacet | ||
facet normal 0.57735026918962573 -0.57735026918962573 -0.57735026918962573 | ||
outer loop | ||
vertex 0 -0.52573114633560181 -0.85065090656280518 | ||
vertex 0.85065090656280518 0 -0.52573114633560181 | ||
vertex 0.52573114633560181 -0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal -0.57735026918962573 -0.57735026918962573 0.57735026918962573 | ||
outer loop | ||
vertex 0 -0.52573114633560181 0.85065090656280518 | ||
vertex -0.85065090656280518 0 0.52573114633560181 | ||
vertex -0.52573114633560181 -0.85065090656280518 0 | ||
endloop | ||
endfacet | ||
facet normal 0.57735026918962573 -0.57735026918962573 0.57735026918962573 | ||
outer loop | ||
vertex 0 -0.52573114633560181 0.85065090656280518 | ||
vertex 0.52573114633560181 -0.85065090656280518 0 | ||
vertex 0.85065090656280518 0 0.52573114633560181 | ||
endloop | ||
endfacet | ||
endsolid |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,83 @@ | ||
"""Test stl_reader.""" | ||
|
||
import os | ||
import numpy as np | ||
import pytest | ||
import pyvista as pv | ||
|
||
import stl_reader | ||
|
||
|
||
@pytest.fixture | ||
def stlfile(tmpdir): | ||
filename = tmpdir.join("tmp.stl") | ||
pv.Sphere().save(filename) | ||
return str(filename) | ||
try: | ||
import pyvista as pv | ||
|
||
PYVISTA_INSTALLED = True | ||
except ImportError: | ||
PYVISTA_INSTALLED = False | ||
|
||
THIS_PATH = os.path.dirname(os.path.abspath(__file__)) | ||
TEST_FILE_ASCII = os.path.join(THIS_PATH, "sphere_ascii.stl") | ||
TEST_FILE_BINARY = os.path.join(THIS_PATH, "sphere_binary.stl") | ||
|
||
EXPECTED_POINTS = np.array( | ||
[ | ||
[0.0, 0.52573115, -0.8506509], | ||
[-0.52573115, 0.8506509, 0.0], | ||
[0.52573115, 0.8506509, 0.0], | ||
[0.0, 0.52573115, 0.8506509], | ||
[-0.8506509, 0.0, 0.52573115], | ||
[0.0, -0.52573115, 0.8506509], | ||
[0.8506509, 0.0, 0.52573115], | ||
[0.8506509, 0.0, -0.52573115], | ||
[0.0, -0.52573115, -0.8506509], | ||
[-0.8506509, 0.0, -0.52573115], | ||
[-0.52573115, -0.8506509, 0.0], | ||
[0.52573115, -0.8506509, 0.0], | ||
], | ||
dtype=np.float32, | ||
) | ||
|
||
@pytest.fixture | ||
def stlfile_ascii(tmpdir): | ||
filename = tmpdir.join("tmp.stl") | ||
pv.Sphere().save(filename, binary=False) | ||
return str(filename) | ||
|
||
EXPECTED_FACES = np.array( | ||
[ | ||
[0, 1, 2], | ||
[3, 2, 1], | ||
[3, 4, 5], | ||
[3, 5, 6], | ||
[0, 7, 8], | ||
[0, 8, 9], | ||
[5, 10, 11], | ||
[8, 11, 10], | ||
[1, 9, 4], | ||
[10, 4, 9], | ||
[2, 6, 7], | ||
[11, 7, 6], | ||
[3, 1, 4], | ||
[3, 6, 2], | ||
[0, 9, 1], | ||
[0, 2, 7], | ||
[8, 10, 9], | ||
[8, 7, 11], | ||
[5, 4, 10], | ||
[5, 11, 6], | ||
], | ||
dtype=np.uint32, | ||
) | ||
|
||
def test_read_binary(stlfile): | ||
pv_mesh = pv.read(stlfile) | ||
|
||
points, ind = stl_reader.read(stlfile) | ||
assert np.allclose(pv_mesh.points, points) | ||
assert np.allclose(pv_mesh._connectivity_array, ind.ravel()) | ||
def test_read_binary() -> None: | ||
points, ind = stl_reader.read(TEST_FILE_BINARY) | ||
assert np.allclose(EXPECTED_POINTS, points) | ||
assert np.allclose(EXPECTED_FACES, ind) | ||
|
||
|
||
def test_read_ascii(stlfile_ascii): | ||
def test_read_ascii() -> None: | ||
with pytest.raises(RuntimeError): | ||
stl_reader.read(stlfile_ascii) | ||
stl_reader.read(TEST_FILE_ASCII) | ||
|
||
|
||
def test_read_as_mesh(stlfile): | ||
pv_mesh = pv.read(stlfile) | ||
@pytest.mark.skipif(not PYVISTA_INSTALLED, reason="Requires PyVista") # type: ignore | ||
def test_read_as_mesh() -> None: | ||
pv_mesh = pv.read(TEST_FILE_BINARY) | ||
|
||
stl_mesh = stl_reader.read_as_mesh(stlfile) | ||
stl_mesh = stl_reader.read_as_mesh(TEST_FILE_BINARY) | ||
assert pv_mesh == stl_mesh |