MOAB: Mesh Oriented datABase  (version 5.2.1)
MBMesquite::MeshTransform Class Reference

#include <MeshTransform.hpp>

+ Inheritance diagram for MBMesquite::MeshTransform:
+ Collaboration diagram for MBMesquite::MeshTransform:

Public Member Functions

 MeshTransform (bool skip_fixed=false)
 MeshTransform (Matrix3D &in_mat, Vector3D &in_vec, bool skip_fixed=false)
virtual ~MeshTransform ()
virtual double loop_over_mesh (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err)
 Loop over the mesh and perform the affine transformation.
virtual std::string get_name () const
 Return the name of this PatchDataUser: Mesh Transform.
virtual void initialize_queue (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err)
void add_translation (const Vector3D &offset)
void add_rotation (const Vector3D &axis, double radians)
void add_scale (double factor)
void add_scale (const Vector3D &factors)
bool skipping_fixed_vertices () const
void skip_fixed_vertices (bool yesno)

Private Attributes

Matrix3D mMat
Vector3D mVec
 Matrix for the affine transformation.
bool skipFixed
 Vector for the affine transformation.

Detailed Description

Perform an Affine transformation on Mesh vertex positions. Essentially define the new vertex position, v_new, from the original vertex position, v_old, s.t. v_new = (mMat * v_old) + mVec, where mMat is a constant matrix and mVec is a constant vector.

Definition at line 55 of file MeshTransform.hpp.


Constructor & Destructor Documentation

MBMesquite::MeshTransform::MeshTransform ( bool  skip_fixed = false) [inline]

Definition at line 58 of file MeshTransform.hpp.

                                             : mMat( 1, 0, 0, 0, 1, 0, 0, 0, 1 ), mVec( 0.0 ), skipFixed( skip_fixed )
    {
    }
MBMesquite::MeshTransform::MeshTransform ( Matrix3D in_mat,
Vector3D in_vec,
bool  skip_fixed = false 
) [inline]

Definition at line 61 of file MeshTransform.hpp.

        : mMat( in_mat ), mVec( in_vec ), skipFixed( skip_fixed )
    {
    }

Definition at line 45 of file MeshTransform.cpp.

{}

Member Function Documentation

void MBMesquite::MeshTransform::add_rotation ( const Vector3D axis,
double  radians 
)

Definition at line 87 of file MeshTransform.cpp.

References MBMesquite::Vector3D::length(), mMat, mVec, and MBMesquite::Matrix3D::outer_product().

{
    const double c   = cos( radians );
    const double s   = sin( radians );
    const Vector3D a = axis / axis.length();
    const Matrix3D m1( c, -a[2] * s, a[1] * s, a[2] * s, c, -a[0] * s, -a[1] * s, a[0] * s, c );
    Matrix3D m2;
    m2.outer_product( a, a );
    Matrix3D rot = m1 + ( 1.0 - c ) * m2;
    mMat         = rot * mMat;
    mVec         = rot * mVec;
}
void MBMesquite::MeshTransform::add_scale ( double  factor)

Definition at line 100 of file MeshTransform.cpp.

{
    add_scale( Vector3D( factor ) );
}

Definition at line 105 of file MeshTransform.cpp.

References mMat, and mVec.

{
    for( int i = 0; i < 3; ++i )
    {
        mVec[i] *= f[i];
        mMat[i][0] *= f[i];
        mMat[i][1] *= f[i];
        mMat[i][2] *= f[i];
    }
}

Definition at line 82 of file MeshTransform.cpp.

References mVec.

{
    mVec += offset;
}
virtual std::string MBMesquite::MeshTransform::get_name ( ) const [inline, virtual]

Return the name of this PatchDataUser: Mesh Transform.

Implements MBMesquite::Instruction.

Definition at line 73 of file MeshTransform.hpp.

    {
        return "Mesh Transform";
    }
void MBMesquite::MeshTransform::initialize_queue ( MeshDomainAssoc mesh_and_domain,
const Settings settings,
MsqError err 
) [virtual]

Called for all instructions in queue before loop_over_mesh is called for any insetruction in queue. Default behavior is to do nothing.

Implements MBMesquite::Instruction.

Definition at line 116 of file MeshTransform.cpp.

{}
double MBMesquite::MeshTransform::loop_over_mesh ( MeshDomainAssoc mesh_and_domain,
const Settings settings,
MsqError err 
) [virtual]

Loop over the mesh and perform the affine transformation.

Actually apply the affine transformation

Implements MBMesquite::Instruction.

Definition at line 50 of file MeshTransform.cpp.

References fixed, MBMesquite::Mesh::get_all_vertices(), MBMesquite::MeshDomainAssoc::get_mesh(), mesh, mMat, MSQ_CHKERR, mVec, skipFixed, MBMesquite::Mesh::vertex_set_coordinates(), MBMesquite::Mesh::vertices_get_coordinates(), and MBMesquite::Mesh::vertices_get_fixed_flag().

Referenced by main().

{
    Mesh* mesh = mesh_and_domain->get_mesh();

    std::vector< Mesh::VertexHandle > handle_list;
    mesh->get_all_vertices( handle_list, err );
    if( MSQ_CHKERR( err ) ) return 1.0;

    std::vector< bool > fixed( 1 );
    MsqVertex vertex;
    std::vector< Mesh::VertexHandle >::const_iterator iter;
    for( iter = handle_list.begin(); iter != handle_list.end(); ++iter )
    {
        mesh->vertices_get_coordinates( &*iter, &vertex, 1, err );
        if( MSQ_CHKERR( err ) ) return 1.0;

        if( skipFixed )
        {
            mesh->vertices_get_fixed_flag( &*iter, fixed, 1, err );
            if( MSQ_CHKERR( err ) ) return 1.0;
            if( fixed.front() ) continue;
        }

        vertex = mMat * vertex + mVec;

        mesh->vertex_set_coordinates( *iter, vertex, err );
        if( MSQ_CHKERR( err ) ) return 1.0;
    }

    return 0.0;
}
void MBMesquite::MeshTransform::skip_fixed_vertices ( bool  yesno) [inline]

Definition at line 89 of file MeshTransform.hpp.

Referenced by main().

    {
        skipFixed = yesno;
    }

Definition at line 85 of file MeshTransform.hpp.

    {
        return skipFixed;
    }

Member Data Documentation

Definition at line 95 of file MeshTransform.hpp.

Referenced by add_rotation(), add_scale(), and loop_over_mesh().

Matrix for the affine transformation.

Definition at line 96 of file MeshTransform.hpp.

Referenced by add_rotation(), add_scale(), add_translation(), and loop_over_mesh().

Vector for the affine transformation.

Definition at line 97 of file MeshTransform.hpp.

Referenced by loop_over_mesh().

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