numpy-stl API Reference
Full documentation for numpy-stl (Standard Library / Native)
numpy-stl.BUFFER_SIZE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
numpy-stl.COUNT_SIZE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
numpy-stl.Dimension
Python Library Documentation: class Dimension in module stl.base class Dimension(enum.IntEnum) | Dimension(*values) | | Named indices for X/Y/Z axes. | | Method resolution order: | Dimension | enum.IntEnum | builtins.int | enum.ReprEnum | enum.Enum | builtins.object | | Methods defined here: | | __format__(self, format_spec, /) from builtins.int | Convert to a string according to format_spec. | | __new__(cls, value) from enum.Enum | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | X = <Dimension.X: 0> | | Y = <Dimension.Y: 1> | | Z = <Dimension.Z: 2> | | ---------------------------------------------------------------------- | Methods inherited from enum.IntEnum: | | __repr__(self) from enum.Enum | Return repr(self). | | __str__ = __repr__(self, /) from builtins.int | Return repr(self). | | ---------------------------------------------------------------------- | Methods inherited from builtins.int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __and__(self, value, /) | Return self&value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __invert__(self, /) | ~self | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __or__(self, value, /) | Return self|value. | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rand__(self, value, /) | Return value&self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __ror__(self, value, /) | Return value|self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | __xor__(self, value, /) | Return self^value. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from builtins.int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number | | ---------------------------------------------------------------------- | Methods inherited from enum.Enum: | | __dir__(self) | Returns public methods and other interesting attributes. | | __init__(self, *args, **kwds) | Initialize self. See help(type(self)) for accurate signature. | | __reduce_ex__(self, proto) | Helper for pickle. | | ---------------------------------------------------------------------- | Data descriptors inherited from enum.Enum: | | name | The name of the Enum member. | | value | The value of the Enum member. | | ---------------------------------------------------------------------- | Static methods inherited from enum.EnumType: | | __contains__(value) | Return True if `value` is in `cls`. | | `value` is in `cls` if: | 1) `value` is a member of `cls`, or | 2) `value` is the value of one of the `cls`'s members. | | __getitem__(name) | Return the member matching `name`. | | __iter__() | Return members in definition order. | | __len__() | Return the number of members (no aliases) | | ---------------------------------------------------------------------- | Readonly properties inherited from enum.EnumType: | | __members__ | Returns a mapping of member name->value. | | This mapping lists all enum members, including aliases. Note that this | is a read-only view of the internal mapping.
numpy-stl.HEADER_SIZE
Python Library Documentation: int object
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
numpy-stl.MAX_COUNT
Python Library Documentation: float object
class float(object)
| float(x=0, /)
|
| Convert a string or number to a floating-point number, if possible.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(self, /)
| Return the ceiling as an Integral.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(self, /)
| Return the floor as an Integral.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Formats the float according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(self, ndigits=None, /)
| Return the Integral closest to x, rounding half toward even.
|
| When an argument is passed, work like built-in round(x, ndigits).
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(self, /)
| Return the Integral closest to x between 0 and x.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is exactly equal to the original float.
|
| The ratio is in lowest terms and has a positive denominator. Raise
| OverflowError on infinities and a ValueError on NaNs.
|
| >>> (10.0).as_integer_ratio()
| (10, 1)
| >>> (0.0).as_integer_ratio()
| (0, 1)
| >>> (-.25).as_integer_ratio()
| (-1, 4)
|
| conjugate(self, /)
| Return self, the complex conjugate of any float.
|
| hex(self, /)
| Return a hexadecimal representation of a floating-point number.
|
| >>> (-0.1).hex()
| '-0x1.999999999999ap-4'
| >>> 3.14159.hex()
| '0x1.921f9f01b866ep+1'
|
| is_integer(self, /)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __getformat__(typestr, /)
| You probably don't want to use this function.
|
| typestr
| Must be 'double' or 'float'.
|
| It exists mainly to be used in Python's test suite.
|
| This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
| little-endian' best describes the format of floating-point numbers used by the
| C type named by typestr.
|
| fromhex(string, /)
| Create a floating-point number from a hexadecimal string.
|
| >>> float.fromhex('0x1.ffffp10')
| 2047.984375
| >>> float.fromhex('-0x1p-1074')
| -5e-324
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
numpy-stl.Mesh
Python Library Documentation: class Mesh in module stl.mesh
class Mesh(stl.stl.BaseStl)
| Mesh(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
|
| Primary user-facing class for STL mesh operations.
|
| Inherits all functionality from
| :class:`~stl.stl.BaseStl` and
| :class:`~stl.base.BaseMesh`. Use class methods
| like :meth:`from_file` and :meth:`from_multi_file`
| to load STL files, or pass a structured NumPy array
| to the constructor.
|
| Example:
| >>> import numpy as np
| >>> from stl import mesh
| >>> data = np.zeros(1, dtype=mesh.Mesh.dtype)
| >>> m = mesh.Mesh(data, remove_empty_areas=False)
| >>> len(m)
| 1
|
| Method resolution order:
| Mesh
| stl.stl.BaseStl
| stl.base.BaseMesh
| python_utils.logger.Logged
| python_utils.logger.LoggerBase
| abc.ABC
| collections.abc.Mapping
| collections.abc.Collection
| collections.abc.Sized
| collections.abc.Iterable
| collections.abc.Container
| builtins.object
|
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from stl.stl.BaseStl:
|
| get_header(self, name: '_Name') -> str
| Build the 80-byte binary STL header string.
|
| Args:
| name: Solid name to embed in the header.
|
| Returns:
| Header string truncated to 80 bytes.
|
| save(self, filename: '_Name', fh: 'IO[bytes] | None' = None, mode: 'Mode | int' = <Mode.AUTOMATIC: 0>, update_normals: bool = True) -> None
| Save the mesh to an STL file.
|
| If mode is :attr:`Mode.AUTOMATIC`, writes binary
| unless the output is a TTY.
|
| Args:
| filename: Output file path. Required even when
| ``fh`` is provided (used for STL header).
| fh: Optional pre-opened binary file handle.
| mode: Output format. Defaults to
| :attr:`Mode.AUTOMATIC`.
| update_normals: Whether to recalculate normals
| before saving. Defaults to True.
|
| Raises:
| TypeError: If ``fh`` is a text-mode handle.
| ValueError: If ``mode`` is not a valid
| :class:`Mode` value.
|
| Example:
| >>> import numpy as np
| >>> from stl import mesh
| >>> data = np.zeros(1, dtype=mesh.Mesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = mesh.Mesh(data, remove_empty_areas=False)
| >>> m.save('/tmp/_numpy_stl_test.stl')
|
| Warning:
| Even for ASCII output, the file handle must be
| opened in binary mode (``'wb'``). A text-mode
| handle raises ``TypeError``.
|
| save_ply(self, filename: str, fh: 'IO[bytes] | None' = None, mode: str = 'binary_little_endian', update_normals: bool = True) -> None
| Save the mesh to a PLY file.
|
| Args:
| filename: Output file path.
| fh: Optional pre-opened binary file handle.
| mode: PLY format. One of ``'ascii'``,
| ``'binary_little_endian'`` (default),
| ``'binary_big_endian'``.
| update_normals: Whether to recalculate normals
| before saving. Defaults to True.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> m.save_ply('/tmp/_numpy_stl_test.ply')
|
| ----------------------------------------------------------------------
| Class methods inherited from stl.stl.BaseStl:
|
| from_3mf_file(filename: str, calculate_normals: bool = True, **kwargs: object) -> collections.abc.Generator['Self', None, None]
| Load meshes from a 3MF file (read-only).
|
| Parses the 3MF ZIP archive and yields one Mesh
| per ``<mesh>`` element found.
|
| Args:
| filename: Path to the .3mf file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| **kwargs: Additional arguments.
|
| Yields:
| Mesh instances, one per 3MF mesh element.
|
| Example:
| >>> from stl import mesh
| >>> meshes = list(mesh.Mesh.from_3mf_file('tests/3mf/Moon.3mf'))
| >>> len(meshes) > 0
| True
|
| Note:
| 3MF support is experimental and read-only.
| Not all 3MF features are supported.
|
| from_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self'
| Load a mesh from an STL file.
|
| Reads binary or ASCII STL files. Format is
| auto-detected unless ``mode`` is explicitly set.
|
| Args:
| filename: Path to the STL file.
| calculate_normals: Whether to recalculate
| normals after loading. Defaults to True.
| fh: Optional pre-opened binary file handle.
| If provided, ``filename`` is used only
| for the mesh name.
| mode: Force ASCII or BINARY loading, or
| AUTOMATIC detection (default).
| speedups: Use Cython speedups for ASCII
| parsing when available. Defaults to True.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A new Mesh instance containing the loaded data.
|
| Raises:
| ValueError: If the file is empty.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> len(m.data) > 0
| True
|
| Note:
| When ``speedups`` is True and the speedups
| package is installed, ASCII parsing uses a
| fast C implementation. Speedups are
| automatically disabled for non-seekable
| streams (e.g., stdin).
|
| from_files(filenames: 'list[str]', calculate_normals: bool = True, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self'
| Load and merge multiple STL files into one mesh.
|
| Args:
| filenames: List of STL file paths.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| mode: Format mode for each file.
| speedups: Use Cython speedups when available.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A single Mesh with data from all files.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_files(['tests/stl_binary/HalfDonut.stl'])
| >>> len(m.data) > 0
| True
|
| from_multi_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> collections.abc.Generator['Self', None, None]
| Load multiple solids from a single STL file.
|
| Yields one Mesh per ``solid`` block found.
|
| Args:
| filename: Path to the STL file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| fh: Optional pre-opened binary file handle.
| mode: Format mode. Defaults to
| :attr:`Mode.AUTOMATIC`.
| speedups: Use Cython speedups when available.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Yields:
| Mesh instances, one per solid block.
|
| Example:
| >>> from stl import mesh
| >>> # Single-solid file yields one mesh
| >>> solids = list(
| ... mesh.Mesh.from_multi_file('tests/stl_ascii/HalfDonut.stl')
| ... )
| >>> len(solids) >= 1
| True
|
| Note:
| Multi-solid loading only works with ASCII
| STL files. Binary STL files always contain
| a single solid.
|
| from_ply_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, **kwargs: Any) -> 'Self'
| Load a mesh from a PLY file.
|
| Supports ASCII and binary PLY formats
| (little-endian and big-endian).
|
| Args:
| filename: Path to the .ply file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| fh: Optional pre-opened binary file handle.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A Mesh instance.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_ply_file('tests/ply_ascii/Cube.ply')
| >>> len(m.data) == 12
| True
|
| load(fh: IO[Any], mode: 'Mode | int' = <Mode.AUTOMATIC: 0>, speedups: bool = True) -> 'tuple[bytes, _data_1d] | Any'
| Load mesh data from an open STL file handle.
|
| Auto-detects binary vs ASCII format unless
| ``mode`` is explicitly set.
|
| Args:
| fh: Open binary file handle.
| mode: Force a specific format or use
| :attr:`Mode.AUTOMATIC` (default). Plain
| ints are accepted and converted to
| :class:`Mode`.
| speedups: Use Cython speedups for ASCII
| parsing. Defaults to True.
|
| Returns:
| A (name, data) tuple, or None if the file
| is empty.
|
| Raises:
| ValueError: If ``mode`` is not a valid
| :class:`Mode` value.
|
| ----------------------------------------------------------------------
| Methods inherited from stl.base.BaseMesh:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __getitem__(self, k: '_ToIndices', /) -> Any
|
| __hash__(self, /) from builtins.object
| Return hash(self).
|
| __init__(self, data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> collections.abc.Iterator[numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]]]
| # mappings iterate over keys, this iterates over values
|
| __len__(self) -> int
|
| __repr__(self) -> str
| Return repr(self).
|
| __setitem__(self, k: '_ToIndices', v: '_ArrayLikeFloat_co', /) -> None
|
| check(self, exact: bool = False) -> bool
| Check whether the mesh is valid (closed).
|
| Args:
| exact: If True, perform an exact edge-matching
| check. If False, use a faster normal-sum
| heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can
| produce false positives and false negatives.
| For reliable results, use ``exact=True``. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_
| and `#213 <https://github.com/WoLpH/numpy-stl/issues/213>`_.
|
| get_mass_properties(self) -> tuple[numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute volume, center of gravity, and inertia.
|
| Uses the polyhedral mass properties algorithm from
| Eberly (Geometric Tools).
|
| Returns:
| A tuple of (volume, center_of_gravity, inertia):
|
| - **volume** -- Mesh volume as float32.
| - **center_of_gravity** -- COG as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3) array
| expressed at the COG.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> vol, cog, inertia = m.get_mass_properties()
| >>> float(vol) > 0
| True
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values. Use
| :meth:`is_closed` to verify beforehand.
|
| get_mass_properties_with_density(self, density: float) -> tuple[numpy.float32, numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute mass properties with a given density.
|
| Like :meth:`get_mass_properties` but scales volume
| to mass using the provided density.
|
| Args:
| density: Material density in consistent units
| (e.g., kg/m^3 when mesh units are meters).
|
| Returns:
| A tuple of (volume, mass, cog, inertia):
|
| - **volume** -- Mesh volume.
| - **mass** -- Volume * density.
| - **cog** -- Center of gravity as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3)
| array.
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values.
|
| get_unit_normals(self) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float32]]
| Return a copy of normals normalized to unit length.
|
| Unlike the :attr:`units` property, this method
| always recomputes from the current :attr:`normals`
| array.
|
| Returns:
| Array of shape (N, 3) with unit-length normals.
| Zero-length normals remain as zeros.
|
| is_closed(self, exact: bool = False) -> bool
| Check whether the mesh is watertight.
|
| A closed mesh has every edge shared by exactly two
| triangles with consistent winding.
|
| Args:
| exact: If True, checks directed edges for
| matching pairs. If False, uses a faster
| normal-sum heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can give
| false positives and false negatives for certain
| mesh geometries. Use ``exact=True`` for reliable
| results. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_.
|
| is_convex(self) -> bool
| Return True if the mesh is convex.
|
| Tests whether every vertex lies on or behind every
| face plane.
|
| Returns:
| True if convex, False otherwise.
|
| rotate(self, axis: '_ToAxis', theta: float = 0, point: '_ToPoint | None' = None) -> None
| Rotate the mesh around an axis.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Example:
| >>> import math
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.rotate([0, 0, 1], math.radians(90))
|
| Warning:
| In older versions, the ``point`` parameter was
| accidentally inverted. If you relied on the old
| behavior, pass ``-point`` instead.
|
| rotate_using_matrix(self, rotation_matrix: '_f32_2d | _f64_2d', point: '_ToPoint | None' = None) -> None
| Rotate using a pre-computed rotation matrix.
|
| Args:
| rotation_matrix: A (3, 3) rotation matrix.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Warning:
| This method produces clockwise rotations for
| positive angles, which is arguably incorrect
| but retained for backwards compatibility. See
| `#166 <https://github.com/WoLpH/numpy-stl/issues/166>`_.
|
| transform(self, matrix: '_f32_2d | _f64_2d') -> None
| Apply a 4x4 transformation matrix.
|
| The upper-left 3x3 submatrix is the rotation.
| The rightmost column (0:3, 3) is the translation.
|
| Args:
| matrix: A (4, 4) transformation matrix. The
| rotation part must have unit determinant.
|
| Raises:
| AssertionError: If matrix shape is not (4, 4)
| or rotation determinant is not 1.0.
|
| translate(self, translation: '_ToTranslation') -> None
| Translate (move) the mesh.
|
| Args:
| translation: Translation vector [x, y, z].
|
| Raises:
| AssertionError: If translation is not length 3.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.translate([10, 20, 30])
| >>> float(m.v0[0][0])
| 10.0
|
| update_areas(self, normals: '_f32_2d | None' = None) -> None
| Refresh the cached per-triangle areas.
|
| Args:
| normals: Pre-computed cross products. If None,
| recomputes from current vertices.
|
| update_centroids(self) -> None
| Refresh the cached per-triangle centroids.
|
| update_max(self) -> None
| Refresh the cached bounding box maximum.
|
| update_min(self) -> None
| Refresh the cached bounding box minimum.
|
| update_normals(self, update_areas: bool = True, update_centroids: bool = True) -> None
| Recalculate normals from current vertex positions.
|
| Also refreshes areas and centroids by default.
|
| Args:
| update_areas: Whether to also refresh cached
| areas. Defaults to True.
| update_centroids: Whether to also refresh cached
| centroids. Defaults to True.
|
| update_units(self) -> None
| Refresh the cached unit normal vectors.
|
| ----------------------------------------------------------------------
| Static methods inherited from stl.base.BaseMesh:
|
| critical(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``CRITICAL`` level on the class logger.
|
| debug(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``DEBUG`` level on the class logger.
|
| error(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``ERROR`` level on the class logger.
|
| exception(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``ERROR`` level with exception info attached.
|
| info(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``INFO`` level on the class logger.
|
| log(level: 'int', msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at the integer ``level`` on the class logger.
|
| remove_duplicate_polygons(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], value: '_Dedupe' = <RemoveDuplicates.SINGLE: 1>) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove duplicate triangles from mesh data.
|
| Args:
| data: Structured mesh array.
| value: Deduplication strategy. Use
| :attr:`RemoveDuplicates.SINGLE` to keep one
| copy, :attr:`RemoveDuplicates.ALL` to remove
| all copies, or :attr:`RemoveDuplicates.NONE`
| to keep everything.
|
| Returns:
| Filtered mesh data array.
|
| Note:
| ``ALL`` has a safety fallback: when removing every
| duplicated polygon would drop half the mesh or more, a
| single copy of each duplicate is kept instead (the
| ``SINGLE`` behavior).
|
| remove_empty_areas(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove triangles with zero surface area.
|
| Filters out degenerate triangles where all three
| vertices are collinear or coincident.
|
| Args:
| data: Structured mesh array.
|
| Returns:
| Filtered mesh data array with zero-area
| triangles removed.
|
| rotation_matrix(axis: '_ToAxis', theta: float) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]
| Generate a 3x3 rotation matrix.
|
| Uses the Euler-Rodrigues formula for fast rotation
| matrix construction.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
|
| Returns:
| A (3, 3) rotation matrix. Returns the identity
| matrix if the axis is zero.
|
| warning(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``WARNING`` level on the class logger.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from stl.base.BaseMesh:
|
| areas
| Per-triangle surface areas, shape (N, 1).
|
| Lazily computed and cached. Call
| :meth:`update_areas` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(2, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> float(m.areas[0][0])
| 0.5
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_areas` to
| get correct results.
|
| attr
| Per-triangle attribute field (uint16), shape (N, 1).
|
| centroids
| Per-triangle centroids, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_centroids` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [3, 0, 0], [0, 3, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.centroids[0].tolist()
| [1.0, 1.0, 0.0]
|
| max_
| Bounding box maximum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_max`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_max` to
| refresh.
|
| min_
| Bounding box minimum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_min`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_min` to
| refresh.
|
| normals
| Per-triangle normal vectors, shape (N, 3).
|
| Lazily computed on first access. Call
| :meth:`update_normals` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.normals[0].tolist()
| [0.0, 0.0, 1.0]
|
| points
| All vertices flattened as (N, 9) array.
|
| units
| Per-triangle unit normal vectors, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_units` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.units[0].tolist()
| [0.0, 0.0, 1.0]
|
| v0
| First vertex of each triangle, shape (N, 3).
|
| v1
| Second vertex of each triangle, shape (N, 3).
|
| v2
| Third vertex of each triangle, shape (N, 3).
|
| vectors
| Triangle vertices as (N, 3, 3) array.
|
| x
| X coordinates by vertex, shape (N, 3).
|
| y
| Y coordinates by vertex, shape (N, 3).
|
| z
| Z coordinates by vertex, shape (N, 3).
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from stl.base.BaseMesh:
|
| __orig_bases__ = (<class 'python_utils.logger.Logged'>, collections.ab...
|
| dtype = dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), (...
|
| logger = <Logger stl.base.BaseMesh (WARNING)>
|
| ----------------------------------------------------------------------
| Static methods inherited from python_utils.logger.Logged:
|
| __new__(cls, *args: 'typing.Any', **kwargs: 'typing.Any') -> 'typing_extensions.Self'
| Create a new instance of the class and initialize the logger.
|
| The logger is named using the module and class name.
|
| Args:
| *args: Variable length argument list.
| **kwargs: Arbitrary keyword arguments.
|
| Returns:
| An instance of the class.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from python_utils.logger.LoggerBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from collections.abc.Mapping:
|
| __contains__(self, key)
|
| get(self, key, default=None)
| D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
|
| items(self)
| D.items() -> a set-like object providing a view on D's items
|
| keys(self)
| D.keys() -> a set-like object providing a view on D's keys
|
| values(self)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from collections.abc.Mapping:
|
| __reversed__ = None
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Collection:
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Iterable:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
numpy-stl.Mode
Python Library Documentation: class Mode in module stl.stl class Mode(enum.IntEnum) | Mode(*values) | | STL file format mode for loading and saving. | | Use :attr:`AUTOMATIC` for auto-detection (default), | :attr:`ASCII` to force ASCII format, or | :attr:`BINARY` to force binary format. | | Method resolution order: | Mode | enum.IntEnum | builtins.int | enum.ReprEnum | enum.Enum | builtins.object | | Methods defined here: | | __format__(self, format_spec, /) from builtins.int | Convert to a string according to format_spec. | | __new__(cls, value) from enum.Enum | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | ASCII = <Mode.ASCII: 1> | | AUTOMATIC = <Mode.AUTOMATIC: 0> | | BINARY = <Mode.BINARY: 2> | | ---------------------------------------------------------------------- | Methods inherited from enum.IntEnum: | | __repr__(self) from enum.Enum | Return repr(self). | | __str__ = __repr__(self, /) from builtins.int | Return repr(self). | | ---------------------------------------------------------------------- | Methods inherited from builtins.int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __and__(self, value, /) | Return self&value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __invert__(self, /) | ~self | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __or__(self, value, /) | Return self|value. | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rand__(self, value, /) | Return value&self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __ror__(self, value, /) | Return value|self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | __xor__(self, value, /) | Return self^value. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from builtins.int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number | | ---------------------------------------------------------------------- | Methods inherited from enum.Enum: | | __dir__(self) | Returns public methods and other interesting attributes. | | __init__(self, *args, **kwds) | Initialize self. See help(type(self)) for accurate signature. | | __reduce_ex__(self, proto) | Helper for pickle. | | ---------------------------------------------------------------------- | Data descriptors inherited from enum.Enum: | | name | The name of the Enum member. | | value | The value of the Enum member. | | ---------------------------------------------------------------------- | Static methods inherited from enum.EnumType: | | __contains__(value) | Return True if `value` is in `cls`. | | `value` is in `cls` if: | 1) `value` is a member of `cls`, or | 2) `value` is the value of one of the `cls`'s members. | | __getitem__(name) | Return the member matching `name`. | | __iter__() | Return members in definition order. | | __len__() | Return the number of members (no aliases) | | ---------------------------------------------------------------------- | Readonly properties inherited from enum.EnumType: | | __members__ | Returns a mapping of member name->value. | | This mapping lists all enum members, including aliases. Note that this | is a read-only view of the internal mapping.
numpy-stl.RemoveDuplicates
Python Library Documentation: class RemoveDuplicates in module stl.base class RemoveDuplicates(enum.Enum) | RemoveDuplicates(*values) | | Strategy for handling duplicate triangles. | | Use with :meth:`BaseMesh.remove_duplicate_polygons`. | | Method resolution order: | RemoveDuplicates | enum.Enum | builtins.object | | Data and other attributes defined here: | | ALL = <RemoveDuplicates.ALL: 2> | | NONE = <RemoveDuplicates.NONE: 0> | | SINGLE = <RemoveDuplicates.SINGLE: 1> | | ---------------------------------------------------------------------- | Data descriptors inherited from enum.Enum: | | name | The name of the Enum member. | | value | The value of the Enum member. | | ---------------------------------------------------------------------- | Static methods inherited from enum.EnumType: | | __contains__(value) | Return True if `value` is in `cls`. | | `value` is in `cls` if: | 1) `value` is a member of `cls`, or | 2) `value` is the value of one of the `cls`'s members. | | __getitem__(name) | Return the member matching `name`. | | __iter__() | Return members in definition order. | | __len__() | Return the number of members (no aliases) | | ---------------------------------------------------------------------- | Readonly properties inherited from enum.EnumType: | | __members__ | Returns a mapping of member name->value. | | This mapping lists all enum members, including aliases. Note that this | is a read-only view of the internal mapping.
numpy-stl.base
Python Library Documentation: module stl.base in stl
NAME
stl.base
CLASSES
collections.abc.Mapping(collections.abc.Collection)
BaseMesh(python_utils.logger.Logged, collections.abc.Mapping)
enum.Enum(builtins.object)
RemoveDuplicates
enum.IntEnum(builtins.int, enum.ReprEnum)
Dimension
python_utils.logger.Logged(python_utils.logger.LoggerBase)
BaseMesh(python_utils.logger.Logged, collections.abc.Mapping)
class BaseMesh(python_utils.logger.Logged, collections.abc.Mapping)
| BaseMesh(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
|
| Mesh object with easy access to vectors through v0, v1, v2.
|
| Normals, areas, min, max, and units are calculated
| automatically.
|
| Args:
| data: Structured NumPy array with dtype
| :attr:`BaseMesh.dtype`.
| calculate_normals: Whether to recalculate normals
| after loading. Defaults to True.
| remove_empty_areas: Whether to remove triangles
| with zero area. Defaults to False.
| remove_duplicate_polygons: Strategy for handling
| duplicate triangles. Defaults to
| :attr:`RemoveDuplicates.NONE`.
| name: Name of the solid (from ASCII STL header).
| speedups: Use Cython speedups when available.
| Defaults to True.
|
| >>> data = np.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 np.array_equal(
| ... mesh[0], np.array([1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0.0])
| ... )
| >>> assert np.array_equal(
| ... mesh.vectors[0],
| ... np.array([[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [0.0, 0.0, 0.0]]),
| ... )
| >>> assert np.array_equal(mesh.v0[0], np.array([1.0, 1.0, 1.0]))
| >>> assert np.array_equal(
| ... mesh.points[0],
| ... np.array([1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0.0]),
| ... )
| >>> assert np.array_equal(
| ... mesh.data[0],
| ... np.array(
| ... (
| ... [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],
| ... ),
| ... dtype=BaseMesh.dtype,
| ... ),
| ... )
| >>> assert np.array_equal(mesh.x[0], np.array([1.0, 2.0, 0.0]))
|
| >>> mesh[0] = 3
| >>> assert np.array_equal(
| ... mesh[0], np.array([3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0])
| ... )
|
| >>> len(mesh) == len(list(mesh))
| True
| >>> bool((mesh.min_ < mesh.max_).all())
| True
| >>> mesh.update_normals()
| >>> float(mesh.units.sum())
| 0.0
| >>> mesh.v0[:] = mesh.v1[:] = mesh.v2[:] = 0
| >>> float(mesh.points.sum())
| 0.0
|
| >>> mesh.v0 = mesh.v1 = mesh.v2 = 0
| >>> mesh.x = mesh.y = mesh.z = 0
|
| >>> mesh.attr = 1
| >>> bool((mesh.attr == 1).all())
| True
|
| >>> mesh.normals = 2
| >>> bool((mesh.normals == 2).all())
| True
|
| >>> mesh.vectors = 3
| >>> bool((mesh.vectors == 3).all())
| True
|
| >>> mesh.points = 4
| >>> bool((mesh.points == 4).all())
| True
|
| Method resolution order:
| BaseMesh
| python_utils.logger.Logged
| python_utils.logger.LoggerBase
| abc.ABC
| collections.abc.Mapping
| collections.abc.Collection
| collections.abc.Sized
| collections.abc.Iterable
| collections.abc.Container
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __getitem__(self, k: '_ToIndices', /) -> Any
|
| __hash__(self, /) from builtins.object
| Return hash(self).
|
| __init__(self, data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> collections.abc.Iterator[numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]]]
| # mappings iterate over keys, this iterates over values
|
| __len__(self) -> int
|
| __repr__(self) -> str
| Return repr(self).
|
| __setitem__(self, k: '_ToIndices', v: '_ArrayLikeFloat_co', /) -> None
|
| check(self, exact: bool = False) -> bool
| Check whether the mesh is valid (closed).
|
| Args:
| exact: If True, perform an exact edge-matching
| check. If False, use a faster normal-sum
| heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can
| produce false positives and false negatives.
| For reliable results, use ``exact=True``. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_
| and `#213 <https://github.com/WoLpH/numpy-stl/issues/213>`_.
|
| get_mass_properties(self) -> tuple[numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute volume, center of gravity, and inertia.
|
| Uses the polyhedral mass properties algorithm from
| Eberly (Geometric Tools).
|
| Returns:
| A tuple of (volume, center_of_gravity, inertia):
|
| - **volume** -- Mesh volume as float32.
| - **center_of_gravity** -- COG as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3) array
| expressed at the COG.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> vol, cog, inertia = m.get_mass_properties()
| >>> float(vol) > 0
| True
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values. Use
| :meth:`is_closed` to verify beforehand.
|
| get_mass_properties_with_density(self, density: float) -> tuple[numpy.float32, numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute mass properties with a given density.
|
| Like :meth:`get_mass_properties` but scales volume
| to mass using the provided density.
|
| Args:
| density: Material density in consistent units
| (e.g., kg/m^3 when mesh units are meters).
|
| Returns:
| A tuple of (volume, mass, cog, inertia):
|
| - **volume** -- Mesh volume.
| - **mass** -- Volume * density.
| - **cog** -- Center of gravity as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3)
| array.
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values.
|
| get_unit_normals(self) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float32]]
| Return a copy of normals normalized to unit length.
|
| Unlike the :attr:`units` property, this method
| always recomputes from the current :attr:`normals`
| array.
|
| Returns:
| Array of shape (N, 3) with unit-length normals.
| Zero-length normals remain as zeros.
|
| is_closed(self, exact: bool = False) -> bool
| Check whether the mesh is watertight.
|
| A closed mesh has every edge shared by exactly two
| triangles with consistent winding.
|
| Args:
| exact: If True, checks directed edges for
| matching pairs. If False, uses a faster
| normal-sum heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can give
| false positives and false negatives for certain
| mesh geometries. Use ``exact=True`` for reliable
| results. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_.
|
| is_convex(self) -> bool
| Return True if the mesh is convex.
|
| Tests whether every vertex lies on or behind every
| face plane.
|
| Returns:
| True if convex, False otherwise.
|
| rotate(self, axis: '_ToAxis', theta: float = 0, point: '_ToPoint | None' = None) -> None
| Rotate the mesh around an axis.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Example:
| >>> import math
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.rotate([0, 0, 1], math.radians(90))
|
| Warning:
| In older versions, the ``point`` parameter was
| accidentally inverted. If you relied on the old
| behavior, pass ``-point`` instead.
|
| rotate_using_matrix(self, rotation_matrix: '_f32_2d | _f64_2d', point: '_ToPoint | None' = None) -> None
| Rotate using a pre-computed rotation matrix.
|
| Args:
| rotation_matrix: A (3, 3) rotation matrix.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Warning:
| This method produces clockwise rotations for
| positive angles, which is arguably incorrect
| but retained for backwards compatibility. See
| `#166 <https://github.com/WoLpH/numpy-stl/issues/166>`_.
|
| transform(self, matrix: '_f32_2d | _f64_2d') -> None
| Apply a 4x4 transformation matrix.
|
| The upper-left 3x3 submatrix is the rotation.
| The rightmost column (0:3, 3) is the translation.
|
| Args:
| matrix: A (4, 4) transformation matrix. The
| rotation part must have unit determinant.
|
| Raises:
| AssertionError: If matrix shape is not (4, 4)
| or rotation determinant is not 1.0.
|
| translate(self, translation: '_ToTranslation') -> None
| Translate (move) the mesh.
|
| Args:
| translation: Translation vector [x, y, z].
|
| Raises:
| AssertionError: If translation is not length 3.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.translate([10, 20, 30])
| >>> float(m.v0[0][0])
| 10.0
|
| update_areas(self, normals: '_f32_2d | None' = None) -> None
| Refresh the cached per-triangle areas.
|
| Args:
| normals: Pre-computed cross products. If None,
| recomputes from current vertices.
|
| update_centroids(self) -> None
| Refresh the cached per-triangle centroids.
|
| update_max(self) -> None
| Refresh the cached bounding box maximum.
|
| update_min(self) -> None
| Refresh the cached bounding box minimum.
|
| update_normals(self, update_areas: bool = True, update_centroids: bool = True) -> None
| Recalculate normals from current vertex positions.
|
| Also refreshes areas and centroids by default.
|
| Args:
| update_areas: Whether to also refresh cached
| areas. Defaults to True.
| update_centroids: Whether to also refresh cached
| centroids. Defaults to True.
|
| update_units(self) -> None
| Refresh the cached unit normal vectors.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| critical(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at ``CRITICAL`` level on the class logger.
|
| debug(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at ``DEBUG`` level on the class logger.
|
| error(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at ``ERROR`` level on the class logger.
|
| exception(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at ``ERROR`` level with exception info attached.
|
| info(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at ``INFO`` level on the class logger.
|
| log(level: 'int', msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at the integer ``level`` on the class logger.
|
| remove_duplicate_polygons(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], value: '_Dedupe' = <RemoveDuplicates.SINGLE: 1>) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove duplicate triangles from mesh data.
|
| Args:
| data: Structured mesh array.
| value: Deduplication strategy. Use
| :attr:`RemoveDuplicates.SINGLE` to keep one
| copy, :attr:`RemoveDuplicates.ALL` to remove
| all copies, or :attr:`RemoveDuplicates.NONE`
| to keep everything.
|
| Returns:
| Filtered mesh data array.
|
| Note:
| ``ALL`` has a safety fallback: when removing every
| duplicated polygon would drop half the mesh or more, a
| single copy of each duplicate is kept instead (the
| ``SINGLE`` behavior).
|
| remove_empty_areas(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove triangles with zero surface area.
|
| Filters out degenerate triangles where all three
| vertices are collinear or coincident.
|
| Args:
| data: Structured mesh array.
|
| Returns:
| Filtered mesh data array with zero-area
| triangles removed.
|
| rotation_matrix(axis: '_ToAxis', theta: float) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]
| Generate a 3x3 rotation matrix.
|
| Uses the Euler-Rodrigues formula for fast rotation
| matrix construction.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
|
| Returns:
| A (3, 3) rotation matrix. Returns the identity
| matrix if the axis is zero.
|
| warning(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' from python_utils.logger.LoggerBase
| Log ``msg`` at ``WARNING`` level on the class logger.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| areas
| Per-triangle surface areas, shape (N, 1).
|
| Lazily computed and cached. Call
| :meth:`update_areas` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(2, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> float(m.areas[0][0])
| 0.5
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_areas` to
| get correct results.
|
| attr
| Per-triangle attribute field (uint16), shape (N, 1).
|
| centroids
| Per-triangle centroids, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_centroids` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [3, 0, 0], [0, 3, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.centroids[0].tolist()
| [1.0, 1.0, 0.0]
|
| max_
| Bounding box maximum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_max`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_max` to
| refresh.
|
| min_
| Bounding box minimum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_min`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_min` to
| refresh.
|
| normals
| Per-triangle normal vectors, shape (N, 3).
|
| Lazily computed on first access. Call
| :meth:`update_normals` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.normals[0].tolist()
| [0.0, 0.0, 1.0]
|
| points
| All vertices flattened as (N, 9) array.
|
| units
| Per-triangle unit normal vectors, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_units` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.units[0].tolist()
| [0.0, 0.0, 1.0]
|
| v0
| First vertex of each triangle, shape (N, 3).
|
| v1
| Second vertex of each triangle, shape (N, 3).
|
| v2
| Third vertex of each triangle, shape (N, 3).
|
| vectors
| Triangle vertices as (N, 3, 3) array.
|
| x
| X coordinates by vertex, shape (N, 3).
|
| y
| Y coordinates by vertex, shape (N, 3).
|
| z
| Z coordinates by vertex, shape (N, 3).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'_areas': numpy.ndarray[tuple[int, int], numpy.dtyp...
|
| __orig_bases__ = (<class 'python_utils.logger.Logged'>, collections.ab...
|
| dtype = dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), (...
|
| logger = <Logger stl.base.BaseMesh (WARNING)>
|
| ----------------------------------------------------------------------
| Static methods inherited from python_utils.logger.Logged:
|
| __new__(cls, *args: 'typing.Any', **kwargs: 'typing.Any') -> 'typing_extensions.Self'
| Create a new instance of the class and initialize the logger.
|
| The logger is named using the module and class name.
|
| Args:
| *args: Variable length argument list.
| **kwargs: Arbitrary keyword arguments.
|
| Returns:
| An instance of the class.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from python_utils.logger.LoggerBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from collections.abc.Mapping:
|
| __contains__(self, key)
|
| get(self, key, default=None)
| D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
|
| items(self)
| D.items() -> a set-like object providing a view on D's items
|
| keys(self)
| D.keys() -> a set-like object providing a view on D's keys
|
| values(self)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from collections.abc.Mapping:
|
| __reversed__ = None
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Collection:
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Iterable:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
class Dimension(enum.IntEnum)
| Dimension(*values)
|
| Named indices for X/Y/Z axes.
|
| Method resolution order:
| Dimension
| enum.IntEnum
| builtins.int
| enum.ReprEnum
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| X = <Dimension.X: 0>
|
| Y = <Dimension.Y: 1>
|
| Z = <Dimension.Z: 2>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntEnum:
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class RemoveDuplicates(enum.Enum)
| RemoveDuplicates(*values)
|
| Strategy for handling duplicate triangles.
|
| Use with :meth:`BaseMesh.remove_duplicate_polygons`.
|
| Method resolution order:
| RemoveDuplicates
| enum.Enum
| builtins.object
|
| Data and other attributes defined here:
|
| ALL = <RemoveDuplicates.ALL: 2>
|
| NONE = <RemoveDuplicates.NONE: 0>
|
| SINGLE = <RemoveDuplicates.SINGLE: 1>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
FUNCTIONS
logged(class_: type[~_LoggedT]) -> type[~_LoggedT]
Initialize the logger for a class.
Workaround for the Logged base class not properly
initializing on Linux.
Args:
class_: The class to add logging to.
Returns:
The class with logger initialized.
DATA
AREA_SIZE_THRESHOLD = 0
ClassVar = typing.ClassVar
Special type construct to mark class variables.
An annotation wrapped in ClassVar indicates that a given
attribute is intended to be used as a class variable and
should not be set on instances of that class.
Usage::
class Starship:
stats: ClassVar[dict[str, int]] = {} # class variable
damage: int = 10 # instance variable
ClassVar accepts only types and cannot be further subscribed.
Note that ClassVar is not a class itself, and should not
be used with isinstance() or issubclass().
DIMENSIONS = 3
Final = typing.Final
Special typing construct to indicate final names to type checkers.
A final name cannot be re-assigned or overridden in a subclass.
For example::
MAX_SIZE: Final = 9000
MAX_SIZE += 1 # Error reported by type checker
class Connection:
TIMEOUT: Final[int] = 10
class FastConnector(Connection):
TIMEOUT = 1 # Error reported by type checker
There is no runtime checking of these properties.
L = typing.Literal
Special typing form to define literal types (a.k.a. value types).
This form can be used to indicate to type checkers that the corresponding
variable or function parameter has a value equivalent to the provided
literal (or one of several literals)::
def validate_simple(data: Any) -> Literal[True]: # always returns True
...
MODE = Literal['r', 'rb', 'w', 'wb']
def open_helper(file: str, mode: MODE) -> str:
...
open_helper('/some/path', 'r') # Passes type check
open_helper('/other/path', 'typo') # Error in type checker
Literal[...] cannot be subclassed. At runtime, an arbitrary value
is allowed as type argument to Literal[...], but type checkers may
impose restrictions.
TYPE_CHECKING = False
TypeAlias = typing.TypeAlias
Special form for marking type aliases.
Use TypeAlias to indicate that an assignment should
be recognized as a proper type alias definition by type
checkers.
For example::
Predicate: TypeAlias = Callable[..., bool]
It's invalid when used anywhere except as in the example above.
VECTORS = 3
X = <Dimension.X: 0>
Y = <Dimension.Y: 1>
Z = <Dimension.Z: 2>
__annotations__ = {'AREA_SIZE_THRESHOLD': <class 'int'>, 'DIMENSIONS':...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\stl\base.py
numpy-stl.mesh
Python Library Documentation: module stl.mesh in stl
NAME
stl.mesh
CLASSES
stl.stl.BaseStl(stl.base.BaseMesh)
Mesh
class Mesh(stl.stl.BaseStl)
| Mesh(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
|
| Primary user-facing class for STL mesh operations.
|
| Inherits all functionality from
| :class:`~stl.stl.BaseStl` and
| :class:`~stl.base.BaseMesh`. Use class methods
| like :meth:`from_file` and :meth:`from_multi_file`
| to load STL files, or pass a structured NumPy array
| to the constructor.
|
| Example:
| >>> import numpy as np
| >>> from stl import mesh
| >>> data = np.zeros(1, dtype=mesh.Mesh.dtype)
| >>> m = mesh.Mesh(data, remove_empty_areas=False)
| >>> len(m)
| 1
|
| Method resolution order:
| Mesh
| stl.stl.BaseStl
| stl.base.BaseMesh
| python_utils.logger.Logged
| python_utils.logger.LoggerBase
| abc.ABC
| collections.abc.Mapping
| collections.abc.Collection
| collections.abc.Sized
| collections.abc.Iterable
| collections.abc.Container
| builtins.object
|
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from stl.stl.BaseStl:
|
| get_header(self, name: '_Name') -> str
| Build the 80-byte binary STL header string.
|
| Args:
| name: Solid name to embed in the header.
|
| Returns:
| Header string truncated to 80 bytes.
|
| save(self, filename: '_Name', fh: 'IO[bytes] | None' = None, mode: 'Mode | int' = <Mode.AUTOMATIC: 0>, update_normals: bool = True) -> None
| Save the mesh to an STL file.
|
| If mode is :attr:`Mode.AUTOMATIC`, writes binary
| unless the output is a TTY.
|
| Args:
| filename: Output file path. Required even when
| ``fh`` is provided (used for STL header).
| fh: Optional pre-opened binary file handle.
| mode: Output format. Defaults to
| :attr:`Mode.AUTOMATIC`.
| update_normals: Whether to recalculate normals
| before saving. Defaults to True.
|
| Raises:
| TypeError: If ``fh`` is a text-mode handle.
| ValueError: If ``mode`` is not a valid
| :class:`Mode` value.
|
| Example:
| >>> import numpy as np
| >>> from stl import mesh
| >>> data = np.zeros(1, dtype=mesh.Mesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = mesh.Mesh(data, remove_empty_areas=False)
| >>> m.save('/tmp/_numpy_stl_test.stl')
|
| Warning:
| Even for ASCII output, the file handle must be
| opened in binary mode (``'wb'``). A text-mode
| handle raises ``TypeError``.
|
| save_ply(self, filename: str, fh: 'IO[bytes] | None' = None, mode: str = 'binary_little_endian', update_normals: bool = True) -> None
| Save the mesh to a PLY file.
|
| Args:
| filename: Output file path.
| fh: Optional pre-opened binary file handle.
| mode: PLY format. One of ``'ascii'``,
| ``'binary_little_endian'`` (default),
| ``'binary_big_endian'``.
| update_normals: Whether to recalculate normals
| before saving. Defaults to True.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> m.save_ply('/tmp/_numpy_stl_test.ply')
|
| ----------------------------------------------------------------------
| Class methods inherited from stl.stl.BaseStl:
|
| from_3mf_file(filename: str, calculate_normals: bool = True, **kwargs: object) -> collections.abc.Generator['Self', None, None]
| Load meshes from a 3MF file (read-only).
|
| Parses the 3MF ZIP archive and yields one Mesh
| per ``<mesh>`` element found.
|
| Args:
| filename: Path to the .3mf file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| **kwargs: Additional arguments.
|
| Yields:
| Mesh instances, one per 3MF mesh element.
|
| Example:
| >>> from stl import mesh
| >>> meshes = list(mesh.Mesh.from_3mf_file('tests/3mf/Moon.3mf'))
| >>> len(meshes) > 0
| True
|
| Note:
| 3MF support is experimental and read-only.
| Not all 3MF features are supported.
|
| from_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self'
| Load a mesh from an STL file.
|
| Reads binary or ASCII STL files. Format is
| auto-detected unless ``mode`` is explicitly set.
|
| Args:
| filename: Path to the STL file.
| calculate_normals: Whether to recalculate
| normals after loading. Defaults to True.
| fh: Optional pre-opened binary file handle.
| If provided, ``filename`` is used only
| for the mesh name.
| mode: Force ASCII or BINARY loading, or
| AUTOMATIC detection (default).
| speedups: Use Cython speedups for ASCII
| parsing when available. Defaults to True.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A new Mesh instance containing the loaded data.
|
| Raises:
| ValueError: If the file is empty.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> len(m.data) > 0
| True
|
| Note:
| When ``speedups`` is True and the speedups
| package is installed, ASCII parsing uses a
| fast C implementation. Speedups are
| automatically disabled for non-seekable
| streams (e.g., stdin).
|
| from_files(filenames: 'list[str]', calculate_normals: bool = True, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self'
| Load and merge multiple STL files into one mesh.
|
| Args:
| filenames: List of STL file paths.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| mode: Format mode for each file.
| speedups: Use Cython speedups when available.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A single Mesh with data from all files.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_files(['tests/stl_binary/HalfDonut.stl'])
| >>> len(m.data) > 0
| True
|
| from_multi_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> collections.abc.Generator['Self', None, None]
| Load multiple solids from a single STL file.
|
| Yields one Mesh per ``solid`` block found.
|
| Args:
| filename: Path to the STL file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| fh: Optional pre-opened binary file handle.
| mode: Format mode. Defaults to
| :attr:`Mode.AUTOMATIC`.
| speedups: Use Cython speedups when available.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Yields:
| Mesh instances, one per solid block.
|
| Example:
| >>> from stl import mesh
| >>> # Single-solid file yields one mesh
| >>> solids = list(
| ... mesh.Mesh.from_multi_file('tests/stl_ascii/HalfDonut.stl')
| ... )
| >>> len(solids) >= 1
| True
|
| Note:
| Multi-solid loading only works with ASCII
| STL files. Binary STL files always contain
| a single solid.
|
| from_ply_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, **kwargs: Any) -> 'Self'
| Load a mesh from a PLY file.
|
| Supports ASCII and binary PLY formats
| (little-endian and big-endian).
|
| Args:
| filename: Path to the .ply file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| fh: Optional pre-opened binary file handle.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A Mesh instance.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_ply_file('tests/ply_ascii/Cube.ply')
| >>> len(m.data) == 12
| True
|
| load(fh: IO[Any], mode: 'Mode | int' = <Mode.AUTOMATIC: 0>, speedups: bool = True) -> 'tuple[bytes, _data_1d] | Any'
| Load mesh data from an open STL file handle.
|
| Auto-detects binary vs ASCII format unless
| ``mode`` is explicitly set.
|
| Args:
| fh: Open binary file handle.
| mode: Force a specific format or use
| :attr:`Mode.AUTOMATIC` (default). Plain
| ints are accepted and converted to
| :class:`Mode`.
| speedups: Use Cython speedups for ASCII
| parsing. Defaults to True.
|
| Returns:
| A (name, data) tuple, or None if the file
| is empty.
|
| Raises:
| ValueError: If ``mode`` is not a valid
| :class:`Mode` value.
|
| ----------------------------------------------------------------------
| Methods inherited from stl.base.BaseMesh:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __getitem__(self, k: '_ToIndices', /) -> Any
|
| __hash__(self, /) from builtins.object
| Return hash(self).
|
| __init__(self, data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> collections.abc.Iterator[numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]]]
| # mappings iterate over keys, this iterates over values
|
| __len__(self) -> int
|
| __repr__(self) -> str
| Return repr(self).
|
| __setitem__(self, k: '_ToIndices', v: '_ArrayLikeFloat_co', /) -> None
|
| check(self, exact: bool = False) -> bool
| Check whether the mesh is valid (closed).
|
| Args:
| exact: If True, perform an exact edge-matching
| check. If False, use a faster normal-sum
| heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can
| produce false positives and false negatives.
| For reliable results, use ``exact=True``. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_
| and `#213 <https://github.com/WoLpH/numpy-stl/issues/213>`_.
|
| get_mass_properties(self) -> tuple[numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute volume, center of gravity, and inertia.
|
| Uses the polyhedral mass properties algorithm from
| Eberly (Geometric Tools).
|
| Returns:
| A tuple of (volume, center_of_gravity, inertia):
|
| - **volume** -- Mesh volume as float32.
| - **center_of_gravity** -- COG as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3) array
| expressed at the COG.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> vol, cog, inertia = m.get_mass_properties()
| >>> float(vol) > 0
| True
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values. Use
| :meth:`is_closed` to verify beforehand.
|
| get_mass_properties_with_density(self, density: float) -> tuple[numpy.float32, numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute mass properties with a given density.
|
| Like :meth:`get_mass_properties` but scales volume
| to mass using the provided density.
|
| Args:
| density: Material density in consistent units
| (e.g., kg/m^3 when mesh units are meters).
|
| Returns:
| A tuple of (volume, mass, cog, inertia):
|
| - **volume** -- Mesh volume.
| - **mass** -- Volume * density.
| - **cog** -- Center of gravity as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3)
| array.
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values.
|
| get_unit_normals(self) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float32]]
| Return a copy of normals normalized to unit length.
|
| Unlike the :attr:`units` property, this method
| always recomputes from the current :attr:`normals`
| array.
|
| Returns:
| Array of shape (N, 3) with unit-length normals.
| Zero-length normals remain as zeros.
|
| is_closed(self, exact: bool = False) -> bool
| Check whether the mesh is watertight.
|
| A closed mesh has every edge shared by exactly two
| triangles with consistent winding.
|
| Args:
| exact: If True, checks directed edges for
| matching pairs. If False, uses a faster
| normal-sum heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can give
| false positives and false negatives for certain
| mesh geometries. Use ``exact=True`` for reliable
| results. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_.
|
| is_convex(self) -> bool
| Return True if the mesh is convex.
|
| Tests whether every vertex lies on or behind every
| face plane.
|
| Returns:
| True if convex, False otherwise.
|
| rotate(self, axis: '_ToAxis', theta: float = 0, point: '_ToPoint | None' = None) -> None
| Rotate the mesh around an axis.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Example:
| >>> import math
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.rotate([0, 0, 1], math.radians(90))
|
| Warning:
| In older versions, the ``point`` parameter was
| accidentally inverted. If you relied on the old
| behavior, pass ``-point`` instead.
|
| rotate_using_matrix(self, rotation_matrix: '_f32_2d | _f64_2d', point: '_ToPoint | None' = None) -> None
| Rotate using a pre-computed rotation matrix.
|
| Args:
| rotation_matrix: A (3, 3) rotation matrix.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Warning:
| This method produces clockwise rotations for
| positive angles, which is arguably incorrect
| but retained for backwards compatibility. See
| `#166 <https://github.com/WoLpH/numpy-stl/issues/166>`_.
|
| transform(self, matrix: '_f32_2d | _f64_2d') -> None
| Apply a 4x4 transformation matrix.
|
| The upper-left 3x3 submatrix is the rotation.
| The rightmost column (0:3, 3) is the translation.
|
| Args:
| matrix: A (4, 4) transformation matrix. The
| rotation part must have unit determinant.
|
| Raises:
| AssertionError: If matrix shape is not (4, 4)
| or rotation determinant is not 1.0.
|
| translate(self, translation: '_ToTranslation') -> None
| Translate (move) the mesh.
|
| Args:
| translation: Translation vector [x, y, z].
|
| Raises:
| AssertionError: If translation is not length 3.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.translate([10, 20, 30])
| >>> float(m.v0[0][0])
| 10.0
|
| update_areas(self, normals: '_f32_2d | None' = None) -> None
| Refresh the cached per-triangle areas.
|
| Args:
| normals: Pre-computed cross products. If None,
| recomputes from current vertices.
|
| update_centroids(self) -> None
| Refresh the cached per-triangle centroids.
|
| update_max(self) -> None
| Refresh the cached bounding box maximum.
|
| update_min(self) -> None
| Refresh the cached bounding box minimum.
|
| update_normals(self, update_areas: bool = True, update_centroids: bool = True) -> None
| Recalculate normals from current vertex positions.
|
| Also refreshes areas and centroids by default.
|
| Args:
| update_areas: Whether to also refresh cached
| areas. Defaults to True.
| update_centroids: Whether to also refresh cached
| centroids. Defaults to True.
|
| update_units(self) -> None
| Refresh the cached unit normal vectors.
|
| ----------------------------------------------------------------------
| Static methods inherited from stl.base.BaseMesh:
|
| critical(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``CRITICAL`` level on the class logger.
|
| debug(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``DEBUG`` level on the class logger.
|
| error(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``ERROR`` level on the class logger.
|
| exception(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``ERROR`` level with exception info attached.
|
| info(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``INFO`` level on the class logger.
|
| log(level: 'int', msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at the integer ``level`` on the class logger.
|
| remove_duplicate_polygons(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], value: '_Dedupe' = <RemoveDuplicates.SINGLE: 1>) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove duplicate triangles from mesh data.
|
| Args:
| data: Structured mesh array.
| value: Deduplication strategy. Use
| :attr:`RemoveDuplicates.SINGLE` to keep one
| copy, :attr:`RemoveDuplicates.ALL` to remove
| all copies, or :attr:`RemoveDuplicates.NONE`
| to keep everything.
|
| Returns:
| Filtered mesh data array.
|
| Note:
| ``ALL`` has a safety fallback: when removing every
| duplicated polygon would drop half the mesh or more, a
| single copy of each duplicate is kept instead (the
| ``SINGLE`` behavior).
|
| remove_empty_areas(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove triangles with zero surface area.
|
| Filters out degenerate triangles where all three
| vertices are collinear or coincident.
|
| Args:
| data: Structured mesh array.
|
| Returns:
| Filtered mesh data array with zero-area
| triangles removed.
|
| rotation_matrix(axis: '_ToAxis', theta: float) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]
| Generate a 3x3 rotation matrix.
|
| Uses the Euler-Rodrigues formula for fast rotation
| matrix construction.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
|
| Returns:
| A (3, 3) rotation matrix. Returns the identity
| matrix if the axis is zero.
|
| warning(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``WARNING`` level on the class logger.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from stl.base.BaseMesh:
|
| areas
| Per-triangle surface areas, shape (N, 1).
|
| Lazily computed and cached. Call
| :meth:`update_areas` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(2, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> float(m.areas[0][0])
| 0.5
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_areas` to
| get correct results.
|
| attr
| Per-triangle attribute field (uint16), shape (N, 1).
|
| centroids
| Per-triangle centroids, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_centroids` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [3, 0, 0], [0, 3, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.centroids[0].tolist()
| [1.0, 1.0, 0.0]
|
| max_
| Bounding box maximum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_max`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_max` to
| refresh.
|
| min_
| Bounding box minimum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_min`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_min` to
| refresh.
|
| normals
| Per-triangle normal vectors, shape (N, 3).
|
| Lazily computed on first access. Call
| :meth:`update_normals` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.normals[0].tolist()
| [0.0, 0.0, 1.0]
|
| points
| All vertices flattened as (N, 9) array.
|
| units
| Per-triangle unit normal vectors, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_units` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.units[0].tolist()
| [0.0, 0.0, 1.0]
|
| v0
| First vertex of each triangle, shape (N, 3).
|
| v1
| Second vertex of each triangle, shape (N, 3).
|
| v2
| Third vertex of each triangle, shape (N, 3).
|
| vectors
| Triangle vertices as (N, 3, 3) array.
|
| x
| X coordinates by vertex, shape (N, 3).
|
| y
| Y coordinates by vertex, shape (N, 3).
|
| z
| Z coordinates by vertex, shape (N, 3).
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from stl.base.BaseMesh:
|
| __orig_bases__ = (<class 'python_utils.logger.Logged'>, collections.ab...
|
| dtype = dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), (...
|
| logger = <Logger stl.base.BaseMesh (WARNING)>
|
| ----------------------------------------------------------------------
| Static methods inherited from python_utils.logger.Logged:
|
| __new__(cls, *args: 'typing.Any', **kwargs: 'typing.Any') -> 'typing_extensions.Self'
| Create a new instance of the class and initialize the logger.
|
| The logger is named using the module and class name.
|
| Args:
| *args: Variable length argument list.
| **kwargs: Arbitrary keyword arguments.
|
| Returns:
| An instance of the class.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from python_utils.logger.LoggerBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from collections.abc.Mapping:
|
| __contains__(self, key)
|
| get(self, key, default=None)
| D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
|
| items(self)
| D.items() -> a set-like object providing a view on D's items
|
| keys(self)
| D.keys() -> a set-like object providing a view on D's keys
|
| values(self)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from collections.abc.Mapping:
|
| __reversed__ = None
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Collection:
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Iterable:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\stl\mesh.py
numpy-stl.stl
Python Library Documentation: module stl.stl in stl
NAME
stl.stl
CLASSES
enum.IntEnum(builtins.int, enum.ReprEnum)
Mode
stl.base.BaseMesh(python_utils.logger.Logged, collections.abc.Mapping)
BaseStl
class BaseStl(stl.base.BaseMesh)
| BaseStl(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
|
| Method resolution order:
| BaseStl
| stl.base.BaseMesh
| python_utils.logger.Logged
| python_utils.logger.LoggerBase
| abc.ABC
| collections.abc.Mapping
| collections.abc.Collection
| collections.abc.Sized
| collections.abc.Iterable
| collections.abc.Container
| builtins.object
|
| Methods defined here:
|
| get_header(self, name: '_Name') -> str
| Build the 80-byte binary STL header string.
|
| Args:
| name: Solid name to embed in the header.
|
| Returns:
| Header string truncated to 80 bytes.
|
| save(self, filename: '_Name', fh: 'IO[bytes] | None' = None, mode: 'Mode | int' = <Mode.AUTOMATIC: 0>, update_normals: bool = True) -> None
| Save the mesh to an STL file.
|
| If mode is :attr:`Mode.AUTOMATIC`, writes binary
| unless the output is a TTY.
|
| Args:
| filename: Output file path. Required even when
| ``fh`` is provided (used for STL header).
| fh: Optional pre-opened binary file handle.
| mode: Output format. Defaults to
| :attr:`Mode.AUTOMATIC`.
| update_normals: Whether to recalculate normals
| before saving. Defaults to True.
|
| Raises:
| TypeError: If ``fh`` is a text-mode handle.
| ValueError: If ``mode`` is not a valid
| :class:`Mode` value.
|
| Example:
| >>> import numpy as np
| >>> from stl import mesh
| >>> data = np.zeros(1, dtype=mesh.Mesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = mesh.Mesh(data, remove_empty_areas=False)
| >>> m.save('/tmp/_numpy_stl_test.stl')
|
| Warning:
| Even for ASCII output, the file handle must be
| opened in binary mode (``'wb'``). A text-mode
| handle raises ``TypeError``.
|
| save_ply(self, filename: str, fh: 'IO[bytes] | None' = None, mode: str = 'binary_little_endian', update_normals: bool = True) -> None
| Save the mesh to a PLY file.
|
| Args:
| filename: Output file path.
| fh: Optional pre-opened binary file handle.
| mode: PLY format. One of ``'ascii'``,
| ``'binary_little_endian'`` (default),
| ``'binary_big_endian'``.
| update_normals: Whether to recalculate normals
| before saving. Defaults to True.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> m.save_ply('/tmp/_numpy_stl_test.ply')
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_3mf_file(filename: str, calculate_normals: bool = True, **kwargs: object) -> collections.abc.Generator['Self', None, None]
| Load meshes from a 3MF file (read-only).
|
| Parses the 3MF ZIP archive and yields one Mesh
| per ``<mesh>`` element found.
|
| Args:
| filename: Path to the .3mf file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| **kwargs: Additional arguments.
|
| Yields:
| Mesh instances, one per 3MF mesh element.
|
| Example:
| >>> from stl import mesh
| >>> meshes = list(mesh.Mesh.from_3mf_file('tests/3mf/Moon.3mf'))
| >>> len(meshes) > 0
| True
|
| Note:
| 3MF support is experimental and read-only.
| Not all 3MF features are supported.
|
| from_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self'
| Load a mesh from an STL file.
|
| Reads binary or ASCII STL files. Format is
| auto-detected unless ``mode`` is explicitly set.
|
| Args:
| filename: Path to the STL file.
| calculate_normals: Whether to recalculate
| normals after loading. Defaults to True.
| fh: Optional pre-opened binary file handle.
| If provided, ``filename`` is used only
| for the mesh name.
| mode: Force ASCII or BINARY loading, or
| AUTOMATIC detection (default).
| speedups: Use Cython speedups for ASCII
| parsing when available. Defaults to True.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A new Mesh instance containing the loaded data.
|
| Raises:
| ValueError: If the file is empty.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> len(m.data) > 0
| True
|
| Note:
| When ``speedups`` is True and the speedups
| package is installed, ASCII parsing uses a
| fast C implementation. Speedups are
| automatically disabled for non-seekable
| streams (e.g., stdin).
|
| from_files(filenames: 'list[str]', calculate_normals: bool = True, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self'
| Load and merge multiple STL files into one mesh.
|
| Args:
| filenames: List of STL file paths.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| mode: Format mode for each file.
| speedups: Use Cython speedups when available.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A single Mesh with data from all files.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_files(['tests/stl_binary/HalfDonut.stl'])
| >>> len(m.data) > 0
| True
|
| from_multi_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> collections.abc.Generator['Self', None, None]
| Load multiple solids from a single STL file.
|
| Yields one Mesh per ``solid`` block found.
|
| Args:
| filename: Path to the STL file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| fh: Optional pre-opened binary file handle.
| mode: Format mode. Defaults to
| :attr:`Mode.AUTOMATIC`.
| speedups: Use Cython speedups when available.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Yields:
| Mesh instances, one per solid block.
|
| Example:
| >>> from stl import mesh
| >>> # Single-solid file yields one mesh
| >>> solids = list(
| ... mesh.Mesh.from_multi_file('tests/stl_ascii/HalfDonut.stl')
| ... )
| >>> len(solids) >= 1
| True
|
| Note:
| Multi-solid loading only works with ASCII
| STL files. Binary STL files always contain
| a single solid.
|
| from_ply_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, **kwargs: Any) -> 'Self'
| Load a mesh from a PLY file.
|
| Supports ASCII and binary PLY formats
| (little-endian and big-endian).
|
| Args:
| filename: Path to the .ply file.
| calculate_normals: Whether to recalculate
| normals. Defaults to True.
| fh: Optional pre-opened binary file handle.
| **kwargs: Additional arguments passed to
| the Mesh constructor.
|
| Returns:
| A Mesh instance.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_ply_file('tests/ply_ascii/Cube.ply')
| >>> len(m.data) == 12
| True
|
| load(fh: IO[Any], mode: 'Mode | int' = <Mode.AUTOMATIC: 0>, speedups: bool = True) -> 'tuple[bytes, _data_1d] | Any'
| Load mesh data from an open STL file handle.
|
| Auto-detects binary vs ASCII format unless
| ``mode`` is explicitly set.
|
| Args:
| fh: Open binary file handle.
| mode: Force a specific format or use
| :attr:`Mode.AUTOMATIC` (default). Plain
| ints are accepted and converted to
| :class:`Mode`.
| speedups: Use Cython speedups for ASCII
| parsing. Defaults to True.
|
| Returns:
| A (name, data) tuple, or None if the file
| is empty.
|
| Raises:
| ValueError: If ``mode`` is not a valid
| :class:`Mode` value.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from stl.base.BaseMesh:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __getitem__(self, k: '_ToIndices', /) -> Any
|
| __hash__(self, /) from builtins.object
| Return hash(self).
|
| __init__(self, data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], calculate_normals: bool = True, remove_empty_areas: bool = False, remove_duplicate_polygons: '_Dedupe' = <RemoveDuplicates.NONE: 0>, name: 'bytes | str' = '', speedups: bool = True, **kwargs: object) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> collections.abc.Iterator[numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]]]
| # mappings iterate over keys, this iterates over values
|
| __len__(self) -> int
|
| __repr__(self) -> str
| Return repr(self).
|
| __setitem__(self, k: '_ToIndices', v: '_ArrayLikeFloat_co', /) -> None
|
| check(self, exact: bool = False) -> bool
| Check whether the mesh is valid (closed).
|
| Args:
| exact: If True, perform an exact edge-matching
| check. If False, use a faster normal-sum
| heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can
| produce false positives and false negatives.
| For reliable results, use ``exact=True``. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_
| and `#213 <https://github.com/WoLpH/numpy-stl/issues/213>`_.
|
| get_mass_properties(self) -> tuple[numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute volume, center of gravity, and inertia.
|
| Uses the polyhedral mass properties algorithm from
| Eberly (Geometric Tools).
|
| Returns:
| A tuple of (volume, center_of_gravity, inertia):
|
| - **volume** -- Mesh volume as float32.
| - **center_of_gravity** -- COG as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3) array
| expressed at the COG.
|
| Example:
| >>> from stl import mesh
| >>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
| >>> vol, cog, inertia = m.get_mass_properties()
| >>> float(vol) > 0
| True
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values. Use
| :meth:`is_closed` to verify beforehand.
|
| get_mass_properties_with_density(self, density: float) -> tuple[numpy.float32, numpy.float32, numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]], numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]]
| Compute mass properties with a given density.
|
| Like :meth:`get_mass_properties` but scales volume
| to mass using the provided density.
|
| Args:
| density: Material density in consistent units
| (e.g., kg/m^3 when mesh units are meters).
|
| Returns:
| A tuple of (volume, mass, cog, inertia):
|
| - **volume** -- Mesh volume.
| - **mass** -- Volume * density.
| - **cog** -- Center of gravity as (3,) array.
| - **inertia** -- Inertia tensor as (3, 3)
| array.
|
| Warning:
| These values are only meaningful for closed
| (watertight) meshes. This method checks via
| ``check(exact=True)`` and logs a warning for
| open meshes, but still computes and returns
| the (then unreliable) values.
|
| get_unit_normals(self) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float32]]
| Return a copy of normals normalized to unit length.
|
| Unlike the :attr:`units` property, this method
| always recomputes from the current :attr:`normals`
| array.
|
| Returns:
| Array of shape (N, 3) with unit-length normals.
| Zero-length normals remain as zeros.
|
| is_closed(self, exact: bool = False) -> bool
| Check whether the mesh is watertight.
|
| A closed mesh has every edge shared by exactly two
| triangles with consistent winding.
|
| Args:
| exact: If True, checks directed edges for
| matching pairs. If False, uses a faster
| normal-sum heuristic.
|
| Returns:
| True if the mesh is closed, False otherwise.
|
| Warning:
| The non-exact check (``exact=False``) can give
| false positives and false negatives for certain
| mesh geometries. Use ``exact=True`` for reliable
| results. See
| `#198 <https://github.com/WoLpH/numpy-stl/issues/198>`_.
|
| is_convex(self) -> bool
| Return True if the mesh is convex.
|
| Tests whether every vertex lies on or behind every
| face plane.
|
| Returns:
| True if convex, False otherwise.
|
| rotate(self, axis: '_ToAxis', theta: float = 0, point: '_ToPoint | None' = None) -> None
| Rotate the mesh around an axis.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Example:
| >>> import math
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.rotate([0, 0, 1], math.radians(90))
|
| Warning:
| In older versions, the ``point`` parameter was
| accidentally inverted. If you relied on the old
| behavior, pass ``-point`` instead.
|
| rotate_using_matrix(self, rotation_matrix: '_f32_2d | _f64_2d', point: '_ToPoint | None' = None) -> None
| Rotate using a pre-computed rotation matrix.
|
| Args:
| rotation_matrix: A (3, 3) rotation matrix.
| point: Optional point to rotate around. If
| None, rotates around the origin.
|
| Warning:
| This method produces clockwise rotations for
| positive angles, which is arguably incorrect
| but retained for backwards compatibility. See
| `#166 <https://github.com/WoLpH/numpy-stl/issues/166>`_.
|
| transform(self, matrix: '_f32_2d | _f64_2d') -> None
| Apply a 4x4 transformation matrix.
|
| The upper-left 3x3 submatrix is the rotation.
| The rightmost column (0:3, 3) is the translation.
|
| Args:
| matrix: A (4, 4) transformation matrix. The
| rotation part must have unit determinant.
|
| Raises:
| AssertionError: If matrix shape is not (4, 4)
| or rotation determinant is not 1.0.
|
| translate(self, translation: '_ToTranslation') -> None
| Translate (move) the mesh.
|
| Args:
| translation: Translation vector [x, y, z].
|
| Raises:
| AssertionError: If translation is not length 3.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.translate([10, 20, 30])
| >>> float(m.v0[0][0])
| 10.0
|
| update_areas(self, normals: '_f32_2d | None' = None) -> None
| Refresh the cached per-triangle areas.
|
| Args:
| normals: Pre-computed cross products. If None,
| recomputes from current vertices.
|
| update_centroids(self) -> None
| Refresh the cached per-triangle centroids.
|
| update_max(self) -> None
| Refresh the cached bounding box maximum.
|
| update_min(self) -> None
| Refresh the cached bounding box minimum.
|
| update_normals(self, update_areas: bool = True, update_centroids: bool = True) -> None
| Recalculate normals from current vertex positions.
|
| Also refreshes areas and centroids by default.
|
| Args:
| update_areas: Whether to also refresh cached
| areas. Defaults to True.
| update_centroids: Whether to also refresh cached
| centroids. Defaults to True.
|
| update_units(self) -> None
| Refresh the cached unit normal vectors.
|
| ----------------------------------------------------------------------
| Static methods inherited from stl.base.BaseMesh:
|
| critical(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``CRITICAL`` level on the class logger.
|
| debug(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``DEBUG`` level on the class logger.
|
| error(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``ERROR`` level on the class logger.
|
| exception(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``ERROR`` level with exception info attached.
|
| info(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``INFO`` level on the class logger.
|
| log(level: 'int', msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at the integer ``level`` on the class logger.
|
| remove_duplicate_polygons(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]], value: '_Dedupe' = <RemoveDuplicates.SINGLE: 1>) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove duplicate triangles from mesh data.
|
| Args:
| data: Structured mesh array.
| value: Deduplication strategy. Use
| :attr:`RemoveDuplicates.SINGLE` to keep one
| copy, :attr:`RemoveDuplicates.ALL` to remove
| all copies, or :attr:`RemoveDuplicates.NONE`
| to keep everything.
|
| Returns:
| Filtered mesh data array.
|
| Note:
| ``ALL`` has a safety fallback: when removing every
| duplicated polygon would drop half the mesh or more, a
| single copy of each duplicate is kept instead (the
| ``SINGLE`` behavior).
|
| remove_empty_areas(data: numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]) -> numpy.ndarray[tuple[int], numpy.dtype[numpy.void]]
| Remove triangles with zero surface area.
|
| Filters out degenerate triangles where all three
| vertices are collinear or coincident.
|
| Args:
| data: Structured mesh array.
|
| Returns:
| Filtered mesh data array with zero-area
| triangles removed.
|
| rotation_matrix(axis: '_ToAxis', theta: float) -> numpy.ndarray[tuple[int, int], numpy.dtype[numpy.float64]]
| Generate a 3x3 rotation matrix.
|
| Uses the Euler-Rodrigues formula for fast rotation
| matrix construction.
|
| Args:
| axis: Axis to rotate around as [x, y, z].
| theta: Rotation angle in radians. Use
| ``math.radians()`` to convert from degrees.
|
| Returns:
| A (3, 3) rotation matrix. Returns the identity
| matrix if the axis is zero.
|
| warning(msg: 'object', *args: 'object', exc_info: '_ExcInfoType' = None, stack_info: 'bool' = False, stacklevel: 'int' = 1, extra: 'collections.abc.Mapping[str, object] | None' = None) -> 'None' class method of stl.base.BaseMesh
| Log ``msg`` at ``WARNING`` level on the class logger.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from stl.base.BaseMesh:
|
| areas
| Per-triangle surface areas, shape (N, 1).
|
| Lazily computed and cached. Call
| :meth:`update_areas` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(2, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> float(m.areas[0][0])
| 0.5
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_areas` to
| get correct results.
|
| attr
| Per-triangle attribute field (uint16), shape (N, 1).
|
| centroids
| Per-triangle centroids, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_centroids` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [3, 0, 0], [0, 3, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.centroids[0].tolist()
| [1.0, 1.0, 0.0]
|
| max_
| Bounding box maximum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_max`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_max` to
| refresh.
|
| min_
| Bounding box minimum corner, shape (3,).
|
| Lazily computed and cached. Call :meth:`update_min`
| after modifying vertices to refresh.
|
| Warning:
| This value is cached on first access. If you
| modify vertices, call :meth:`update_min` to
| refresh.
|
| normals
| Per-triangle normal vectors, shape (N, 3).
|
| Lazily computed on first access. Call
| :meth:`update_normals` after modifying vertices
| to refresh.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.normals[0].tolist()
| [0.0, 0.0, 1.0]
|
| points
| All vertices flattened as (N, 9) array.
|
| units
| Per-triangle unit normal vectors, shape (N, 3).
|
| Lazily computed and cached. Call
| :meth:`update_units` after modifying vertices.
|
| Example:
| >>> import numpy as np
| >>> from stl.base import BaseMesh
| >>> data = np.zeros(1, dtype=BaseMesh.dtype)
| >>> data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
| >>> m = BaseMesh(data, remove_empty_areas=False)
| >>> m.units[0].tolist()
| [0.0, 0.0, 1.0]
|
| v0
| First vertex of each triangle, shape (N, 3).
|
| v1
| Second vertex of each triangle, shape (N, 3).
|
| v2
| Third vertex of each triangle, shape (N, 3).
|
| vectors
| Triangle vertices as (N, 3, 3) array.
|
| x
| X coordinates by vertex, shape (N, 3).
|
| y
| Y coordinates by vertex, shape (N, 3).
|
| z
| Z coordinates by vertex, shape (N, 3).
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from stl.base.BaseMesh:
|
| __orig_bases__ = (<class 'python_utils.logger.Logged'>, collections.ab...
|
| dtype = dtype([('normals', '<f4', (3,)), ('vectors', '<f4', (3, 3)), (...
|
| logger = <Logger stl.base.BaseMesh (WARNING)>
|
| ----------------------------------------------------------------------
| Static methods inherited from python_utils.logger.Logged:
|
| __new__(cls, *args: 'typing.Any', **kwargs: 'typing.Any') -> 'typing_extensions.Self'
| Create a new instance of the class and initialize the logger.
|
| The logger is named using the module and class name.
|
| Args:
| *args: Variable length argument list.
| **kwargs: Arbitrary keyword arguments.
|
| Returns:
| An instance of the class.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from python_utils.logger.LoggerBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from collections.abc.Mapping:
|
| __contains__(self, key)
|
| get(self, key, default=None)
| D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
|
| items(self)
| D.items() -> a set-like object providing a view on D's items
|
| keys(self)
| D.keys() -> a set-like object providing a view on D's keys
|
| values(self)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from collections.abc.Mapping:
|
| __reversed__ = None
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Collection:
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Class methods inherited from collections.abc.Iterable:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
class Mode(enum.IntEnum)
| Mode(*values)
|
| STL file format mode for loading and saving.
|
| Use :attr:`AUTOMATIC` for auto-detection (default),
| :attr:`ASCII` to force ASCII format, or
| :attr:`BINARY` to force binary format.
|
| Method resolution order:
| Mode
| enum.IntEnum
| builtins.int
| enum.ReprEnum
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ASCII = <Mode.ASCII: 1>
|
| AUTOMATIC = <Mode.AUTOMATIC: 0>
|
| BINARY = <Mode.BINARY: 2>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntEnum:
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
FUNCTIONS
StlMesh = from_file(filename: str, calculate_normals: bool = True, fh: 'IO[bytes] | None' = None, mode: stl.stl.Mode = <Mode.AUTOMATIC: 0>, speedups: bool = True, **kwargs: Any) -> 'Self' class method of BaseStl
Load a mesh from an STL file.
Reads binary or ASCII STL files. Format is
auto-detected unless ``mode`` is explicitly set.
Args:
filename: Path to the STL file.
calculate_normals: Whether to recalculate
normals after loading. Defaults to True.
fh: Optional pre-opened binary file handle.
If provided, ``filename`` is used only
for the mesh name.
mode: Force ASCII or BINARY loading, or
AUTOMATIC detection (default).
speedups: Use Cython speedups for ASCII
parsing when available. Defaults to True.
**kwargs: Additional arguments passed to
the Mesh constructor.
Returns:
A new Mesh instance containing the loaded data.
Raises:
ValueError: If the file is empty.
Example:
>>> from stl import mesh
>>> m = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')
>>> len(m.data) > 0
True
Note:
When ``speedups`` is True and the speedups
package is installed, ASCII parsing uses a
fast C implementation. Speedups are
automatically disabled for non-seekable
streams (e.g., stdin).
DATA
ASCII = <Mode.ASCII: 1>
AUTOMATIC = <Mode.AUTOMATIC: 0>
BINARY = <Mode.BINARY: 2>
BUFFER_SIZE = 4096
COUNT_SIZE = 4
HEADER_FORMAT = '{package_name} ({version}) {now} {name}'
HEADER_SIZE = 80
L = typing.Literal
Special typing form to define literal types (a.k.a. value types).
This form can be used to indicate to type checkers that the corresponding
variable or function parameter has a value equivalent to the provided
literal (or one of several literals)::
def validate_simple(data: Any) -> Literal[True]: # always returns True
...
MODE = Literal['r', 'rb', 'w', 'wb']
def open_helper(file: str, mode: MODE) -> str:
...
open_helper('/some/path', 'r') # Passes type check
open_helper('/other/path', 'typo') # Error in type checker
Literal[...] cannot be subclassed. At runtime, an arbitrary value
is allowed as type argument to Literal[...], but type checkers may
impose restrictions.
MAX_COUNT = 100000000.0
TYPE_CHECKING = False
__annotations__ = {'ASCII': typing.Literal[<Mode.ASCII: 1>], 'AUTOMATI...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\stl\stl.py
numpy-stl.utils
Python Library Documentation: module stl.utils in stl
NAME
stl.utils
FUNCTIONS
b(s: 'str | bytes', encoding: str = 'ascii', errors: str = 'replace') -> bytes
Encode a string to bytes, passing bytes through.
Args:
s: String or bytes input.
encoding: Encoding to use. Defaults to ``'ascii'``.
errors: Error handling strategy. Defaults to
``'replace'``.
Returns:
Encoded bytes.
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\stl\utils.py