stl package¶
stl.Mesh¶
-
class
stl.
Mesh
(data, calculate_normals=True, remove_empty_areas=False, remove_duplicate_polygons=<RemoveDuplicates.NONE: 0>, name='', speedups=True, **kwargs)[source]¶ Bases:
stl.stl.BaseStl
-
areas
¶ Mesh areas
-
attr
¶
-
check
()¶ Check the mesh is valid or not
-
classmethod
debug
(*args, **kwargs)¶ Log a message with severity ‘DEBUG’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
dtype
= dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), ('attr', '<u2', (1,))])¶
-
classmethod
error
(*args, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
classmethod
exception
(*args, exc_info=True, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format.
-
classmethod
from_file
(filename, calculate_normals=True, fh=None, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)¶ Load a mesh from a STL file
Parameters: - filename (str) – The file to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
classmethod
from_files
(filenames, calculate_normals=True, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)¶ Load multiple meshes from a STL file
Note: mode is hardcoded to ascii since binary stl files do not support the multi format
Parameters: - filenames (list(str)) – The files to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
classmethod
from_multi_file
(filename, calculate_normals=True, fh=None, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)¶ Load multiple meshes from a STL file
Note: mode is hardcoded to ascii since binary stl files do not support the multi format
Parameters: - filename (str) – The file to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
get_header
(name)¶
-
get_mass_properties
()¶ - Evaluate and return a tuple with the following elements:
- the volume
- the position of the center of gravity (COG)
- the inertia matrix expressed at the COG
Documentation can be found here: http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
-
get_mass_properties_with_density
(density)¶
-
get_unit_normals
()¶
-
classmethod
info
(*args, **kwargs)¶ Log a message with severity ‘INFO’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
is_closed
()¶ Check the mesh is closed or not
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
classmethod
load
(fh, mode=<Mode.AUTOMATIC: 0>, speedups=True)¶ Load Mesh from STL file
Automatically detects binary versus ascii STL files.
Parameters: - fh (file) – The file handle to open
- mode (int) – Automatically detect the filetype or force binary
-
classmethod
log
(msg, *args, **kwargs)¶ Log ‘msg % args’ with the integer severity ‘level’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
logger
= <Logger stl.base.BaseMesh (WARNING)>¶
-
max_
¶ Mesh maximum value
-
min_
¶ Mesh minimum value
-
normals
¶
-
points
¶
-
classmethod
remove_duplicate_polygons
(data, value=<RemoveDuplicates.SINGLE: 1>)¶
-
classmethod
remove_empty_areas
(data)¶
-
rotate
(axis, theta=0, point=None)¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()
in the background.Note
Note that the point was accidentaly inverted with the old version of the code. To get the old and incorrect behaviour simply pass -point instead of point or -numpy.array(point) if you’re passing along an array.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
- point (numpy.array) – Rotation point so manual translation is not required
-
rotate_using_matrix
(rotation_matrix, point=None)¶ Rotate using a given rotation matrix and optional rotation point
Note that this rotation produces clockwise rotations for positive angles which is arguably incorrect but will remain for legacy reasons. For more details, read here: https://github.com/WoLpH/numpy-stl/issues/166
-
classmethod
rotation_matrix
(axis, theta)¶ Generate a rotation matrix to Rotate the matrix over the given axis by the given theta (angle)
Uses the Euler-Rodrigues formula for fast rotations.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
-
save
(filename, fh=None, mode=<Mode.AUTOMATIC: 0>, update_normals=True)¶ Save the STL to a (binary) file
If mode is
AUTOMATIC
anASCII
file will be written if the output is a TTY and aBINARY
file otherwise.Parameters:
-
transform
(matrix)¶ Transform the mesh with a rotation and a translation stored in a single 4x4 matrix
Parameters: matrix (numpy.array) – Transform matrix with shape (4, 4), where matrix[0:3, 0:3] represents the rotation part of the transformation matrix[0:3, 3] represents the translation part of the transformation
-
translate
(translation)¶ Translate the mesh in the three directions
Parameters: translation (numpy.array) – Translation vector (x, y, z)
-
units
¶ Mesh unit vectors
-
update_areas
(normals=None)¶
-
update_max
()¶
-
update_min
()¶
-
update_normals
(update_areas=True)¶ Update the normals and areas for all points
-
update_units
()¶
-
v0
¶
-
v1
¶
-
v2
¶
-
values
() → an object providing a view on D's values¶
-
vectors
¶
-
classmethod
warning
(*args, **kwargs)¶ Log a message with severity ‘WARNING’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
x
¶
-
y
¶
-
z
¶
-
stl.main module¶
stl.base module¶
-
stl.base.
AREA_SIZE_THRESHOLD
= 0¶ When removing empty areas, remove areas that are smaller than this
-
class
stl.base.
BaseMesh
(data, calculate_normals=True, remove_empty_areas=False, remove_duplicate_polygons=<RemoveDuplicates.NONE: 0>, name='', speedups=True, **kwargs)[source]¶ Bases:
python_utils.logger.Logged
,collections.abc.Mapping
Mesh object with easy access to the vectors through v0, v1 and v2. The normals, areas, min, max and units are calculated automatically.
Parameters: Variables: - name (str) – Name of the solid, only exists in ASCII files
- data (numpy.array) – Data as
BaseMesh.dtype()
- points (numpy.array) – All points (Nx9)
- normals (numpy.array) – Normals for this mesh, calculated automatically by default (Nx3)
- vectors (numpy.array) – Vectors in the mesh (Nx3x3)
- attr (numpy.array) – Attributes per vector (used by binary STL)
- x (numpy.array) – Points on the X axis by vertex (Nx3)
- y (numpy.array) – Points on the Y axis by vertex (Nx3)
- z (numpy.array) – Points on the Z axis by vertex (Nx3)
- v0 (numpy.array) – Points in vector 0 (Nx3)
- v1 (numpy.array) – Points in vector 1 (Nx3)
- v2 (numpy.array) – Points in vector 2 (Nx3)
>>> data = numpy.zeros(10, dtype=BaseMesh.dtype) >>> mesh = BaseMesh(data, remove_empty_areas=False) >>> # Increment vector 0 item 0 >>> mesh.v0[0] += 1 >>> mesh.v1[0] += 2
>>> # Check item 0 (contains v0, v1 and v2) >>> assert numpy.array_equal( ... mesh[0], ... numpy.array([1., 1., 1., 2., 2., 2., 0., 0., 0.])) >>> assert numpy.array_equal( ... mesh.vectors[0], ... numpy.array([[1., 1., 1.], ... [2., 2., 2.], ... [0., 0., 0.]])) >>> assert numpy.array_equal( ... mesh.v0[0], ... numpy.array([1., 1., 1.])) >>> assert numpy.array_equal( ... mesh.points[0], ... numpy.array([1., 1., 1., 2., 2., 2., 0., 0., 0.])) >>> assert numpy.array_equal( ... mesh.data[0], ... numpy.array(( ... [0., 0., 0.], ... [[1., 1., 1.], [2., 2., 2.], [0., 0., 0.]], ... [0]), ... dtype=BaseMesh.dtype)) >>> assert numpy.array_equal(mesh.x[0], numpy.array([1., 2., 0.]))
>>> mesh[0] = 3 >>> assert numpy.array_equal( ... mesh[0], ... numpy.array([3., 3., 3., 3., 3., 3., 3., 3., 3.]))
>>> len(mesh) == len(list(mesh)) True >>> (mesh.min_ < mesh.max_).all() True >>> mesh.update_normals() >>> mesh.units.sum() 0.0 >>> mesh.v0[:] = mesh.v1[:] = mesh.v2[:] = 0 >>> mesh.points.sum() 0.0
>>> mesh.v0 = mesh.v1 = mesh.v2 = 0 >>> mesh.x = mesh.y = mesh.z = 0
>>> mesh.attr = 1 >>> (mesh.attr == 1).all() True
>>> mesh.normals = 2 >>> (mesh.normals == 2).all() True
>>> mesh.vectors = 3 >>> (mesh.vectors == 3).all() True
>>> mesh.points = 4 >>> (mesh.points == 4).all() True
-
areas
¶ Mesh areas
-
attr
¶
-
classmethod
debug
(*args, **kwargs)¶ Log a message with severity ‘DEBUG’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
dtype
= dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), ('attr', '<u2', (1,))])¶ - normals:
numpy.float32()
, (3, ) - vectors:
numpy.float32()
, (3, 3) - attr:
numpy.uint16()
, (1, )
- normals:
-
classmethod
error
(*args, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
classmethod
exception
(*args, exc_info=True, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
get_mass_properties
()[source]¶ - Evaluate and return a tuple with the following elements:
- the volume
- the position of the center of gravity (COG)
- the inertia matrix expressed at the COG
Documentation can be found here: http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
-
classmethod
info
(*args, **kwargs)¶ Log a message with severity ‘INFO’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
classmethod
log
(msg, *args, **kwargs)¶ Log ‘msg % args’ with the integer severity ‘level’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
logger
= <Logger stl.base.BaseMesh (WARNING)>¶
-
max_
¶ Mesh maximum value
-
min_
¶ Mesh minimum value
-
normals
¶
-
points
¶
-
rotate
(axis, theta=0, point=None)[source]¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()
in the background.Note
Note that the point was accidentaly inverted with the old version of the code. To get the old and incorrect behaviour simply pass -point instead of point or -numpy.array(point) if you’re passing along an array.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
- point (numpy.array) – Rotation point so manual translation is not required
-
rotate_using_matrix
(rotation_matrix, point=None)[source]¶ Rotate using a given rotation matrix and optional rotation point
Note that this rotation produces clockwise rotations for positive angles which is arguably incorrect but will remain for legacy reasons. For more details, read here: https://github.com/WoLpH/numpy-stl/issues/166
-
classmethod
rotation_matrix
(axis, theta)[source]¶ Generate a rotation matrix to Rotate the matrix over the given axis by the given theta (angle)
Uses the Euler-Rodrigues formula for fast rotations.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
-
transform
(matrix)[source]¶ Transform the mesh with a rotation and a translation stored in a single 4x4 matrix
Parameters: matrix (numpy.array) – Transform matrix with shape (4, 4), where matrix[0:3, 0:3] represents the rotation part of the transformation matrix[0:3, 3] represents the translation part of the transformation
-
translate
(translation)[source]¶ Translate the mesh in the three directions
Parameters: translation (numpy.array) – Translation vector (x, y, z)
-
units
¶ Mesh unit vectors
-
v0
¶
-
v1
¶
-
v2
¶
-
values
() → an object providing a view on D's values¶
-
vectors
¶
-
classmethod
warning
(*args, **kwargs)¶ Log a message with severity ‘WARNING’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
x
¶
-
y
¶
-
z
¶
-
stl.base.
DIMENSIONS
= 3¶ Dimensions used in a vector
-
class
stl.base.
Dimension
[source]¶ Bases:
enum.IntEnum
An enumeration.
-
X
= 0¶ X index (for example, mesh.v0[0][X])
-
Y
= 1¶ Y index (for example, mesh.v0[0][Y])
-
Z
= 2¶ Z index (for example, mesh.v0[0][Z])
-
-
class
stl.base.
RemoveDuplicates
[source]¶ Bases:
enum.Enum
Choose whether to remove no duplicates, leave only a single of the duplicates or remove all duplicates (leaving holes).
-
ALL
= 2¶
-
NONE
= 0¶
-
SINGLE
= 1¶
-
-
stl.base.
VECTORS
= 3¶ Vectors in a point
stl.mesh module¶
-
class
stl.mesh.
Mesh
(data, calculate_normals=True, remove_empty_areas=False, remove_duplicate_polygons=<RemoveDuplicates.NONE: 0>, name='', speedups=True, **kwargs)[source]¶ Bases:
stl.stl.BaseStl
-
areas
¶ Mesh areas
-
attr
¶
-
check
()¶ Check the mesh is valid or not
-
classmethod
debug
(*args, **kwargs)¶ Log a message with severity ‘DEBUG’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
dtype
= dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), ('attr', '<u2', (1,))])¶
-
classmethod
error
(*args, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
classmethod
exception
(*args, exc_info=True, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format.
-
classmethod
from_file
(filename, calculate_normals=True, fh=None, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)¶ Load a mesh from a STL file
Parameters: - filename (str) – The file to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
classmethod
from_files
(filenames, calculate_normals=True, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)¶ Load multiple meshes from a STL file
Note: mode is hardcoded to ascii since binary stl files do not support the multi format
Parameters: - filenames (list(str)) – The files to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
classmethod
from_multi_file
(filename, calculate_normals=True, fh=None, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)¶ Load multiple meshes from a STL file
Note: mode is hardcoded to ascii since binary stl files do not support the multi format
Parameters: - filename (str) – The file to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
get_header
(name)¶
-
get_mass_properties
()¶ - Evaluate and return a tuple with the following elements:
- the volume
- the position of the center of gravity (COG)
- the inertia matrix expressed at the COG
Documentation can be found here: http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
-
get_mass_properties_with_density
(density)¶
-
get_unit_normals
()¶
-
classmethod
info
(*args, **kwargs)¶ Log a message with severity ‘INFO’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
is_closed
()¶ Check the mesh is closed or not
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
classmethod
load
(fh, mode=<Mode.AUTOMATIC: 0>, speedups=True)¶ Load Mesh from STL file
Automatically detects binary versus ascii STL files.
Parameters: - fh (file) – The file handle to open
- mode (int) – Automatically detect the filetype or force binary
-
classmethod
log
(msg, *args, **kwargs)¶ Log ‘msg % args’ with the integer severity ‘level’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
logger
= <Logger stl.base.BaseMesh (WARNING)>¶
-
max_
¶ Mesh maximum value
-
min_
¶ Mesh minimum value
-
normals
¶
-
points
¶
-
classmethod
remove_duplicate_polygons
(data, value=<RemoveDuplicates.SINGLE: 1>)¶
-
classmethod
remove_empty_areas
(data)¶
-
rotate
(axis, theta=0, point=None)¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()
in the background.Note
Note that the point was accidentaly inverted with the old version of the code. To get the old and incorrect behaviour simply pass -point instead of point or -numpy.array(point) if you’re passing along an array.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
- point (numpy.array) – Rotation point so manual translation is not required
-
rotate_using_matrix
(rotation_matrix, point=None)¶ Rotate using a given rotation matrix and optional rotation point
Note that this rotation produces clockwise rotations for positive angles which is arguably incorrect but will remain for legacy reasons. For more details, read here: https://github.com/WoLpH/numpy-stl/issues/166
-
classmethod
rotation_matrix
(axis, theta)¶ Generate a rotation matrix to Rotate the matrix over the given axis by the given theta (angle)
Uses the Euler-Rodrigues formula for fast rotations.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
-
save
(filename, fh=None, mode=<Mode.AUTOMATIC: 0>, update_normals=True)¶ Save the STL to a (binary) file
If mode is
AUTOMATIC
anASCII
file will be written if the output is a TTY and aBINARY
file otherwise.Parameters:
-
transform
(matrix)¶ Transform the mesh with a rotation and a translation stored in a single 4x4 matrix
Parameters: matrix (numpy.array) – Transform matrix with shape (4, 4), where matrix[0:3, 0:3] represents the rotation part of the transformation matrix[0:3, 3] represents the translation part of the transformation
-
translate
(translation)¶ Translate the mesh in the three directions
Parameters: translation (numpy.array) – Translation vector (x, y, z)
-
units
¶ Mesh unit vectors
-
update_areas
(normals=None)¶
-
update_max
()¶
-
update_min
()¶
-
update_normals
(update_areas=True)¶ Update the normals and areas for all points
-
update_units
()¶
-
v0
¶
-
v1
¶
-
v2
¶
-
values
() → an object providing a view on D's values¶
-
vectors
¶
-
classmethod
warning
(*args, **kwargs)¶ Log a message with severity ‘WARNING’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
x
¶
-
y
¶
-
z
¶
-
stl.stl module¶
-
stl.stl.
BUFFER_SIZE
= 4096¶ Amount of bytes to read while using buffered reading
-
class
stl.stl.
BaseStl
(data, calculate_normals=True, remove_empty_areas=False, remove_duplicate_polygons=<RemoveDuplicates.NONE: 0>, name='', speedups=True, **kwargs)[source]¶ Bases:
stl.base.BaseMesh
-
areas
¶ Mesh areas
-
attr
¶
-
check
()¶ Check the mesh is valid or not
-
classmethod
debug
(*args, **kwargs)¶ Log a message with severity ‘DEBUG’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
dtype
= dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), ('attr', '<u2', (1,))])¶
-
classmethod
error
(*args, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
classmethod
exception
(*args, exc_info=True, **kwargs)¶ Log a message with severity ‘ERROR’ on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format.
-
classmethod
from_file
(filename, calculate_normals=True, fh=None, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)[source]¶ Load a mesh from a STL file
Parameters: - filename (str) – The file to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
classmethod
from_files
(filenames, calculate_normals=True, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)[source]¶ Load multiple meshes from a STL file
Note: mode is hardcoded to ascii since binary stl files do not support the multi format
Parameters: - filenames (list(str)) – The files to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
classmethod
from_multi_file
(filename, calculate_normals=True, fh=None, mode=<Mode.AUTOMATIC: 0>, speedups=True, **kwargs)[source]¶ Load multiple meshes from a STL file
Note: mode is hardcoded to ascii since binary stl files do not support the multi format
Parameters: - filename (str) – The file to load
- calculate_normals (bool) – Whether to update the normals
- fh (file) – The file handle to open
- kwargs (dict) – The same as for
stl.mesh.Mesh
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
get_mass_properties
()¶ - Evaluate and return a tuple with the following elements:
- the volume
- the position of the center of gravity (COG)
- the inertia matrix expressed at the COG
Documentation can be found here: http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf
-
get_mass_properties_with_density
(density)¶
-
get_unit_normals
()¶
-
classmethod
info
(*args, **kwargs)¶ Log a message with severity ‘INFO’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
is_closed
()¶ Check the mesh is closed or not
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
classmethod
load
(fh, mode=<Mode.AUTOMATIC: 0>, speedups=True)[source]¶ Load Mesh from STL file
Automatically detects binary versus ascii STL files.
Parameters: - fh (file) – The file handle to open
- mode (int) – Automatically detect the filetype or force binary
-
classmethod
log
(msg, *args, **kwargs)¶ Log ‘msg % args’ with the integer severity ‘level’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
logger
= <Logger stl.base.BaseMesh (WARNING)>¶
-
max_
¶ Mesh maximum value
-
min_
¶ Mesh minimum value
-
normals
¶
-
points
¶
-
classmethod
remove_duplicate_polygons
(data, value=<RemoveDuplicates.SINGLE: 1>)¶
-
classmethod
remove_empty_areas
(data)¶
-
rotate
(axis, theta=0, point=None)¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()
in the background.Note
Note that the point was accidentaly inverted with the old version of the code. To get the old and incorrect behaviour simply pass -point instead of point or -numpy.array(point) if you’re passing along an array.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
- point (numpy.array) – Rotation point so manual translation is not required
-
rotate_using_matrix
(rotation_matrix, point=None)¶ Rotate using a given rotation matrix and optional rotation point
Note that this rotation produces clockwise rotations for positive angles which is arguably incorrect but will remain for legacy reasons. For more details, read here: https://github.com/WoLpH/numpy-stl/issues/166
-
classmethod
rotation_matrix
(axis, theta)¶ Generate a rotation matrix to Rotate the matrix over the given axis by the given theta (angle)
Uses the Euler-Rodrigues formula for fast rotations.
Parameters: - axis (numpy.array) – Axis to rotate over (x, y, z)
- theta (float) – Rotation angle in radians, use math.radians to convert degrees to radians if needed.
-
save
(filename, fh=None, mode=<Mode.AUTOMATIC: 0>, update_normals=True)[source]¶ Save the STL to a (binary) file
If mode is
AUTOMATIC
anASCII
file will be written if the output is a TTY and aBINARY
file otherwise.Parameters:
-
transform
(matrix)¶ Transform the mesh with a rotation and a translation stored in a single 4x4 matrix
Parameters: matrix (numpy.array) – Transform matrix with shape (4, 4), where matrix[0:3, 0:3] represents the rotation part of the transformation matrix[0:3, 3] represents the translation part of the transformation
-
translate
(translation)¶ Translate the mesh in the three directions
Parameters: translation (numpy.array) – Translation vector (x, y, z)
-
units
¶ Mesh unit vectors
-
update_areas
(normals=None)¶
-
update_max
()¶
-
update_min
()¶
-
update_normals
(update_areas=True)¶ Update the normals and areas for all points
-
update_units
()¶
-
v0
¶
-
v1
¶
-
v2
¶
-
values
() → an object providing a view on D's values¶
-
vectors
¶
-
classmethod
warning
(*args, **kwargs)¶ Log a message with severity ‘WARNING’ on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format.
-
x
¶
-
y
¶
-
z
¶
-
-
stl.stl.
COUNT_SIZE
= 4¶ The amount of bytes in the count field
-
stl.stl.
HEADER_FORMAT
= '{package_name} ({version}) {now} {name}'¶ The header format, can be safely monkeypatched. Limited to 80 characters
-
stl.stl.
HEADER_SIZE
= 80¶ The amount of bytes in the header field
-
stl.stl.
MAX_COUNT
= 100000000.0¶ The maximum amount of triangles we can read from binary files