With the 3D Image Processing module, you can translate, rotate, and scale a point cloud or 3D geometry. You can also apply a transformation matrix to 3D points to transform a point cloud or 3D geometry.
To displace a point cloud or 3D geometry, use M3dimTranslate(). Specify the required displacements along each axis direction, in world units. The translation applies to all points in the source object.
To rotate a point cloud or 3D geometry, use M3dimRotate(). Specify the point around which to rotate and the type of rotation to perform. You can choose from several rotation types, including rotation around a specified axis, quaternion rotation, and rotation around all 3 axes of the working coordinate system (also known as Roll-Pitch-Yaw rotation). Note that the default center of rotation is the origin (0,0,0). You can specify a custom center of rotation or, for 3D geometry objects, you can choose to center the rotation around the volumetric center of the object (M_GEOMETRY_CENTER).
To scale the distance between points in a point cloud or 3D geometry, use M3dimScale(). Specify the required factor by which to scale in each axis direction. The scaling is applied to each point's distance from the origin or specified center point, along X, Y, or Z. For example, if you specify a 0.5 scale factor along each axis, the resulting point cloud is half the size. That is, each point's distance from the center point (along X, Y, and Z) is half the distance as that of points in the source point cloud. As with rotation, you can specify to scale with respect to the volumetric center of a 3D geometry object.
Note that applying a non-uniform scale (that is, a scale with a different factor along each axis) changes the shape of the point cloud or 3D geometry. For this reason, you cannot apply a non-uniform scale to a box or sphere 3D geometry, because the result would no longer be a box or sphere.
To obtain a mirror-image of your source object, you can set negative scale factors.
To apply an arbitrary linear transformation to a point cloud or 3D geometry, apply the following:
Allocate a transformation matrix object using M3dgeoAlloc().
Generate the required transformation coefficients using M3dgeoMatrixSetTransform().
Apply the transformation matrix to the 3D points using M3dimMatrixTransform().
Note that you can also apply the transformation matrix to an array of 3D coordinates using M3dimMatrixTransformList().
The above procedure is useful when fixturing. See the How to fixture in 3D section of Chapter 39: Fixturing in 3D for more information.
If you apply multiple transformations consecutively (using M3dimTranslate(), M3dimRotate(), and/or M3dimScale()), MIL computes a new point cloud for each transformation. For better performance, you can generate a transformation matrix that combines all the transformations into one, and then apply it as a single transformation. To do so, use M3dgeoMatrixSetTransform() with M_COMPOSE_WITH_CURRENT, which will compose the coefficients of a specified transformation with the existing coefficients of the specified transformation matrix object. Alternatively, you can use M_COMPOSE_TWO_MATRICES to use the transformation that results from the composition of two matrices. Note that the order of the matrices matters.
The following code snippet is an example of the steps required to transform a point cloud:
/* Set transformation coefficients. */
M3dgeoMatrixSetTransform(MilMatrix, M_TRANSLATION, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, M_DEFAULT, M_DEFAULT);
M3dgeoMatrixSetTransform(MilMatrix, M_ROTATION_XYZ, ROTATION_X, ROTATION_Y, ROTATION_Z, M_DEFAULT, M_COMPOSE_WITH_CURRENT);
/* Find inverse matrix. */
M3dgeoMatrixSetTransform(MilMatrix, M_INVERSE, MilMatrix, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT);
/* Apply transformation to point cloud. */
M3dimMatrixTransform(MilPointCloud, MilDstPointCloud, MilMatrix, M_DEFAULT);