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: trimMixin, smoothMixin, 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

close(overwrite=False)
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

getFaces()

Function to return the faces array

getLandmarks()

Function to return the landmarks dictionary

getValues()

Function to return the values array

getVert()

Function to return the vert array

read_aop(filename, unify=True, struc=True)

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

Parameters
  • filename (str) – file path of the .stl file to read

  • struc (boolean, default True) – Calculate the underlying structure of the mesh, such as edges

  • file (To access the landmarks use te getLandmarks() methods after the) –

  • imported (has been) –

read_bytes(data, 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

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

save_aop(filename, slices=100, spokes=72, sliceInterval=None, spokeInterval=None, closeEnd=True, centreEnd=True, side=None, adaptive=False, commments=None, landmarks=False, returnVerts=False)

Function to save the AmpObj as an aop file

Parameters
  • filename (str) – file path of the .aop file to save to

  • spokes (int or array_like) – Either number of evenly spaced spokes or an array of spoke theta (in degrees)

  • slices (int or array_like) – Either number of evenly spaced slices or an array of slice heights

  • spokeInterval (float) – Target spoke interval in degrees, will override spokes variable, must be less than 360

  • slicesInterval (float) – Target slice interval in mm, will override slices variable

  • closeEnd (bool, default True) – If True, then this will overwrite the most distal slice to close the shpae

  • centreEnd (bool, default True) – If True, this will translate the shape so the distal end is centered in the x and y plane

  • side (str, default NONE) – Either ‘LEFT’, ‘RIGHT’ or ‘NONE’ for the side

  • adaptive (bool, default False) – If True, this will add slices where there is significant change in perimeter between consecutive slices

  • comments (str, default None) – Any additional comments to add to the file

  • landmarks (dict or bool, default False) – If True, then use the landmarks within the object. Otherwise pass a dictionary with string keys and numpy arrays of size [n x 3] where n is the number of points in each landmark. Ensure passed in cartesian co-ordinates for ampscan

  • returnVerts (bool, default False) – if True, return the resampled verts in an N x 3 numpy array in cylindrical co-ordinates (r, theta, z)

scale(sf)

Scale the vertices of the AmpObject by some scaling factor

Parameters

sf (float) – The scaling factor to apply to the verts

setFaces(faces)

Function to set the faces array

setLandmarks(landmarks)

Function to set the landmarks dictionary

setValues(values)

Function to set the values array

setVert(vert)

Function to set the vert array

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)