Volume Cartographer 2.27.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Private Attributes | List of all members
volcart::Transform3D Class Referenceabstract

Base class for 3D transforms. More...

#include <vc/core/types/Transforms.hpp>

Inheritance diagram for volcart::Transform3D:
[legend]

Public Types

using Pointer = std::shared_ptr< Transform3D >
 
using Identifier = std::string
 

Public Member Functions

virtual ~Transform3D ()=default
 
 Transform3D (Transform3D &&)=delete
 
auto operator= (Transform3D &&other) -> Transform3D &=delete
 
virtual auto type () const -> std::string_view=0
 Return a string representation of the transform type. More...
 
virtual auto clone () const -> Pointer=0
 Clone the transform. More...
 
virtual auto invertible () const -> bool
 Return whether the underlying transform is invertible. More...
 
virtual auto invert () const -> Pointer
 Return the inverted transform. More...
 
virtual auto composable () const -> bool
 Return whether the underlying transform is composable. More...
 
virtual void reset ()=0
 Reset the transform parameters. More...
 
void clear ()
 Clears all parameters and properties of the transform.
 
void source (const std::string &src)
 Set the identifier for the source space. More...
 
auto source () const -> std::string
 Get the source space identifier. More...
 
void target (const std::string &tgt)
 Set the identifier for the target space. More...
 
auto target () const -> std::string
 Set the identifier for the target space. More...
 
virtual auto applyPoint (const cv::Vec3d &point) const -> cv::Vec3d=0
 Transform a 3D point. More...
 
virtual auto applyVector (const cv::Vec3d &vector) const -> cv::Vec3d=0
 Transform a 3D direction vector. More...
 
auto applyUnitVector (const cv::Vec3d &vector) const -> cv::Vec3d
 Transform a 3D direction unit vector. More...
 
auto applyPointAndNormal (const cv::Vec6d &ptN, bool normalize=true) const -> cv::Vec6d
 Transform a 3D point and surface normal stored in a cv::Vec6d. More...
 

Static Public Member Functions

static auto Compose (const Pointer &lhs, const Pointer &rhs) -> std::pair< Pointer, Pointer >
 Compose two transforms into a single new transform. More...
 
static void Save (const filesystem::path &path, const Pointer &transform)
 Save a transform to a JSON file.
 
static auto Load (const filesystem::path &path) -> Pointer
 Load a transform from a JSON file.
 

Static Public Attributes

static constexpr std::string_view TYPE {"Transform3D"}
 Transform type string constant. More...
 

Protected Types

using Metadata = nlohmann::ordered_json
 

Protected Member Functions

 Transform3D ()=default
 
 Transform3D (const Transform3D &)=default
 
auto operator= (const Transform3D &other) -> Transform3D &=default
 
virtual auto compose_ (const Pointer &rhs) const -> Pointer
 
virtual void to_meta_ (Metadata &meta)=0
 
virtual void from_meta_ (const Metadata &meta)=0
 

Static Protected Member Functions

static auto Serialize (const Pointer &transform) -> Metadata
 
static auto Deserialize (const Metadata &meta) -> Pointer
 

Private Attributes

std::string src_
 
std::string tgt_
 

Detailed Description

Base class for 3D transforms.

Provides a common interface for all 3D transforms. Transform implementations should derive from this class and be careful to implement all virtual functions. Because Transform3D objects are polymorphic in nature, they must be constructed on the heap using a New() static function or copied using the clone() member function.

Transforms can be applied from either the base or derived class.

// Construct and apply a transform
auto tfm = AffineTransform::New();
tfm.scale(10);
tfm.translate(0, 10, 0);
auto fromDerived = tfm->applyPoint({1, 1, 1});
// Convert to base class and apply transform
Transform::Pointer baseTfm = tfm;
auto fromBase = baseTfm->applyPoint({1, 1, 1});
if(fromDerived == fromBase) {
std::cout << "Matches." << std::endl;
}
static auto New() -> Pointer
Create a new AffineTransform.

Definition at line 49 of file Transforms.hpp.

Member Typedef Documentation

◆ Identifier

using volcart::Transform3D::Identifier = std::string

Transform identifier type (for VolumePkg)

Definition at line 59 of file Transforms.hpp.

◆ Metadata

using volcart::Transform3D::Metadata = nlohmann::ordered_json
protected

On-disk metadata type

Definition at line 193 of file Transforms.hpp.

◆ Pointer

using volcart::Transform3D::Pointer = std::shared_ptr<Transform3D>

Pointer type

Definition at line 56 of file Transforms.hpp.

Constructor & Destructor Documentation

◆ ~Transform3D()

virtual volcart::Transform3D::~Transform3D ( )
virtualdefault

Default constructor

◆ Transform3D() [1/3]

volcart::Transform3D::Transform3D ( Transform3D &&  )
delete

Disallow move construction

◆ Transform3D() [2/3]

volcart::Transform3D::Transform3D ( )
protecteddefault

Only derived classes can construct

◆ Transform3D() [3/3]

volcart::Transform3D::Transform3D ( const Transform3D )
protecteddefault

Only derived classes can copy

Member Function Documentation

◆ applyPoint()

virtual auto volcart::Transform3D::applyPoint ( const cv::Vec3d &  point) const -> cv::Vec3d
pure virtual

◆ applyPointAndNormal()

auto volcart::Transform3D::applyPointAndNormal ( const cv::Vec6d &  ptN,
bool  normalize = true 
) const -> cv::Vec6d

Transform a 3D point and surface normal stored in a cv::Vec6d.

This is a convenience function for transforming values stored in a PerPixelMap.

Parameters
ptNThe point and normal to be transformed.
normalizeIf true (default), the normal component of the output (the last 3 elements in the output) will be normalized.

◆ applyUnitVector()

auto volcart::Transform3D::applyUnitVector ( const cv::Vec3d &  vector) const -> cv::Vec3d

Transform a 3D direction unit vector.

This is a convenience function for vectors which should be normalized after transformation (e.g. surface normals).

◆ applyVector()

virtual auto volcart::Transform3D::applyVector ( const cv::Vec3d &  vector) const -> cv::Vec3d
pure virtual

Transform a 3D direction vector.

Implemented in volcart::AffineTransform, volcart::IdentityTransform, and volcart::CompositeTransform.

◆ clone()

virtual auto volcart::Transform3D::clone ( ) const -> Pointer
pure virtual

◆ composable()

virtual auto volcart::Transform3D::composable ( ) const -> bool
virtual

Return whether the underlying transform is composable.

Reimplemented in volcart::AffineTransform, and volcart::IdentityTransform.

◆ Compose()

static auto volcart::Transform3D::Compose ( const Pointer lhs,
const Pointer rhs 
) -> std::pair< Pointer, Pointer >
static

Compose two transforms into a single new transform.

Returns a pair of transform pointers. If the composition fails, the pair will contain pointers to both of the original inputs. If the second value in the pair is nullptr, then the composition was successful, and the new transform is available from the first pointer.

// Two transforms
// Compose and assign the results to existing variables
std::tie(lhs, rhs) = Transform3D::Compose(lhs, rhs);
// Check the result
if(rhs) {
std::cout << "Failed to compose transforms!\n";
} else {
std::cout << "Composition successful!\n";
}
std::shared_ptr< Transform3D > Pointer
Definition: Transforms.hpp:56
static auto Compose(const Pointer &lhs, const Pointer &rhs) -> std::pair< Pointer, Pointer >
Compose two transforms into a single new transform.

◆ compose_()

virtual auto volcart::Transform3D::compose_ ( const Pointer rhs) const -> Pointer
protectedvirtual

Helper compose function. The base implementation returns a nullptr. Implementing derived classes should set the returned transform's source to this->source() and the target to rhs->target().

Reimplemented in volcart::AffineTransform, and volcart::IdentityTransform.

◆ Deserialize()

static auto volcart::Transform3D::Deserialize ( const Metadata meta) -> Pointer
staticprotected

Deserialize the transform from metadata

◆ from_meta_()

virtual void volcart::Transform3D::from_meta_ ( const Metadata meta)
protectedpure virtual

Deserialize the derived class parameters

Implemented in volcart::AffineTransform, volcart::IdentityTransform, and volcart::CompositeTransform.

◆ invert()

virtual auto volcart::Transform3D::invert ( ) const -> Pointer
virtual

Return the inverted transform.

Reimplemented in volcart::AffineTransform, and volcart::IdentityTransform.

◆ invertible()

virtual auto volcart::Transform3D::invertible ( ) const -> bool
virtual

Return whether the underlying transform is invertible.

Reimplemented in volcart::AffineTransform, and volcart::IdentityTransform.

◆ operator=() [1/2]

auto volcart::Transform3D::operator= ( const Transform3D other) -> Transform3D &=default
protecteddefault

Only derived classes can copy

◆ operator=() [2/2]

auto volcart::Transform3D::operator= ( Transform3D &&  other) -> Transform3D &=delete
delete

Disallow move assignment

◆ reset()

virtual void volcart::Transform3D::reset ( )
pure virtual

Reset the transform parameters.

Resets all parameters controlled by the derived transform. Does not reset base transform properties like source and target.

See also
Transform3D::clear()

Implemented in volcart::AffineTransform, volcart::IdentityTransform, and volcart::CompositeTransform.

◆ Serialize()

static auto volcart::Transform3D::Serialize ( const Pointer transform) -> Metadata
staticprotected

Serialize the transform to metadata

◆ source() [1/2]

auto volcart::Transform3D::source ( ) const -> std::string

Get the source space identifier.

This is a convenience feature for tracking the input and output spaces for the transform. This is usually a Volume::Identifier.

◆ source() [2/2]

void volcart::Transform3D::source ( const std::string &  src)

Set the identifier for the source space.

This is a convenience feature for tracking the input and output spaces for the transform. This is usually a Volume::Identifier.

◆ target() [1/2]

auto volcart::Transform3D::target ( ) const -> std::string

Set the identifier for the target space.

This is a convenience feature for tracking the input and output spaces for the transform. This is usually a Volume::Identifier.

◆ target() [2/2]

void volcart::Transform3D::target ( const std::string &  tgt)

Set the identifier for the target space.

This is a convenience feature for tracking the input and output spaces for the transform. This is usually a Volume::Identifier.

◆ to_meta_()

virtual void volcart::Transform3D::to_meta_ ( Metadata meta)
protectedpure virtual

Serialize the derived class parameters

Implemented in volcart::AffineTransform, volcart::IdentityTransform, and volcart::CompositeTransform.

◆ type()

virtual auto volcart::Transform3D::type ( ) const -> std::string_view
pure virtual

Return a string representation of the transform type.

Implemented in volcart::AffineTransform, volcart::IdentityTransform, and volcart::CompositeTransform.

Member Data Documentation

◆ src_

std::string volcart::Transform3D::src_
private

Source space identifier

Definition at line 205 of file Transforms.hpp.

◆ tgt_

std::string volcart::Transform3D::tgt_
private

Target space identifier

Definition at line 207 of file Transforms.hpp.

◆ TYPE

constexpr std::string_view volcart::Transform3D::TYPE {"Transform3D"}
staticconstexpr

Transform type string constant.

Definition at line 53 of file Transforms.hpp.


The documentation for this class was generated from the following file: