.. meta:: :description: Code snippets affine transform UnstructuredGrid How to apply an affine transform to an UnstructuredGrid ======================================================= In this example we will apply an affine transform to different UnstructuredGrid. UnstructuredGrid is an abstract class who has 2 concrete subclasses: HalfEdgeMesh and FaceVertexMesh. Let's start by creating an instance of each of the UnstructuredGrid subclasses:: from ORSModel import Channel from ORSModel import FaceVertexMesh, HalfEdgeMesh channel = Channel() channel.setTitle('demo channel') #set it sizes, since we use the default voxel size, the channel is for now 100 meter cube channel.setXYZTSize(100,100,100,1) channel.setXSpacing(0.01) channel.setYSpacing(0.01) channel.setZSpacing(0.01) #now the channel is 1 meter cube #initilize it for float32 data channel.initializeDataForFLOAT() channelBox = channel.getBox() channelBox.grow(orsVect(-channelBox.getDirection0Size()*0.5, -channelBox.getDirection1Size()*0.5, -channelBox.getDirection2Size()*0.5)) channel.paintBox(channelBox, 1, 0) channelBox.grow(orsVect(-channelBox.getDirection0Size()*0.5, -channelBox.getDirection1Size()*0.5, -channelBox.getDirection2Size()*0.5)) channel.paintBox(channelBox, 2, 0) channel.setDataDirty() #publish it so that it is visible in the Object properties list channel.publish() faceMesh = FaceVertexMesh() channel.getAsMarchingCubeMesh(1 - 0.001, True, False, 0, 1, 1, 1, False, True, None, faceMesh) faceMesh.setTitle('Face mesh') halfEdgeMesh = HalfEdgeMesh() channel.getAsMarchingCubeMesh(2 - 0.0001, True, False, 0, 1, 1, 1, False, True, None, halfEdgeMesh) halfEdgeMesh.setTitle('Half edge mesh') faceMesh.publish() halfEdgeMesh.publish() Let's define an affine transform:: translation = Matrix4x4() translation.setTranslation(channel.getBox().getDirectionSizeVector()*0.25) rotationAxis = orsVect(0, 1, 0) rotation = Matrix4x4() rotation.setAsRotation(rotationAxis, 3.1416/8) scale = Matrix4x4() scale.setScale(orsVect(0.5,1,2)) #now let's concatenate these transformation, in an arbritrary order fullTransform = scale*rotation*translation Let's apply the affine transformation:: faceMeshT = faceMesh.copy() faceMeshT.setTitle(faceMesh.getTitle() + ' transformed') faceMeshT.publish() faceMesh.getTransformed(fullTransform, faceMeshT) halfEdgeMeshT = halfEdgeMesh.copy() halfEdgeMeshT.setTitle(halfEdgeMesh.getTitle() + ' transformed') halfEdgeMeshT.publish() halfEdgeMesh.getTransformed(fullTransform, halfEdgeMeshT)