Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:57

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file orange/transform/detail/TransformTransformer.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "geocel/Types.hh"
0011 #include "orange/MatrixUtils.hh"
0012 
0013 #include "../NoTransformation.hh"
0014 #include "../Transformation.hh"
0015 #include "../Translation.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Apply a transformation to another transformation.
0024  *
0025  * An instance of this class applies a daughter-to-parent translation to
0026  * another transformation: the translation needed to relocate a "lower"
0027  * universe to a new coordinate system in the "higher" universe.
0028  *
0029  * Given a transform operator \b T defined \f[
0030    \mathbf{T}x = \mathbf{R} x + t
0031  * \f]
0032  * this operation returns a new transform
0033  * \f[
0034    \mathbf{T}' = \mathbf{T}_A \mathbf{T}_B
0035  * \f]
0036  * where \f$\mathbf{T}_A\f$ is the constructor argument
0037  * (the operator itself), \f$\mathbf{T}_b\f$ is the argument passed to the call
0038  * operator, and the \f$\mathbf{T}'\f$ is the return value.
0039  * The new transform has rotation
0040  * \f[
0041    \mathbf{R}' = \mathbf{R}_A\mathbf{R}_B
0042  * \f]
0043  * and translation
0044  * \f[
0045    \mathbf{t}' = \mathbf{R}_A\mathbf{t}_B + \mathbf{t}_A
0046  * \f]
0047  */
0048 class TransformTransformer
0049 {
0050   public:
0051     //@{
0052     //! \name Type aliases
0053     using Mat3 = SquareMatrix<real_type, 3>;
0054     //@}
0055 
0056   public:
0057     //! Construct with the new reference frame of the transformation
0058     explicit TransformTransformer(Transformation const& tr) : tr_{tr} {}
0059 
0060     //! Transform an identity
0061     Transformation const& operator()(NoTransformation const&) const
0062     {
0063         return tr_;
0064     }
0065 
0066     //!@{
0067     //! Transform a transformation
0068     inline Transformation operator()(Mat3 const&) const;
0069     inline Transformation operator()(Transformation const&) const;
0070     inline Transformation operator()(Translation const&) const;
0071     //!@}
0072 
0073   private:
0074     Transformation tr_;
0075 };
0076 
0077 //---------------------------------------------------------------------------//
0078 /*!
0079  * Apply a transformation to a rotation matrix.
0080  */
0081 Transformation TransformTransformer::operator()(Mat3 const& other) const
0082 {
0083     return Transformation{gemm(tr_.rotation(), other), tr_.translation()};
0084 }
0085 
0086 //---------------------------------------------------------------------------//
0087 /*!
0088  * Apply a transformation to a transform.
0089  */
0090 Transformation
0091 TransformTransformer::operator()(Transformation const& other) const
0092 {
0093     return Transformation{gemm(tr_.rotation(), other.rotation()),
0094                           tr_.transform_up(other.translation())};
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Apply a transformation to a translation.
0100  */
0101 Transformation TransformTransformer::operator()(Translation const& other) const
0102 {
0103     return Transformation{tr_.rotation(),
0104                           tr_.transform_up(other.translation())};
0105 }
0106 
0107 //---------------------------------------------------------------------------//
0108 }  // namespace detail
0109 }  // namespace celeritas