Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new transform types and utility functions #69

Merged
merged 9 commits into from
Nov 28, 2023
Merged

Conversation

csparker247
Copy link
Member

@csparker247 csparker247 commented Nov 28, 2023

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}

Example transform file:

{
  "type": "Transform3D",
  "source": "20231128010200",
  "target": "20231127120000",
  "transform-type": "IdentityTransform"
}

Composite transforms

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}

Example transform file:

{
  "type": "Transform3D",
  "source": "20231128010200",
  "target": "20231127120000",
  "transform-type": "CompositeTransform",
  "transform-stack": [
    {
      "type": "Transform3D",
      "source": "not-used",
      "target": "not-used",
      "transform-type": "AffineTransform",
      "params": [[1.0, 0.0, 0.0, 0.0],
                 [0.0, 1.0, 0.0, 0.0],
                 [0.0, 0.0, 1.0, 0.0],
                 [0.0, 0.0, 0.0, 1.0]]
    }
  ]
}

Other changes

  • 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.
  • Example transform files in examples/files/.

@csparker247 csparker247 added the enhancement New feature or request label Nov 28, 2023
@csparker247 csparker247 changed the title Add composite transforms Add new transform types Nov 28, 2023
@csparker247 csparker247 marked this pull request as ready for review November 28, 2023 18:36
@csparker247 csparker247 changed the title Add new transform types Add new transform types and utility functions Nov 28, 2023
@csparker247 csparker247 merged commit ac12472 into develop Nov 28, 2023
2 checks passed
@csparker247 csparker247 deleted the composite-tfms branch November 28, 2023 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant