core module

Package for defining the core AmpObject Copyright: Joshua Steer 2020, Joshua.Steer@soton.ac.uk

class AmpObject(data=None, stype='limb', unify=True, struc=True)

Bases: ampscan.trim.trimMixin, ampscan.smooth.smoothMixin, ampscan.vis.vis.visMixin

Base class for the ampscan project. Stores mesh data and extra information Inherits methods via mixins Flexible class able to deal with surface data using 3 or 4 node faces and visualise nodal data such as FEA outputs or shape deviations

Parameters:
  • data (str or dict) – Data input as either a string to import from an external file or a dictionary to pull values directly
  • stype (str, optional) – descriptor of the type of data the AmpObject is representing, e.g ‘limb’ or ‘socket’. Default is ‘limb’
Returns:

Initiation of the object

Return type:

AmpObject

Examples

>>> amp = AmpObject(filename)
calcEdgeFaces()

Function that calculates the indicies of the three edges that make up each face

Returns:edgesFace – Denoting the indicies of the three edges on each face
Return type:ndarray
calcEdges()

Function to compute the edges array ie the index of the two vertices that make up each edge

Returns:edges – Denoting the indicies of two vertices on each edge
Return type:ndarray
calcFaceEdges()

Function that calculates the indicies of the faces on each edge

Returns:faceEdges – The indicies of the faces in each edge, edges may have either 1 or 2 faces, if 1 then the second index will be NaN
Return type:ndarray
calcNorm()

Calculate the normal of each face of the AmpObj

Returns:norm – normal of each face
Return type:ndarray
calcStruct(norm=True, edges=True, edgeFaces=True, faceEdges=True, vNorm=False)

Top level function to calculate the underlying structure of the AmpObject

Parameters:
  • norm (boolean, default True) – If true, the normals of each face in the mesh will be calculated
  • edges (boolean, default True) – If true, the edges of the mesh will be calculated, the refers to the vertex index that make up any edge
  • edgeFaces (boolean, default True) – If true, the edgeFaces array of the mesh will be calculated, this refers to the index of the three edges that make up each face
  • faceEdges (boolean, default True) – If true, the faceEdges array will be calculated, this refers to index of the faces that are coincident to each edge. Normally, there are two faces per edge, if there is only one, then -99999 will be used to indicate this
  • vNorm (boolean, default False) – If true, the normals of each vertex in the mesh will be calculated
calcVNorm()

Function to compute the vertex normals based upon the mean of the connected face normals

Returns:vNorm – normal of each vertex
Return type:ndarray
centre()

Centre the AmpObject based upon the mean of all the vertices

centreStatic(static)

Centre this AmpObject on the static AmpObject’s centroid based upon the mean of all the vertices

Parameters:static (AmpObject) – The static shape to center this object onto
fixNorm()

Fix normals of faces so they all face outwards

flip(axis=1)

Flip the mesh in a plane

Parameters:axis (int, default 1) – The axis in which to flip the mesh
read_stl(filename, unify=True, struc=True)

Function to read .stl file from filename and import data into the AmpObj

Parameters:
  • filename (str) – file path of the .stl file to read
  • unify (boolean, default True) – unify the coincident vertices of each face
  • struc (boolean, default True) – Calculate the underlying structure of the mesh, such as edges
rigidTransform(R=None, T=None)

Perform a rigid transformation on the AmpObject, first the rotation, then the translation

Parameters:
  • R (array_like, default None) – A 3x3 array specifying the rotation matrix
  • T (array_like, defauly None) – An array of the form [x, y, z] which specifies the translation
static rotMatrix(rot, ang='rad')

Calculate the rotation matrix from three angles, the order is assumed as around the x, then y, then z axis

Parameters:
  • rot (array_like) – Rotation around [x, y, z]
  • ang (str, default 'rad') – Specify if the Euler angles are in degrees or radians
Returns:

R – The calculated 3x3 rotation matrix

Return type:

array_like

rotate(R, norms=True)

Rotate the AmpObject using a rotation matrix

Parameters:
  • R (array_like) – A 3x3 array specifying the rotation matrix
  • norms (boolean, default True) –
rotateAng(rot, ang='rad', norms=True)

Rotate the AmpObj in 3D space according to three angles

Parameters:
  • rot (array_like) – Rotation around [x, y, z]
  • ang (str, default 'rad') – Specify if the euler angles are in degrees or radians. Default is radians

Examples

>>> amp = AmpObject(filename)
>>> ang = [np.pi/2, -np.pi/4, np.pi/3]
>>> amp.rotateAng(ang, ang='rad')
save(filename)

Function to save the AmpObj as a binary .stl file

Parameters:filename (str) – file path of the .stl file to save to
translate(trans)

Translate the AmpObj in 3D space

Parameters:trans (array_like) – Translation in [x, y, z]
unifyVert()

Function to unify coincident vertices of the mesh to reduce size of the vertices array enabling speed increases when performing calculations using the vertex array

Examples

>>> amp = AmpObject(filename, unify=False)
>>> amp.vert.shape
(44832, 3)
>>> amp.unifyVert()
>>> amp.vert.shape
(7530, 3)