MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::PlanarDomain Class Reference

#include <PlanarDomain.hpp>

+ Inheritance diagram for MBMesquite::PlanarDomain:
+ Collaboration diagram for MBMesquite::PlanarDomain:

Public Types

enum  Plane { XY = 2, XZ = 1, YZ = 0 }

Public Member Functions

 PlanarDomain (Plane orient, double offset=0.0)
 PlanarDomain ()
 PlanarDomain (const Vector3D &normal, const Vector3D &point)
virtual ~PlanarDomain ()
void fit_vertices (Mesh *mesh, MsqError &err, double epsilon=0.0)
void fit_vertices (Mesh *mesh, const Mesh::VertexHandle *vertex_array, size_t vertex_array_length, MsqError &err, double epsilon=0.0)
void set_plane (const Vector3D &normal, const Vector3D &point)
void flip ()
const Vector3Dget_normal () const
double get_coeff ()
Vector3D get_origin () const
virtual void snap_to (Mesh::VertexHandle entity_handle, Vector3D &coordinate) const
virtual void vertex_normal_at (Mesh::VertexHandle entity_handle, Vector3D &coordinate) const
virtual void element_normal_at (Mesh::ElementHandle entity_handle, Vector3D &coordinate) const
virtual void vertex_normal_at (const Mesh::VertexHandle *handle, Vector3D coords[], unsigned count, MsqError &err) const
 evaluate surface normals
virtual void closest_point (Mesh::VertexHandle handle, const Vector3D &position, Vector3D &closest, Vector3D &normal, MsqError &err) const
 evaluate closest point and normal
virtual void domain_DoF (const Mesh::VertexHandle *handle_array, unsigned short *dof_array, size_t num_vertices, MsqError &err) const

Private Attributes

Vector3D mNormal
double mCoeff

Detailed Description

This is a template for a planar domain. It will provide the normal information necessary for surface mesh optimization.

Definition at line 49 of file PlanarDomain.hpp.


Member Enumeration Documentation

Enumerator:
XY 
XZ 
YZ 

Definition at line 52 of file PlanarDomain.hpp.

    {
        XY = 2,
        XZ = 1,
        YZ = 0
    };

Constructor & Destructor Documentation

MBMesquite::PlanarDomain::PlanarDomain ( Plane  orient,
double  offset = 0.0 
) [inline]

Definition at line 59 of file PlanarDomain.hpp.

    {
        Vector3D normal( 0, 0, 0 ), point( 0, 0, 0 );
        normal[orient] = 1.0;
        point[orient]  = offset;
        set_plane( normal, point );
    }

Definition at line 67 of file PlanarDomain.hpp.

{}
MBMesquite::PlanarDomain::PlanarDomain ( const Vector3D normal,
const Vector3D point 
) [inline]

Definition at line 69 of file PlanarDomain.hpp.

    {
        set_plane( normal, point );
    }

Definition at line 35 of file PlanarDomain.cpp.

{}

Member Function Documentation

void MBMesquite::PlanarDomain::closest_point ( Mesh::VertexHandle  handle,
const Vector3D position,
Vector3D closest,
Vector3D normal,
MsqError err 
) const [virtual]

evaluate closest point and normal

Given a position in space, return the closest position in the domain and the domain normal at that point.

Parameters:
entity_handleEvaluate the subset of the domain contianing this entity
positionInput position for which to evaluate
closestClosest position in the domain.
normalDomain normal at the location of 'closest'

Implements MBMesquite::MeshDomain.

Definition at line 70 of file PlanarDomain.cpp.

{
    normal  = mNormal;
    closest = position - mNormal * ( mNormal % position + mCoeff );
}
void MBMesquite::PlanarDomain::domain_DoF ( const Mesh::VertexHandle handle_array,
unsigned short *  dof_array,
size_t  num_vertices,
MsqError err 
) const [virtual]

Definition at line 80 of file PlanarDomain.cpp.

{
    std::fill( dof_array, dof_array + num_vertices, 2 );
}
void MBMesquite::PlanarDomain::element_normal_at ( Mesh::ElementHandle  entity_handle,
MBMesquite::Vector3D coordinate 
) const [virtual]

Implements MBMesquite::MeshDomain.

Definition at line 55 of file PlanarDomain.cpp.

{
    coordinate = mNormal;
}
void MBMesquite::PlanarDomain::fit_vertices ( Mesh mesh,
MsqError err,
double  epsilon = 0.0 
)

Definition at line 94 of file PlanarDomain.cpp.

References MBMesquite::arrptr(), MBMesquite::MsqError::clear(), MBMesquite::Mesh::elements_get_attached_vertices(), MBMesquite::Mesh::elements_get_topologies(), epsilon, fixed, MBMesquite::Mesh::get_all_elements(), MBMesquite::Mesh::get_all_vertices(), MBMesquite::DomainUtil::get_fixed_vertices(), MSQ_ERRRTN, n, and MBMesquite::Mesh::vertices_get_coordinates().

Referenced by main(), and PlanarGeometryTest::test_fit_plane().

{
    // Our goal here is to consider only the boundary (fixed) vertices
    // when calculating the plane.  If for some reason the user wants
    // to snap a not-quite-planar mesh to a plane during optimization,
    // if possible we want to start with the plane containing the fixed
    // vertices, as those won't get snapped.  If no vertices are fixed,
    // then treat them all as fixed for the purpose calculating the plane
    // (consider them all.)

    std::vector< Mesh::VertexHandle > verts, fixed;
    mesh->get_all_vertices( verts, err );MSQ_ERRRTN( err );
    DomainUtil::get_fixed_vertices( mesh, arrptr( verts ), verts.size(), fixed, err );MSQ_ERRRTN( err );

    bool do_all_verts = true;
    if( fixed.size() > 2 )
    {
        do_all_verts = false;
        fit_vertices( mesh, arrptr( fixed ), fixed.size(), err, epsilon );

        // if we failed with only the fixed vertices, try again with all of the
        // vertices
        if( err )
        {
            err.clear();
            do_all_verts = true;
        }
    }

    if( do_all_verts )
    {
        fit_vertices( mesh, arrptr( verts ), verts.size(), err, epsilon );MSQ_ERRRTN( err );
    }

    // now count inverted elements
    size_t inverted_count = 0, total_count = 0;
    std::vector< Mesh::ElementHandle > elems;
    std::vector< size_t > junk;
    std::vector< MsqVertex > coords;
    mesh->get_all_elements( elems, err );MSQ_ERRRTN( err );
    for( size_t i = 0; i < elems.size(); ++i )
    {

        EntityTopology type;
        mesh->elements_get_topologies( &elems[i], &type, 1, err );
        if( TopologyInfo::dimension( type ) != 2 ) continue;

        verts.clear();
        mesh->elements_get_attached_vertices( arrptr( elems ), 1, verts, junk, err );MSQ_ERRRTN( err );
        if( verts.size() < 3 ) continue;

        coords.resize( verts.size() );
        mesh->vertices_get_coordinates( arrptr( verts ), arrptr( coords ), 3, err );MSQ_ERRRTN( err );
        Vector3D n = ( coords[1] - coords[0] ) * ( coords[2] - coords[0] );
        ++total_count;
        if( n % mNormal < 0.0 ) ++inverted_count;
    }

    // if most elements are inverted, flip normal
    if( 2 * inverted_count > total_count ) this->flip();
}
void MBMesquite::PlanarDomain::fit_vertices ( MBMesquite::Mesh mesh,
const Mesh::VertexHandle vertex_array,
size_t  vertex_array_length,
MBMesquite::MsqError err,
double  epsilon = 0.0 
)

Definition at line 156 of file PlanarDomain.cpp.

References MBMesquite::arrptr(), MBMesquite::DomainUtil::default_tolerance(), MBMesquite::MsqError::INVALID_MESH, MSQ_ERRRTN, MSQ_SETERR, MBMesquite::DomainUtil::non_colinear_vertices(), and MBMesquite::Mesh::vertices_get_coordinates().

{
    std::vector< MsqVertex > coords( num_verts );
    mesh->vertices_get_coordinates( verts, arrptr( coords ), num_verts, err );MSQ_ERRRTN( err );

    if( epsilon <= 0.0 ) epsilon = DomainUtil::default_tolerance( arrptr( coords ), num_verts );

    Vector3D pts[3];
    if( !DomainUtil::non_colinear_vertices( arrptr( coords ), num_verts, pts, epsilon ) )
    {
        MSQ_SETERR( err )( "All vertices are colinear", MsqError::INVALID_MESH );
        return;
    }

    this->set_plane( ( pts[1] - pts[0] ) * ( pts[2] - pts[0] ), pts[0] );
}

Definition at line 88 of file PlanarDomain.cpp.

Definition at line 93 of file PlanarDomain.hpp.

Referenced by PlanarGeometryTest::test_fit_plane().

    {
        return mCoeff;
    }

Definition at line 98 of file PlanarDomain.hpp.

Referenced by PatchTranslate::xform(), PatchScale::xform(), and PatchRotate::xform().

    {
        return -mCoeff * mNormal;
    }
void MBMesquite::PlanarDomain::set_plane ( const Vector3D normal,
const Vector3D point 
)

Definition at line 37 of file PlanarDomain.cpp.

References MBMesquite::Vector3D::normalize().

Referenced by PatchTranslate::xform(), PatchScale::xform(), and PatchRotate::xform().

{
    mNormal = normal;
    mNormal.normalize();
    mCoeff = -( mNormal % point );
}
void MBMesquite::PlanarDomain::snap_to ( Mesh::VertexHandle  entity_handle,
Vector3D coordinate 
) const [virtual]

Modifies "coordinate" so that it lies on the domain to which "entity_handle" is constrained. The handle determines the domain. The coordinate is the proposed new position on that domain.

Implements MBMesquite::MeshDomain.

Definition at line 44 of file PlanarDomain.cpp.

{
    coordinate -= mNormal * ( mNormal % coordinate + mCoeff );
}
void MBMesquite::PlanarDomain::vertex_normal_at ( Mesh::VertexHandle  entity_handle,
Vector3D coordinate 
) const [virtual]

Returns the normal of the domain to which "entity_handle" is constrained. For non-planar surfaces, the normal is calculated at the point on the domain that is closest to the passed in value of "coordinate". If the domain does not have a normal, or the normal cannot be determined, "coordinate" is set to (0,0,0). Otherwise, "coordinate" is set to the domain's normal at the appropriate point. In summary, the handle determines the domain. The coordinate determines the point of interest on that domain.

User should see also PatchData::get_domain_normal_at_vertex and PatchData::get_domain_normal_at_element .

Implements MBMesquite::MeshDomain.

Definition at line 49 of file PlanarDomain.cpp.

Referenced by MBMesquite::MeshWriter::Projection::Projection().

{
    coordinate = mNormal;
}
void MBMesquite::PlanarDomain::vertex_normal_at ( const Mesh::VertexHandle handles,
Vector3D  coordinates[],
unsigned  count,
MsqError err 
) const [virtual]

evaluate surface normals

Returns normals for a domain.

Parameters:
handlesThe domain evaluated is the one in which this mesh entity is constrained.
coordinatesAs input, a list of positions at which to evaluate the domain. As output, the resulting domain normals.
countThe length of the coordinates array.

Implements MBMesquite::MeshDomain.

Definition at line 61 of file PlanarDomain.cpp.

{
    for( unsigned i = 0; i < count; ++i )
        coords[i] = mNormal;
}

Member Data Documentation

Definition at line 127 of file PlanarDomain.hpp.

Definition at line 126 of file PlanarDomain.hpp.

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