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
-
debug(msg, *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,))])¶
-
error(msg, *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.
-
exception(msg, *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.
-
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
-
from_multi_file(filename, calculate_normals=True, fh=None, mode=<Mode.ASCII: 1>, speedups=True, **kwargs)¶ Load multiple meshes 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
-
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
-
info(msg, *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¶
-
load(fh, mode=<Mode.AUTOMATIC: 0>, speedups=True)¶ Load Mesh from STL file
Automatically detects binary versus ascii STL files.
Parameters:
-
log(level, 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= <logging.Logger object>¶
-
max_¶ Mesh maximum value
-
min_¶ Mesh minimum value
-
remove_duplicate_polygons(data, value=<RemoveDuplicates.SINGLE: 1>)¶
-
remove_empty_areas(data)¶
-
rotate(axis, theta, point=None)¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()in the background.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
-
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
AUTOMATICanASCIIfile will be written if the output is a TTY and aBINARYfile 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()¶
-
update_max()¶
-
update_min()¶
-
update_normals()¶ Update the normals for all points
-
update_units()¶
-
values() → an object providing a view on D's values¶
-
warning(msg, *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.
-
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.MappingMesh object with easy access to the vectors through v0, v1 and v2. The normals, areas, min, max and units are calculated automatically.
Parameters: - data (numpy.array) – The data for this mesh
- calculate_normals (bool) – Whether to calculate the normals
- remove_empty_areas (bool) – Whether to remove triangles with 0 area (due to rounding errors for example)
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) >>> mesh[0] array([ 1., 1., 1., 2., 2., 2., 0., 0., 0.], dtype=float32) >>> mesh.vectors[0] array([[ 1., 1., 1.], [ 2., 2., 2.], [ 0., 0., 0.]], dtype=float32) >>> mesh.v0[0] array([ 1., 1., 1.], dtype=float32) >>> mesh.points[0] array([ 1., 1., 1., 2., 2., 2., 0., 0., 0.], dtype=float32) >>> mesh.data[0] ([0.0, 0.0, 0.0], [[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [0.0, 0.0, 0.0]], [0]) >>> mesh.x[0] array([ 1., 2., 0.], dtype=float32)
>>> mesh[0] = 3 >>> mesh[0] array([ 3., 3., 3., 3., 3., 3., 3., 3., 3.], dtype=float32)
>>> 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
-
areas¶ Mesh areas
-
debug(msg, *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:
-
error(msg, *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.
-
exception(msg, *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
-
info(msg, *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¶
-
log(level, 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= <logging.Logger object>¶
-
max_¶ Mesh maximum value
-
min_¶ Mesh minimum value
-
rotate(axis, theta, point=None)[source]¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()in the background.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
-
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
-
values() → an object providing a view on D's values¶
-
warning(msg, *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.
-
stl.base.DIMENSIONS= 3¶ Dimensions used in a vector
-
class
stl.base.Dimension[source]¶ Bases:
enum.IntEnumAn 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.EnumChoose 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
-
debug(msg, *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,))])¶
-
error(msg, *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.
-
exception(msg, *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.
-
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
-
from_multi_file(filename, calculate_normals=True, fh=None, mode=<Mode.ASCII: 1>, speedups=True, **kwargs)¶ Load multiple meshes 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
-
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
-
info(msg, *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¶
-
load(fh, mode=<Mode.AUTOMATIC: 0>, speedups=True)¶ Load Mesh from STL file
Automatically detects binary versus ascii STL files.
Parameters:
-
log(level, 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= <logging.Logger object>¶
-
max_¶ Mesh maximum value
-
min_¶ Mesh minimum value
-
remove_duplicate_polygons(data, value=<RemoveDuplicates.SINGLE: 1>)¶
-
remove_empty_areas(data)¶
-
rotate(axis, theta, point=None)¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()in the background.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
-
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
AUTOMATICanASCIIfile will be written if the output is a TTY and aBINARYfile 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()¶
-
update_max()¶
-
update_min()¶
-
update_normals()¶ Update the normals for all points
-
update_units()¶
-
values() → an object providing a view on D's values¶
-
warning(msg, *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.
-
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
-
debug(msg, *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,))])¶
-
error(msg, *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.
-
exception(msg, *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_multi_file(filename, calculate_normals=True, fh=None, mode=<Mode.ASCII: 1>, speedups=True, **kwargs)[source]¶ Load multiple meshes 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
-
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
-
info(msg, *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
load(fh, mode=<Mode.AUTOMATIC: 0>, speedups=True)[source]¶ Load Mesh from STL file
Automatically detects binary versus ascii STL files.
Parameters:
-
log(level, 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= <logging.Logger object>¶
-
max_¶ Mesh maximum value
-
min_¶ Mesh minimum value
-
remove_duplicate_polygons(data, value=<RemoveDuplicates.SINGLE: 1>)¶
-
remove_empty_areas(data)¶
-
rotate(axis, theta, point=None)¶ Rotate the matrix over the given axis by the given theta (angle)
Uses the
rotation_matrix()in the background.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
-
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
AUTOMATICanASCIIfile will be written if the output is a TTY and aBINARYfile 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()¶
-
update_max()¶
-
update_min()¶
-
update_normals()¶ Update the normals for all points
-
update_units()¶
-
values() → an object providing a view on D's values¶
-
warning(msg, *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.
-
-
stl.stl.COUNT_SIZE= 4¶ The amount of bytes in the count field
-
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