MOAB: Mesh Oriented datABase  (version 5.4.1)
obb_time.cpp File Reference
#include "moab/Core.hpp"
#include "moab/CartVect.hpp"
#include "moab/OrientedBox.hpp"
#include "moab/OrientedBoxTreeTool.hpp"
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
#include <csignal>
#include <cassert>
+ Include dependency graph for obb_time.cpp:

Go to the source code of this file.

Functions

static void usage ()
void generate_ray (const CartVect &sphere_center, double sphere_radius, CartVect &point, CartVect &dir)
ErrorCode read_tree (Interface *instance, const char *filename, EntityHandle &tree_root_out)
void signal_handler (int)
int main (int argc, char *argv[])

Variables

const int NUM_RAYS = 40000
const int NUM_XSCT = 20000
int num_rays = NUM_RAYS
int num_xsct = NUM_XSCT
const char * filename = 0
bool do_sets = false
bool do_trv_stats = false
int rays = 0
int xsct = 0
int gen = 0
clock_t ttimer

Function Documentation

void generate_ray ( const CartVect sphere_center,
double  sphere_radius,
CartVect point,
CartVect dir 
)

Definition at line 31 of file obb_time.cpp.

References moab::CartVect::normalize().

Referenced by main().

{
    const int H = RAND_MAX / 2;
    point[0]    = (double)rand() / H - 1;
    point[1]    = (double)rand() / H - 1;
    point[2]    = (double)rand() / H - 1;
    point *= sphere_radius;

    dir[0] = (double)rand() * -point[0];
    dir[1] = (double)rand() * -point[1];
    dir[2] = (double)rand() * -point[2];
    dir.normalize();

    point += sphere_center;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 84 of file obb_time.cpp.

References moab::CartVect::array(), moab::OrientedBoxTreeTool::box(), box(), moab::OrientedBox::center, do_sets, do_trv_stats, ErrorCode, filename, gen, generate_ray(), iface, MB_SUCCESS, num_rays, num_xsct, moab::OrientedBox::outer_radius(), moab::OrientedBoxTreeTool::TrvStats::print(), moab::OrientedBoxTreeTool::ray_intersect_sets(), moab::OrientedBoxTreeTool::ray_intersect_triangles(), rays, read_tree(), signal_handler(), ttimer, usage, and xsct.

{
    signal( SIGINT, &signal_handler );

    for( int i = 1; i < argc; ++i )
    {
        if( !strcmp( argv[i], "-r" ) )
        {
            ++i;
            if( i == argc || !argv[i][0] )
            {
                std::cerr << "Expected value following '-r'" << std::endl;
                usage();
            }
            char* end;
            long t1  = strtol( argv[i], &end, 0 );
            num_rays = (int)t1;
            if( *end || t1 < 0 || num_rays != t1 )
            {
                std::cerr << "Expected positive integer following '-r'" << std::endl;
                usage();
            }
        }
        else if( !strcmp( argv[i], "-i" ) )
        {
            ++i;
            if( i == argc || !argv[i][0] )
            {
                std::cerr << "Expected value following '-i'" << std::endl;
                usage();
            }
            char* end;
            long t1  = strtol( argv[i], &end, 0 );
            num_xsct = (int)t1;
            if( *end || t1 < 0 || num_xsct != t1 )
            {
                std::cerr << "Expected positive integer following '-i'" << std::endl;
                usage();
            }
        }
        else if( !strcmp( argv[i], "-s" ) )
        {
            do_sets = true;
        }
        else if( !strcmp( argv[i], "-p" ) )
        {
            do_trv_stats = true;
        }
        else if( filename )
        {
            std::cerr << "Invalid options or multiple file names specified." << std::endl;
            usage();
        }
        else
        {
            filename = argv[i];
        }
    }
    if( !filename )
    {
        std::cerr << "No file name specified." << std::endl;
        usage();
    }

    Core instance;
    Interface* iface = &instance;
    EntityHandle root;
    ErrorCode rval = read_tree( iface, filename, root );
    if( MB_SUCCESS != rval )
    {
        std::cerr << "Failed to read \"" << filename << '"' << std::endl;
        return 2;
    }

    OrientedBoxTreeTool tool( iface );
    OrientedBox box;
    rval = tool.box( root, box );
    if( MB_SUCCESS != rval )
    {
        std::cerr << "Corrupt tree.  Cannot get box for root node." << std::endl;
        return 3;
    }

    OrientedBoxTreeTool::TrvStats* stats = NULL;
    if( do_trv_stats )
    {
        stats = new OrientedBoxTreeTool::TrvStats;
    }

    const unsigned cached = 1000;
    std::vector< double > intersections;
    std::vector< EntityHandle > sets, facets;
    CartVect point, dir;
    std::vector< CartVect > randrays;
    randrays.reserve( cached );
    int cached_idx = 0;

    ttimer = clock();
    for( ;; )
    {
        if( !num_rays )
        {
            if( xsct >= num_xsct ) break;
        }
        else if( !num_xsct )
        {
            if( rays >= num_rays ) break;
        }
        else if( rays >= num_rays && xsct >= num_xsct )
            break;

        ++rays;
        if( randrays.size() < cached )
        {
            generate_ray( box.center, box.outer_radius(), point, dir );
            ++gen;
        }
        else
        {
            point      = randrays[cached_idx++];
            dir        = randrays[cached_idx++];
            cached_idx = cached_idx % randrays.size();
        }

        intersections.clear();
        if( do_sets )
        {
            sets.clear();
            facets.clear();

            OrientedBoxTreeTool::IntersectSearchWindow search_win;
            OrientedBoxTreeTool::IntRegCtxt int_reg_ctxt;
            rval = tool.ray_intersect_sets( intersections, sets, facets, root, 1e-6, point.array(), dir.array(),
                                            search_win, int_reg_ctxt, stats );
        }
        else
        {
            rval =
                tool.ray_intersect_triangles( intersections, facets, root, 1e-6, point.array(), dir.array(), 0, stats );
        }
        if( MB_SUCCESS != rval )
        {
            std::cerr << "Rayfire #" << rays << " failed." << std::endl;
            return 4;
        }

        if( !intersections.empty() )
        {
            ++xsct;
        }

        if( randrays.size() < cached && ( !intersections.empty() || !num_xsct || xsct >= num_xsct ) )
        {
            randrays.push_back( point );
            randrays.push_back( dir );
        }
    }

    ttimer = clock() - ttimer;
    std::cout << rays << " ray fires done" << std::endl
              << gen << " unique rays used" << std::endl
              << xsct << " intersecting fires" << std::endl
              << (double)ttimer / CLOCKS_PER_SEC << " seconds" << std::endl;

    if( do_trv_stats )
    {
        std::cout << "Traversal statistics: " << std::endl;
        stats->print( std::cout );
    }

    return 0;
}
ErrorCode read_tree ( Interface instance,
const char *  filename,
EntityHandle tree_root_out 
)

Definition at line 47 of file obb_time.cpp.

References ErrorCode, moab::Interface::load_mesh(), MB_SUCCESS, MB_TYPE_HANDLE, moab::Interface::tag_get_data(), and moab::Interface::tag_get_handle().

Referenced by main().

{
    ErrorCode rval = instance->load_mesh( filename );
    if( MB_SUCCESS != rval ) return rval;

    Tag tag;
    rval = instance->tag_get_handle( "OBB_ROOT", 1, MB_TYPE_HANDLE, tag );
    if( MB_SUCCESS != rval ) return rval;

    const EntityHandle root = 0;
    return instance->tag_get_data( tag, &root, 1, &tree_root_out );
}
void signal_handler ( int  )

Definition at line 72 of file obb_time.cpp.

References filename, gen, num_rays, num_xsct, rays, ttimer, and xsct.

Referenced by main().

{
    ttimer = clock() - ttimer;
    std::cout << filename << ":" << std::endl
              << rays << " of " << num_rays << " ray fires done" << std::endl
              << xsct << " of " << num_xsct << " intersecting fires" << std::endl
              << gen << " unique rays used" << std::endl
              << (double)ttimer / CLOCKS_PER_SEC << " seconds" << std::endl;
    exit( 1 );
}
static void usage ( ) [static]

Definition at line 17 of file obb_time.cpp.

References NUM_RAYS, and NUM_XSCT.

{
    std::cerr << "obb_time [-r <int>] [-i <int>] <filename>" << std::endl
              << "  -r - Specify total rays to fire." << std::endl
              << "       Zero implies unbounded. Default: " << NUM_RAYS << std::endl
              << "  -i - Specify total intersecting rays to fire." << std::endl
              << "       Zero implies unbounded. Default: " << NUM_XSCT << std::endl
              << "  -s - Use set-based tree." << std::endl
              << "  -p - Measure and report traversal performance statistics" << std::endl
              << "  The input file should be generated using the '-s'" << std::endl
              << "  option with 'obb_test'" << std::endl;
    exit( 1 );
}

Variable Documentation

bool do_sets = false

Definition at line 64 of file obb_time.cpp.

Referenced by main().

bool do_trv_stats = false

Definition at line 65 of file obb_time.cpp.

Referenced by main().

const char* filename = 0

Definition at line 63 of file obb_time.cpp.

int gen = 0

Definition at line 68 of file obb_time.cpp.

Referenced by main(), and signal_handler().

const int NUM_RAYS = 40000

Definition at line 12 of file obb_time.cpp.

Referenced by usage().

Definition at line 61 of file obb_time.cpp.

Referenced by main(), and signal_handler().

const int NUM_XSCT = 20000

Definition at line 13 of file obb_time.cpp.

Referenced by usage().

Definition at line 62 of file obb_time.cpp.

Referenced by main(), and signal_handler().

int rays = 0

Definition at line 68 of file obb_time.cpp.

Referenced by main(), and signal_handler().

clock_t ttimer

Definition at line 69 of file obb_time.cpp.

Referenced by main(), and signal_handler().

int xsct = 0

Definition at line 68 of file obb_time.cpp.

Referenced by main(), and signal_handler().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines