Follow-up to #67 which adds IdentityTransform and CompositeTransform, as well as various new transform-related QoL features.
Identity transforms
New IdentityTransform class which doesn't apply any transform to the inputs. Useful for explicitly defining a map between two coordinate spaces that are inherently aligned.
auto tfm = IdentityTransform::New();
auto res = tfm->applyPoint({5, 10, 15}); // {5, 10, 15}
New CompositeTransform class which stores a list of transforms. When applied, each transform in the list is applied in sequence:
// create a composite transform
auto tfm = CompositeTransform::New();
// add a translation to the composite transform
auto a = AffineTransform::New();
a->translate(1, 2, 3);
tfm->push_back(a);
// add a scale to the composite
a->reset();
a->scale(5);
tfm->push_back(a);
// apply to a point
tfm->applyPoint({0, 0, 0}); // {5, 10, 15}
If the transforms are all composable, the transform can be simplified with the CompositeTransform::simplify() member function:
// create a composite transform
auto tfm = CompositeTransform::New();
// set up an affine transform
auto a = AffineTransform::New();
a->translate(1, 2, 3);
tfm->push_back(a); // forward translate
tfm->push_back(IdentityTransform::New()); // no-op transform
tfm->push_back(a->invert()); // undo translate
// simplify
tfm->size(); // contains 3 transforms
tfm->simplify();
tfm->size(); // contains 1 transform
// apply to a point
tfm->applyPoint({0, 0, 0}); // {0, 0, 0}
New Transform3D::Compose() static member function for composing two composable transforms into a single transform. Alternatively, use the * operator with two composable transforms:
auto res = affine0 * affine1;
New Transform3D::composable() function which returns whether the derived class supports composition. Derived transform classes which are composable should override both this function and the private member function compose_().
Transform3D::clear() is now derived only in the base class.
New Transform3D::Serialize and Transform3D::Deserialize` protected static member functions for storing/restoring a transform to/from metadata.
Follow-up to #67 which adds
IdentityTransform
andCompositeTransform
, as well as various new transform-related QoL features.Identity transforms
New
IdentityTransform
class which doesn't apply any transform to the inputs. Useful for explicitly defining a map between two coordinate spaces that are inherently aligned.Example transform file:
Composite transforms
New
CompositeTransform
class which stores a list of transforms. When applied, each transform in the list is applied in sequence:If the transforms are all composable, the transform can be simplified with the
CompositeTransform::simplify()
member function:Example transform file:
Other changes
Transform3D::Compose()
static member function for composing two composable transforms into a single transform. Alternatively, use the*
operator with two composable transforms:Transform3D::composable()
function which returns whether the derived class supports composition. Derived transform classes which are composable should override both this function and the private member functioncompose_()
.Transform3D::clear()
is now derived only in the base class.Transform3D::Serialize
and Transform3D::Deserialize` protected static member functions for storing/restoring a transform to/from metadata.examples/files/
.