MOAB: Mesh Oriented datABase  (version 5.4.1)
moab::TreeNodePrinter Class Reference
+ Inheritance diagram for moab::TreeNodePrinter:
+ Collaboration diagram for moab::TreeNodePrinter:

Public Member Functions

 TreeNodePrinter (std::ostream &stream, bool list_contents, bool list_box, const char *id_tag_name, OrientedBoxTreeTool *tool_ptr)
virtual ErrorCode visit (EntityHandle node, int depth, bool &descend)
 Visit a node in the tree during a traversal.
virtual ErrorCode leaf (EntityHandle)
 Process a leaf node during tree traversal.

Private Member Functions

ErrorCode print_geometry (EntityHandle node)
ErrorCode print_contents (EntityHandle node)
ErrorCode print_counts (EntityHandle node)

Private Attributes

bool printContents
bool printGeometry
bool haveTag
Tag tag
Tag gidTag
Tag geomTag
Interfaceinstance
OrientedBoxTreeTooltool
std::ostream & outputStream

Detailed Description

Definition at line 1474 of file OrientedBoxTreeTool.cpp.


Constructor & Destructor Documentation

moab::TreeNodePrinter::TreeNodePrinter ( std::ostream &  stream,
bool  list_contents,
bool  list_box,
const char *  id_tag_name,
OrientedBoxTreeTool tool_ptr 
)

Definition at line 1504 of file OrientedBoxTreeTool.cpp.

References ErrorCode, GEOM_DIMENSION_TAG_NAME, geomTag, gidTag, moab::Interface::globalId_tag(), haveTag, instance, MB_SUCCESS, MB_TYPE_INTEGER, tag, and moab::Interface::tag_get_handle().

    : printContents( list_contents ), printGeometry( list_box ), haveTag( false ), tag( 0 ), gidTag( 0 ), geomTag( 0 ),
      instance( tool_ptr->get_moab_instance() ), tool( tool_ptr ), outputStream( stream )
{
    ErrorCode rval;
    if( id_tag_name )
    {
        rval = instance->tag_get_handle( id_tag_name, 1, MB_TYPE_INTEGER, tag );
        if( !rval )
        {
            std::cerr << "Could not get tag \"" << id_tag_name << "\"\n";
            stream << "Could not get tag \"" << id_tag_name << "\"\n";
        }
        else
        {
            haveTag = true;
        }
    }

    gidTag = instance->globalId_tag();

    rval = instance->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geomTag );
    if( MB_SUCCESS != rval ) geomTag = 0;
}

Member Function Documentation

virtual ErrorCode moab::TreeNodePrinter::leaf ( EntityHandle  node) [inline, virtual]

Process a leaf node during tree traversal.

Implements moab::OrientedBoxTreeTool::Op.

Definition at line 1485 of file OrientedBoxTreeTool.cpp.

References MB_SUCCESS.

    {
        return MB_SUCCESS;
    }

Definition at line 1597 of file OrientedBoxTreeTool.cpp.

References moab::Range::begin(), moab::Range::empty(), moab::Range::end(), moab::CN::EntityTypeName(), ErrorCode, moab::Interface::get_entities_by_type(), haveTag, moab::Interface::id_from_handle(), instance, MB_SUCCESS, MBMAXTYPE, MBVERTEX, outputStream, moab::Range::size(), tag, and moab::Interface::tag_get_data().

Referenced by visit().

{
    // list contents
    for( EntityType type = MBVERTEX; type != MBMAXTYPE; ++type )
    {
        Range range;
        ErrorCode rval = instance->get_entities_by_type( node, type, range );
        if( MB_SUCCESS != rval ) return rval;
        if( range.empty() ) continue;
        outputStream << " " << CN::EntityTypeName( type ) << " ";
        std::vector< int > ids( range.size() );
        if( haveTag )
        {
            rval = instance->tag_get_data( tag, range, &ids[0] );
            std::sort( ids.begin(), ids.end() );
        }
        else
        {
            Range::iterator ri              = range.begin();
            std::vector< int >::iterator vi = ids.begin();
            while( ri != range.end() )
            {
                *vi = instance->id_from_handle( *ri );
                ++ri;
                ++vi;
            }
        }

        unsigned i = 0;
        for( ;; )
        {
            unsigned beg = i, end;
            do
            {
                end = i++;
            } while( i < ids.size() && ids[end] + 1 == ids[i] );
            if( end == beg )
                outputStream << ids[end];
            else if( end == beg + 1 )
                outputStream << ids[beg] << ", " << ids[end];
            else
                outputStream << ids[beg] << "-" << ids[end];

            if( i == ids.size() )
            {
                outputStream << std::endl;
                break;
            }
            else
                outputStream << ", ";
        }
    }

    return MB_SUCCESS;
}

Definition at line 1585 of file OrientedBoxTreeTool.cpp.

References moab::CN::EntityTypeName(), ErrorCode, moab::Interface::get_number_entities_by_type(), instance, MB_SUCCESS, MBMAXTYPE, MBVERTEX, and outputStream.

Referenced by visit().

{
    for( EntityType type = MBVERTEX; type != MBMAXTYPE; ++type )
    {
        int count      = 0;
        ErrorCode rval = instance->get_number_entities_by_type( node, type, count );
        if( MB_SUCCESS != rval ) return rval;
        if( count > 0 ) outputStream << " " << count << " " << CN::EntityTypeName( type ) << std::endl;
    }
    return MB_SUCCESS;
}

Definition at line 1570 of file OrientedBoxTreeTool.cpp.

References moab::OrientedBox::axis(), moab::OrientedBoxTreeTool::box(), box(), moab::OrientedBox::center, moab::OrientedBox::dimensions(), ErrorCode, moab::OrientedBox::inner_radius(), length(), MB_SUCCESS, moab::OrientedBox::outer_radius(), outputStream, and tool.

Referenced by visit().

{
    OrientedBox box;
    ErrorCode rval = tool->box( node, box );
    if( MB_SUCCESS != rval ) return rval;

    CartVect length = box.dimensions();

    outputStream << box.center << "  Radius: " << box.inner_radius() << " - " << box.outer_radius() << std::endl
                 << '+' << box.axis( 0 ) << " : " << length[0] << std::endl
                 << 'x' << box.axis( 1 ) << " : " << length[1] << std::endl
                 << 'x' << box.axis( 2 ) << " : " << length[2] << std::endl;
    return MB_SUCCESS;
}
ErrorCode moab::TreeNodePrinter::visit ( EntityHandle  node,
int  depth,
bool &  descend 
) [virtual]

Visit a node in the tree during a traversal.

This method is called for each node in the tree visited during a pre-order traversal.

Parameters:
nodeThe EntityHandle for the entity set for the tree node.
depthThe current depth in the tree.
descendOutput: if false, traversal will skip children of the current node, or if the current node is a leaf, the 'leaf' method will not be called.

Implements moab::OrientedBoxTreeTool::Op.

Definition at line 1533 of file OrientedBoxTreeTool.cpp.

References moab::Range::begin(), ErrorCode, geomTag, moab::Interface::get_entities_by_type_and_tag(), gidTag, moab::Interface::id_from_handle(), instance, MB_SUCCESS, MBENTITYSET, outputStream, print_contents(), print_counts(), print_geometry(), printContents, printGeometry, moab::Range::size(), and moab::Interface::tag_get_data().

{
    descend            = true;
    EntityHandle setid = instance->id_from_handle( node );
    outputStream << setid << ":" << std::endl;

    Range surfs;
    ErrorCode r3 = MB_SUCCESS;
    if( geomTag )
    {
        const int two         = 2;
        const void* tagdata[] = { &two };
        r3 = instance->get_entities_by_type_and_tag( node, MBENTITYSET, &geomTag, tagdata, 1, surfs );

        if( MB_SUCCESS == r3 && surfs.size() == 1 )
        {
            EntityHandle surf = *surfs.begin();
            int id;
            if( gidTag && MB_SUCCESS == instance->tag_get_data( gidTag, &surf, 1, &id ) )
                outputStream << "  Surface " << id << std::endl;
            else
                outputStream << "  Surface w/ unknown ID (" << surf << ")" << std::endl;
        }
    }

    ErrorCode r1 = printGeometry ? print_geometry( node ) : MB_SUCCESS;
    ErrorCode r2 = printContents ? print_contents( node ) : print_counts( node );
    outputStream << std::endl;

    if( MB_SUCCESS != r1 )
        return r1;
    else if( MB_SUCCESS != r2 )
        return r2;
    else
        return r3;
}

Member Data Documentation

Definition at line 1498 of file OrientedBoxTreeTool.cpp.

Referenced by TreeNodePrinter(), and visit().

Definition at line 1498 of file OrientedBoxTreeTool.cpp.

Referenced by TreeNodePrinter(), and visit().

Definition at line 1497 of file OrientedBoxTreeTool.cpp.

Referenced by print_contents(), and TreeNodePrinter().

std::ostream& moab::TreeNodePrinter::outputStream [private]

Definition at line 1501 of file OrientedBoxTreeTool.cpp.

Referenced by print_contents(), print_counts(), print_geometry(), and visit().

Definition at line 1495 of file OrientedBoxTreeTool.cpp.

Referenced by visit().

Definition at line 1496 of file OrientedBoxTreeTool.cpp.

Referenced by visit().

Definition at line 1498 of file OrientedBoxTreeTool.cpp.

Referenced by print_contents(), and TreeNodePrinter().

Definition at line 1500 of file OrientedBoxTreeTool.cpp.

Referenced by print_geometry().

List of all members.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines