Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
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 (kraft.nosp@m.che@.nosp@m.cae.w.nosp@m.isc..nosp@m.edu)
Date
August, 2006

Definition at line 34 of file AffineXform.hpp.

Constructor & Destructor Documentation

◆ AffineXform() [1/3]

AffineXform::AffineXform ( )
inline

Definition at line 126 of file AffineXform.hpp.

126 : mMatrix( 1.0 ), mOffset( 0.0 ) {}

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

◆ AffineXform() [2/3]

AffineXform::AffineXform ( const double *  three_by_three,
const double *  translation 
)
inline

Definition at line 128 of file AffineXform.hpp.

129  : mMatrix( three_by_three ), mOffset( trans )
130 {
131 }

◆ AffineXform() [3/3]

AffineXform::AffineXform ( const Matrix3 mat,
const CartVect off 
)
inline

Definition at line 133 of file AffineXform.hpp.

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

Member Function Documentation

◆ accumulate()

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.

187 {
188  mMatrix = other.mMatrix * mMatrix;
189  other.xform_point( mOffset.array() );
190 }

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

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

◆ get_tag()

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.

39 {
40  assert( sizeof( AffineXform ) == 12 * sizeof( double ) );
41 
42  if( !tagname ) tagname = AFFINE_XFORM_TAG_NAME;
43 
44  return interface->tag_get_handle( tagname, sizeof( AffineXform ), MB_TYPE_DOUBLE, tag_out,
46 }

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

◆ inverse()

AffineXform AffineXform::inverse ( ) const
inline

get transform that is the inverse of this transform

Definition at line 221 of file AffineXform.hpp.

222 {
223  Matrix3 m = mMatrix.inverse();
224  return AffineXform( m, m * -mOffset );
225 }

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

◆ matrix()

const Matrix3& moab::AffineXform::matrix ( ) const
inline

get 3x3 matrix portion of transform

Definition at line 82 of file AffineXform.hpp.

83  {
84  return mMatrix;
85  }

References mMatrix.

◆ offset()

const CartVect& moab::AffineXform::offset ( ) const
inline

get translation portion of transform

Definition at line 87 of file AffineXform.hpp.

88  {
89  return mOffset;
90  }

References mOffset.

Referenced by scale().

◆ reflection() [1/2]

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.

228 {
229  return mMatrix.determinant() < 0.0;
230 }

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

◆ reflection() [2/2]

AffineXform AffineXform::reflection ( const double *  plane_normal)
inlinestatic

reflect about plane through origin

Definition at line 153 of file AffineXform.hpp.

154 {
155  double i = plane_normal[0];
156  double j = plane_normal[1];
157  double k = plane_normal[2];
158  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,
159  -2.0 * i * k, -2.0 * j * k, i * i + j * j - k * k );
160  m *= 1.0 / ( i * i + j * j + k * k ); // normalize
161  return AffineXform( m, CartVect( 0.0 ) );
162 }

References AffineXform().

◆ rotation() [1/3]

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.

49 {
50  CartVect from( from_vec );
51  CartVect to( to_vec );
52  CartVect a = from * to;
53  double len = a.length();
54 
55  // If input vectors are not parallel (the normal case)
56  if( len >= std::numeric_limits< double >::epsilon() )
57  {
58  from.normalize();
59  to.normalize();
60  return rotation( from % to, ( from * to ).length(), a / len );
61  }
62 
63  // Vectors are parallel:
64  //
65  // If vectors are in same direction then rotation is identity (no transform)
66  if( from % to >= 0.0 ) return AffineXform();
67 
68  // Parallel vectors in opposite directions:
69  //
70  // NOTE: This case is ill-defined. There are infinitely
71  // many rotations that can align the two vectors. The angle
72  // of rotation is 180 degrees, but the axis of rotation may
73  // be any unit vector orthogonal to the input vectors.
74  //
75  from.normalize();
76  double lenxy = std::sqrt( from[0] * from[0] + from[1] * from[1] );
77  CartVect axis( -from[0] * from[2] / lenxy, -from[1] * from[2] / lenxy, lenxy );
78  return rotation( -1, 0, axis );
79 }

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

◆ rotation() [2/3]

AffineXform AffineXform::rotation ( double  cos_angle,
double  sin_angle,
const CartVect unit_axis 
)
inlinestaticprivate

Definition at line 147 of file AffineXform.hpp.

148 {
149  const Matrix3 m1( c, -a[2] * s, a[1] * s, a[2] * s, c, -a[0] * s, -a[1] * s, a[0] * s, c );
150  return AffineXform( m1 + ( 1.0 - c ) * outer_product( a, a ), CartVect( 0.0 ) );
151 }

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

◆ rotation() [3/3]

AffineXform AffineXform::rotation ( double  radians,
const double *  axis 
)
inlinestatic

rotate about axis through origin

Definition at line 140 of file AffineXform.hpp.

141 {
142  CartVect a( axis );
143  a.normalize();
144  return AffineXform::rotation( std::cos( angle ), std::sin( angle ), a );
145 }

References moab::angle(), and moab::CartVect::normalize().

Referenced by moab::ReadABAQUS::create_instance_of_part(), moab::ReadSmf::rot(), and rotation().

◆ scale() [1/5]

bool AffineXform::scale ( ) const
inline

Does this transform do any scaling

Definition at line 232 of file AffineXform.hpp.

233 {
234  return fabs( fabs( mMatrix.determinant() ) - 1 ) > std::numeric_limits< double >::epsilon();
235 }

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

Referenced by scale(), and moab::ReadSmf::scale().

◆ scale() [2/5]

AffineXform AffineXform::scale ( const double *  fractions)
inlinestatic

scale about origin

Definition at line 164 of file AffineXform.hpp.

165 {
166  return AffineXform( Matrix3( CartVect( f ) ), CartVect( 0.0 ) );
167 }

References AffineXform().

◆ scale() [3/5]

AffineXform AffineXform::scale ( const double *  fractions,
const double *  point 
)
inlinestatic

scale about a point

Definition at line 180 of file AffineXform.hpp.

181 {
182  double offset[] = { p[0] * ( 1 - f[0] ), p[1] * ( 1 - f[1] ), p[2] * ( 1 - f[2] ) };
183  return AffineXform( Matrix3( CartVect( f ) ), CartVect( offset ) );
184 }

References AffineXform(), and offset().

◆ scale() [4/5]

AffineXform AffineXform::scale ( double  f)
inlinestatic

scale about origin

Definition at line 169 of file AffineXform.hpp.

170 {
171  return AffineXform( Matrix3( CartVect( f ) ), CartVect( 0.0 ) );
172 }

References AffineXform().

◆ scale() [5/5]

AffineXform AffineXform::scale ( double  f,
const double *  point 
)
inlinestatic

scale about a point

Definition at line 174 of file AffineXform.hpp.

175 {
176  double fs[] = { f, f, f };
177  return AffineXform::scale( fs, point );
178 }

References scale().

◆ translation()

AffineXform AffineXform::translation ( const double *  vector)
inlinestatic

move

Definition at line 135 of file AffineXform.hpp.

136 {
137  return AffineXform( Matrix3( 1.0 ), CartVect( vector ) );
138 }

References AffineXform().

Referenced by moab::ReadSmf::trans().

◆ xform_point() [1/2]

void AffineXform::xform_point ( const double *  input,
double *  output 
) const
inline

apply transform to a point

Definition at line 192 of file AffineXform.hpp.

193 {
194  xform_vector( input, output );
195  output[0] += mOffset[0];
196  output[1] += mOffset[1];
197  output[2] += mOffset[2];
198 }

References mOffset, output, and xform_vector().

Referenced by accumulate(), and moab::SMF_State::vertex().

◆ xform_point() [2/2]

void AffineXform::xform_point ( double *  in_out) const
inline

apply transform to a point

Definition at line 200 of file AffineXform.hpp.

201 {
202  xform_vector( in_out );
203  in_out[0] += mOffset[0];
204  in_out[1] += mOffset[1];
205  in_out[2] += mOffset[2];
206 }

References mOffset, and xform_vector().

◆ xform_vector() [1/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.

209 {
210  output[0] = input[0] * mMatrix[0][0] + input[1] * mMatrix[0][1] + input[2] * mMatrix[0][2];
211  output[1] = input[0] * mMatrix[1][0] + input[1] * mMatrix[1][1] + input[2] * mMatrix[1][2];
212  output[2] = input[0] * mMatrix[2][0] + input[1] * mMatrix[2][1] + input[2] * mMatrix[2][2];
213 }

References mMatrix, and output.

Referenced by moab::ReadABAQUS::create_instance_of_part(), moab::SMF_State::normal(), xform_point(), and xform_vector().

◆ xform_vector() [2/2]

void AffineXform::xform_vector ( double *  in_out) const
inline

apply transform to a vector

Definition at line 215 of file AffineXform.hpp.

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

References xform_vector().

Member Data Documentation

◆ mMatrix

Matrix3 moab::AffineXform::mMatrix
private

Definition at line 112 of file AffineXform.hpp.

Referenced by accumulate(), inverse(), matrix(), reflection(), scale(), and xform_vector().

◆ mOffset

CartVect moab::AffineXform::mOffset
private

Definition at line 113 of file AffineXform.hpp.

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


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