Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/orange/transform/detail/TransformTranslator.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/transform/detail/TransformTranslator.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/math/ArrayOperators.hh"
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 translation to a transform to get another transform.
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  * and a translation operator defined \f[
0033    \mathbf{\tilde T} x = x + t
0034  * \f]
0035  * where \f$ \mathbf{R} = \mathbf{I} \f$ is the implicit rotation matrix for
0036  * a translation, this operation returns a new transform
0037  * \f[
0038    \mathbf{T}' = \mathbf{\tilde T}_A \mathbf{T}_B
0039  * \f]
0040  * where \f$\mathbf{\tilde T}_A\f$ is the constructor argument, \b T_B is the
0041  argument passed to the call operator,
0042  * and the \f$\mathbf{T}'\f$ is the return value.
0043  * The resulting transform has rotation
0044  * \f[
0045    \mathbf{R}' = \mathbf{R}_B
0046  * \f]
0047  * and translation
0048  * \f[
0049    \mathbf{t}' = \mathbf{t}_B + \mathbf{t}_A
0050  * \f]
0051  */
0052 class TransformTranslator
0053 {
0054   public:
0055     //@{
0056     //! \name Type aliases
0057     using Mat3 = SquareMatrixReal3;
0058     //@}
0059 
0060   public:
0061     //! Construct with the new reference frame of the translation
0062     explicit TransformTranslator(Translation const& tr) : tr_{tr} {}
0063 
0064     //// TRANSFORMATIONS ////
0065 
0066     //! Transform an identity
0067     Translation const& operator()(NoTransformation const&) const
0068     {
0069         return tr_;
0070     }
0071 
0072     inline Transformation operator()(Mat3 const&) const;
0073 
0074     inline Transformation operator()(Transformation const&) const;
0075 
0076     inline Translation operator()(Translation const&) const;
0077 
0078   private:
0079     Translation tr_;
0080 };
0081 
0082 //---------------------------------------------------------------------------//
0083 /*!
0084  * Apply a translation to a rotation matrix.
0085  */
0086 Transformation TransformTranslator::operator()(Mat3 const& rot) const
0087 {
0088     return Transformation{rot, tr_.translation()};
0089 }
0090 
0091 //---------------------------------------------------------------------------//
0092 /*!
0093  * Apply a translation to a transform.
0094  */
0095 Transformation TransformTranslator::operator()(Transformation const& tr) const
0096 {
0097     return Transformation{tr.rotation(), tr.translation() + tr_.translation()};
0098 }
0099 
0100 //---------------------------------------------------------------------------//
0101 /*!
0102  * Apply a translation to another translation.
0103  */
0104 Translation TransformTranslator::operator()(Translation const& tl) const
0105 {
0106     return Translation{tl.translation() + tr_.translation()};
0107 }
0108 
0109 //---------------------------------------------------------------------------//
0110 }  // namespace detail
0111 }  // namespace celeritas