moab
|
Define an affine transformation. More...
#include <AffineXform.hpp>
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 Matrix3 & | matrix () const |
const CartVect & | offset () 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 |
AffineXform::AffineXform | ( | ) | [inline] |
Definition at line 127 of file AffineXform.hpp.
AffineXform::AffineXform | ( | const double * | three_by_three, |
const double * | translation | ||
) | [inline] |
Definition at line 131 of file AffineXform.hpp.
AffineXform::AffineXform | ( | const Matrix3 & | mat, |
const CartVect & | off | ||
) | [inline] |
Definition at line 136 of file AffineXform.hpp.
void AffineXform::accumulate | ( | const AffineXform & | other | ) | [inline] |
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 36 of file AffineXform.cpp.
{ 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 233 of file AffineXform.hpp.
{ 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 86 of file AffineXform.hpp.
{ return mMatrix; }
const CartVect& moab::AffineXform::offset | ( | ) | const [inline] |
get translation portion of transform
Definition at line 88 of file AffineXform.hpp.
{ return mOffset; }
AffineXform AffineXform::reflection | ( | const double * | plane_normal | ) | [inline, static] |
reflect about plane through origin
Definition at line 162 of file AffineXform.hpp.
{ 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 239 of file AffineXform.hpp.
{ return mMatrix.determinant() < 0.0; }
AffineXform AffineXform::rotation | ( | double | radians, |
const double * | axis | ||
) | [inline, static] |
rotate about axis through origin
Definition at line 145 of file AffineXform.hpp.
{ 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 54 of file AffineXform.cpp.
{ 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 152 of file AffineXform.hpp.
{ 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 179 of file AffineXform.hpp.
{ return AffineXform( Matrix3( CartVect(f) ), CartVect( 0.0 ) ); }
AffineXform AffineXform::scale | ( | const double * | fractions | ) | [inline, static] |
scale about origin
Definition at line 174 of file AffineXform.hpp.
{ 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 184 of file AffineXform.hpp.
{ 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 190 of file AffineXform.hpp.
{ 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 244 of file AffineXform.hpp.
{ return fabs(fabs(mMatrix.determinant()) - 1) > std::numeric_limits<double>::epsilon(); }
AffineXform AffineXform::translation | ( | const double * | vector | ) | [inline, static] |
move
Definition at line 140 of file AffineXform.hpp.
{ 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 204 of file AffineXform.hpp.
{ 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 212 of file AffineXform.hpp.
{ 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 220 of file AffineXform.hpp.
void AffineXform::xform_vector | ( | double * | in_out | ) | const [inline] |
apply transform to a vector
Definition at line 227 of file AffineXform.hpp.
{ double input[] = { in_out[0], in_out[1], in_out[2] }; xform_vector( input, in_out ); }
Matrix3 moab::AffineXform::mMatrix [private] |
Definition at line 113 of file AffineXform.hpp.
CartVect moab::AffineXform::mOffset [private] |
Definition at line 114 of file AffineXform.hpp.