Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
quads_to_tris.hpp File Reference
#include <iostream>
#include <cassert>
#include "moab/Core.hpp"
#include "MBTagConventions.hpp"
#include "moab/Range.hpp"
+ Include dependency graph for quads_to_tris.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

moab::ErrorCode make_tris_from_quad (moab::Interface *MBI, moab::EntityHandle quad, moab::EntityHandle &tri0, moab::EntityHandle &tri1)
moab::ErrorCode make_tris_from_quads (moab::Interface *MBI, const moab::Range &quads, moab::Range &tris)
moab::ErrorCode quads_to_tris (moab::Interface *MBI, moab::EntityHandle input_meshset)

Function Documentation

Definition at line 21 of file quads_to_tris.cpp.

References moab::Interface::create_element(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::CartVect::length_squared(), MB_SUCCESS, and MBTRI.

Referenced by make_tris_from_quads(), and quads_to_tris().

{

    // get connectivity (ordered counterclockwise for 2D elements in MOAB)
    ErrorCode result;
    const EntityHandle* quad_conn;
    int n_verts = 0;
    result      = MBI->get_connectivity( quad, quad_conn, n_verts );
    assert( 4 == n_verts );
    assert( MB_SUCCESS == result );

    // find length of diagonals
    std::vector< CartVect > coords( n_verts );
    result = MBI->get_coords( quad_conn, n_verts, coords[0].array() );
    if( MB_SUCCESS != result ) return result;
    CartVect diagA  = coords[0] - coords[2];
    double lenA_sqr = diagA.length_squared();
    CartVect diagB  = coords[1] - coords[3];
    double lenB_sqr = diagB.length_squared();

    // choose the shortest diagonal
    EntityHandle tri0_conn[3], tri1_conn[3];
    if( lenA_sqr < lenB_sqr )
    {
        tri0_conn[0] = quad_conn[0];
        tri0_conn[1] = quad_conn[1];
        tri0_conn[2] = quad_conn[2];
        tri1_conn[0] = quad_conn[0];
        tri1_conn[1] = quad_conn[2];
        tri1_conn[2] = quad_conn[3];
    }
    else
    {
        tri0_conn[0] = quad_conn[0];
        tri0_conn[1] = quad_conn[1];
        tri0_conn[2] = quad_conn[3];
        tri1_conn[0] = quad_conn[1];
        tri1_conn[1] = quad_conn[2];
        tri1_conn[2] = quad_conn[3];
    }

    // make tris from quad
    result = MBI->create_element( MBTRI, tri0_conn, 3, tri0 );
    assert( MB_SUCCESS == result );
    result = MBI->create_element( MBTRI, tri1_conn, 3, tri1 );
    assert( MB_SUCCESS == result );

    return MB_SUCCESS;
}

Definition at line 74 of file quads_to_tris.cpp.

References moab::Range::begin(), moab::Range::clear(), moab::Range::end(), ErrorCode, moab::Range::insert(), make_tris_from_quad(), and MB_SUCCESS.

Referenced by fix_surface_senses(), and replace_faceted_cgm_surfs().

{
    tris.clear();
    for( Range::const_iterator i = quads.begin(); i != quads.end(); ++i )
    {
        EntityHandle tri0, tri1;
        ErrorCode result = make_tris_from_quad( MBI, *i, tri0, tri1 );
        assert( MB_SUCCESS == result );
        if( MB_SUCCESS != result ) return result;
        tris.insert( tri0 );
        tris.insert( tri1 );
    }
    return MB_SUCCESS;
}

Definition at line 89 of file quads_to_tris.cpp.

References moab::Interface::add_entities(), moab::Range::begin(), moab::Interface::delete_entities(), dim, moab::Range::end(), ErrorCode, GEOM_DIMENSION_TAG_NAME, moab::Interface::get_entities_by_type(), moab::Interface::get_entities_by_type_and_tag(), moab::Interface::globalId_tag(), make_tris_from_quad(), MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MBENTITYSET, MBQUAD, moab::Interface::remove_entities(), moab::Range::size(), moab::Interface::tag_get_data(), and moab::Interface::tag_get_handle().

Referenced by main().

{

    // create a geometry tag to find the surfaces with
    ErrorCode result;
    Tag geom_tag, id_tag;
    result = MBI->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag, MB_TAG_DENSE | MB_TAG_CREAT );
    if( MB_SUCCESS != result ) return result;

    // create an id tag to find the surface id with
    id_tag = MBI->globalId_tag();

    // get all surface meshsets
    Range surface_meshsets;
    int dim           = 2;
    void* input_dim[] = { &dim };
    result = MBI->get_entities_by_type_and_tag( input_meshset, MBENTITYSET, &geom_tag, input_dim, 1, surface_meshsets );
    assert( MB_SUCCESS == result );
    std::cout << surface_meshsets.size() << " surfaces found." << std::endl;

    // ******************************************************************
    // Loop over every surface meshset and grab each surface's quads.
    // ******************************************************************
    for( Range::iterator i = surface_meshsets.begin(); i != surface_meshsets.end(); ++i )
    {

        // get the surface id of the surface meshset
        int surf_id = 0;
        result      = MBI->tag_get_data( id_tag, &( *i ), 1, &surf_id );
        assert( MB_SUCCESS == result );
        std::cout << "  Surface " << surf_id << " has ";

        // get all quads of the surface
        Range quads;
        result = MBI->get_entities_by_type( *i, MBQUAD, quads );
        assert( MB_SUCCESS == result );
        std::cout << quads.size() << " quads." << std::endl;

        // ******************************************************************
        // For each quad, make two triangles then delete the quad.
        // ******************************************************************
        for( Range::iterator j = quads.begin(); j != quads.end(); ++j )
        {

            // make the tris
            EntityHandle tri0 = 0, tri1 = 0;
            result = make_tris_from_quad( MBI, *j, tri0, tri1 );
            assert( MB_SUCCESS == result );

            // add all the tris to the same surface meshset as the quads were inside.
            result = MBI->add_entities( *i, &tri0, 1 );
            if( MB_SUCCESS != result ) std::cout << "result=" << result << std::endl;
            assert( MB_SUCCESS == result );
            result = MBI->add_entities( *i, &tri1, 1 );
            assert( MB_SUCCESS == result );

            // remove the quad from the surface meshset
            result = MBI->remove_entities( *i, &( *j ), 1 );
            assert( MB_SUCCESS == result );

            // delete the quad
            result = MBI->delete_entities( &( *j ), 1 );
            assert( MB_SUCCESS == result );

        }  // end quad loop
    }      // end surface meshset loop
    return MB_SUCCESS;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines