MOAB: Mesh Oriented datABase  (version 5.4.1)
moab::AffineXform Class Reference

Define an affine transformation. More...

#include <AffineXform.hpp>

+ Collaboration diagram for moab::AffineXform:

Public Member Functions

 AffineXform ()
 AffineXform (const double *three_by_three, const double *translation)
 AffineXform (const Matrix3 &mat, const CartVect &off)
void accumulate (const AffineXform &other)
void xform_point (const double *input, double *output) const
void xform_point (double *in_out) const
void xform_vector (const double *input, double *output) const
void xform_vector (double *in_out) const
AffineXform inverse () const
const Matrix3matrix () const
const CartVectoffset () const
bool reflection () const
bool scale () const

Static Public Member Functions

static AffineXform translation (const double *vector)
static AffineXform rotation (double radians, const double *axis)
static AffineXform rotation (const double *from_vec, const double *to_vec)
static AffineXform reflection (const double *plane_normal)
static AffineXform scale (double f)
static AffineXform scale (const double *fractions)
static AffineXform scale (double f, const double *point)
static AffineXform scale (const double *fractions, const double *point)
static ErrorCode get_tag (Tag &tag_handle_out, Interface *moab, const char *tagname=0)

Static Private Member Functions

static AffineXform rotation (double cos_angle, double sin_angle, const CartVect &unit_axis)

Private Attributes

Matrix3 mMatrix
CartVect mOffset

Detailed Description

Define an affine transformation.

Author:
Jason Kraftcheck ([email protected])
Date:
August, 2006

Definition at line 34 of file AffineXform.hpp.


Constructor & Destructor Documentation

Definition at line 126 of file AffineXform.hpp.

Referenced by inverse(), reflection(), rotation(), scale(), and translation().

: mMatrix( 1.0 ), mOffset( 0.0 ) {}
AffineXform::AffineXform ( const double *  three_by_three,
const double *  translation 
) [inline]

Definition at line 128 of file AffineXform.hpp.

    : mMatrix( three_by_three ), mOffset( trans )
{
}
AffineXform::AffineXform ( const Matrix3 mat,
const CartVect off 
) [inline]

Definition at line 133 of file AffineXform.hpp.

: mMatrix( mat ), mOffset( off ) {}

Member Function Documentation

void AffineXform::accumulate ( const AffineXform other) [inline]

incorporate the passed transform into this one such that the resulting transform is the cumulative affect of this initial transform followed by the passed transform

Definition at line 186 of file AffineXform.hpp.

References moab::CartVect::array(), mMatrix, mOffset, and xform_point().

Referenced by moab::SMF_State::mmult(), moab::operator*(), test_accumulate(), test_inversion(), and test_is_reflection().

{
    mMatrix = other.mMatrix * mMatrix;
    other.xform_point( mOffset.array() );
}
ErrorCode AffineXform::get_tag ( Tag tag_handle_out,
Interface moab,
const char *  tagname = 0 
) [static]

get a tag that can be used to store an instance of this class

Definition at line 38 of file AffineXform.cpp.

References moab::AFFINE_XFORM_TAG_NAME, MB_TAG_BYTES, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_DOUBLE, and moab::Interface::tag_get_handle().

{
    assert( sizeof( AffineXform ) == 12 * sizeof( double ) );

    if( !tagname ) tagname = AFFINE_XFORM_TAG_NAME;

    return interface->tag_get_handle( tagname, sizeof( AffineXform ), MB_TYPE_DOUBLE, tag_out,
                                      MB_TAG_BYTES | MB_TAG_CREAT | MB_TAG_DENSE );
}
AffineXform AffineXform::inverse ( ) const [inline]

get transform that is the inverse of this transform

Definition at line 221 of file AffineXform.hpp.

References AffineXform(), moab::Matrix3::inverse(), mMatrix, and mOffset.

Referenced by test_inversion(), and test_is_reflection().

{
    Matrix3 m = mMatrix.inverse();
    return AffineXform( m, m * -mOffset );
}
const Matrix3& moab::AffineXform::matrix ( ) const [inline]

get 3x3 matrix portion of transform

Definition at line 82 of file AffineXform.hpp.

References mMatrix.

Referenced by test_reflection(), and test_rotation().

    {
        return mMatrix;
    }
const CartVect& moab::AffineXform::offset ( ) const [inline]

get translation portion of transform

Definition at line 87 of file AffineXform.hpp.

References mOffset.

Referenced by scale().

    {
        return mOffset;
    }
AffineXform AffineXform::reflection ( const double *  plane_normal) [inline, static]

reflect about plane through origin

Definition at line 153 of file AffineXform.hpp.

References AffineXform().

Referenced by test_is_reflection().

{
    double i = plane_normal[0];
    double j = plane_normal[1];
    double k = plane_normal[2];
    Matrix3 m( j * j + k * k - i * i, -2.0 * i * j, -2.0 * i * k, -2.0 * i * j, i * i + k * k - j * j, -2.0 * j * k,
               -2.0 * i * k, -2.0 * j * k, i * i + j * j - k * k );
    m *= 1.0 / ( i * i + j * j + k * k );  // normalize
    return AffineXform( m, CartVect( 0.0 ) );
}
bool AffineXform::reflection ( ) const [inline]

Is this transform a reflection

A relfecting transform will require the reversal of the order of edges in a loop, etc. because it produces a mirror-image of the input geometry. This method tests if this is such a transform. A reflection may be created with by an explicit transform, scaling with a negative scale factor, etc. If multiple transforms are combined such that the transform is no longer a reflection (e.g. two reflections that are effectively a rotation), this method will return false.

Definition at line 227 of file AffineXform.hpp.

References moab::Matrix3::determinant(), and mMatrix.

Referenced by test_accumulate(), test_inversion(), test_is_reflection(), and test_reflection().

{
    return mMatrix.determinant() < 0.0;
}
AffineXform AffineXform::rotation ( double  radians,
const double *  axis 
) [inline, static]

rotate about axis through origin

Definition at line 140 of file AffineXform.hpp.

References moab::CartVect::normalize().

Referenced by moab::ReadABAQUS::create_instance_of_part(), moab::ReadSmf::rot(), rotation(), test_accumulate(), test_inversion(), test_is_reflection(), test_rotation(), and test_rotation_from_vec().

{
    CartVect a( axis );
    a.normalize();
    return AffineXform::rotation( std::cos( angle ), std::sin( angle ), a );
}
AffineXform AffineXform::rotation ( const double *  from_vec,
const double *  to_vec 
) [static]

define rotation such that if applied to from_vec the result aligned with to_vec

Definition at line 48 of file AffineXform.cpp.

References AffineXform(), length(), moab::CartVect::length(), moab::CartVect::normalize(), and rotation().

{
    CartVect from( from_vec );
    CartVect to( to_vec );
    CartVect a = from * to;
    double len = a.length();

    // If input vectors are not parallel (the normal case)
    if( len >= std::numeric_limits< double >::epsilon() )
    {
        from.normalize();
        to.normalize();
        return rotation( from % to, ( from * to ).length(), a / len );
    }

    // Vectors are parallel:
    //
    // If vectors are in same direction then rotation is identity (no transform)
    if( from % to >= 0.0 ) return AffineXform();

    // Parallel vectors in opposite directions:
    //
    // NOTE:  This case is ill-defined.  There are infinitely
    // many rotations that can align the two vectors.  The angle
    // of rotation is 180 degrees, but the axis of rotation may
    // be any unit vector orthogonal to the input vectors.
    //
    from.normalize();
    double lenxy = std::sqrt( from[0] * from[0] + from[1] * from[1] );
    CartVect axis( -from[0] * from[2] / lenxy, -from[1] * from[2] / lenxy, lenxy );
    return rotation( -1, 0, axis );
}
AffineXform AffineXform::rotation ( double  cos_angle,
double  sin_angle,
const CartVect unit_axis 
) [inline, static, private]

Definition at line 147 of file AffineXform.hpp.

References AffineXform(), and moab::outer_product().

{
    const Matrix3 m1( c, -a[2] * s, a[1] * s, a[2] * s, c, -a[0] * s, -a[1] * s, a[0] * s, c );
    return AffineXform( m1 + ( 1.0 - c ) * outer_product( a, a ), CartVect( 0.0 ) );
}
AffineXform AffineXform::scale ( double  f) [inline, static]

scale about origin

Definition at line 169 of file AffineXform.hpp.

References AffineXform().

Referenced by test_scale().

{
    return AffineXform( Matrix3( CartVect( f ) ), CartVect( 0.0 ) );
}
AffineXform AffineXform::scale ( const double *  fractions) [inline, static]

scale about origin

Definition at line 164 of file AffineXform.hpp.

References AffineXform().

{
    return AffineXform( Matrix3( CartVect( f ) ), CartVect( 0.0 ) );
}
AffineXform AffineXform::scale ( double  f,
const double *  point 
) [inline, static]

scale about a point

Definition at line 174 of file AffineXform.hpp.

References scale().

{
    double fs[] = { f, f, f };
    return AffineXform::scale( fs, point );
}
AffineXform AffineXform::scale ( const double *  fractions,
const double *  point 
) [inline, static]

scale about a point

Definition at line 180 of file AffineXform.hpp.

References AffineXform(), and offset().

{
    double offset[] = { p[0] * ( 1 - f[0] ), p[1] * ( 1 - f[1] ), p[2] * ( 1 - f[2] ) };
    return AffineXform( Matrix3( CartVect( f ) ), CartVect( offset ) );
}
bool AffineXform::scale ( ) const [inline]

Does this transform do any scaling

Definition at line 232 of file AffineXform.hpp.

References moab::Matrix3::determinant(), and mMatrix.

Referenced by scale(), test_accumulate(), test_inversion(), test_is_reflection(), test_scale(), and test_scale_point().

{
    return fabs( fabs( mMatrix.determinant() ) - 1 ) > std::numeric_limits< double >::epsilon();
}
AffineXform AffineXform::translation ( const double *  vector) [inline, static]

move

Definition at line 135 of file AffineXform.hpp.

References AffineXform().

Referenced by test_accumulate(), test_inversion(), test_is_reflection(), test_translation(), and moab::ReadSmf::trans().

{
    return AffineXform( Matrix3( 1.0 ), CartVect( vector ) );
}
void AffineXform::xform_point ( const double *  input,
double *  output 
) const [inline]

apply transform to a point

Definition at line 192 of file AffineXform.hpp.

References mOffset, and xform_vector().

Referenced by accumulate(), test_accumulate(), test_inversion(), test_none(), test_reflection(), test_rotation(), test_scale_point(), test_translation(), and moab::SMF_State::vertex().

{
    xform_vector( input, output );
    output[0] += mOffset[0];
    output[1] += mOffset[1];
    output[2] += mOffset[2];
}
void AffineXform::xform_point ( double *  in_out) const [inline]

apply transform to a point

Definition at line 200 of file AffineXform.hpp.

References mOffset, and xform_vector().

{
    xform_vector( in_out );
    in_out[0] += mOffset[0];
    in_out[1] += mOffset[1];
    in_out[2] += mOffset[2];
}
void AffineXform::xform_vector ( const double *  input,
double *  output 
) const [inline]

apply transform to a vector

Definition at line 208 of file AffineXform.hpp.

References mMatrix.

Referenced by moab::ReadABAQUS::create_instance_of_part(), moab::SMF_State::normal(), test_accumulate(), test_inversion(), test_none(), test_reflection(), test_rotation(), test_rotation_from_vec(), test_translation(), xform_point(), and xform_vector().

{
    output[0] = input[0] * mMatrix[0][0] + input[1] * mMatrix[0][1] + input[2] * mMatrix[0][2];
    output[1] = input[0] * mMatrix[1][0] + input[1] * mMatrix[1][1] + input[2] * mMatrix[1][2];
    output[2] = input[0] * mMatrix[2][0] + input[1] * mMatrix[2][1] + input[2] * mMatrix[2][2];
}
void AffineXform::xform_vector ( double *  in_out) const [inline]

apply transform to a vector

Definition at line 215 of file AffineXform.hpp.

References xform_vector().

{
    double input[] = { in_out[0], in_out[1], in_out[2] };
    xform_vector( input, in_out );
}

Member Data Documentation

Definition at line 113 of file AffineXform.hpp.

Referenced by accumulate(), inverse(), offset(), and xform_point().

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines