⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strech.c

📁 任意给定三维空间的点集
💻 C
📖 第 1 页 / 共 2 页
字号:
    info = new SceneInfo;    info->fill_info( scene );    return  info;}void   ThreeDs_get_stats( char  * filename ){    double  len_min, len_max;    H3dsScene   * scene;    //set_global_translate( 0, 0, 0 );    //set_global_scale( 1.0 );    scene = ThreeDS_ReadFromFile( filename );    assert( scene != NULL );    get_scene_ratios( scene );    //get_scene_longest_shortest_edge( scene, len_min, len_max );    //ArrPoint3d  points;    SceneInfo   * info = CompSceneInfo( scene );    //    info->computeLongestShortestEdge();    info->computeRatio();    info->get_longest_shortest_edge( len_min, len_max );    printf( "len_min: %g   len_max: %g\n", len_min, len_max );    (void)info;    printf( "RES: [%20s]  %12g  %12g   vert#: %d\n",            filename,             len_max / len_min,            info->global_vertex_ratio,            info->size );                exit( -1 );           }int  compDouble( const double  & a, const double  & b ){    if  ( a < b )         return  1;    if  ( a > b )        return  -1;    return  0;}void  PolyModel::print_stat( const char  * filename ){    printf( "\n\n" );    printf( "Longest edge: %g  shrotest edge: %g\n", longest_edge,            shortest_edge );    global_ratio = longest_edge / shortest_edge;    printf( "global_ratio = %g\n", global_ratio );    edge_ratio = 0;    int  skip_count;    Array<double>   arr_rt;    arr_rt.init( vertices_num, 24352 );    double   max_rt;    max_rt = -1;    worst_vertex = -1;    skip_count = 0;    for  ( int  ind = 0; ind < vertices_num; ind++ ) {        double  rt;        if  ( p_dist_nn[ ind ] == 0.0 ) {            skip_count++;            continue;        }        rt = p_longest_edge[ ind ] / p_dist_nn[ ind ];        if  ( rt > max_rt ) {            worst_vertex = ind;            max_rt = rt;        }        arr_rt.pushx( rt );        if  ( rt > edge_ratio )            edge_ratio = rt;    }    printf( "%d vertices were skipped\n", skip_count );    printf( "[%-20s] se/le: %12.5g  max vert rt : %12.5g\n",            filename, global_ratio, edge_ratio );    arr_rt.quickSort( compDouble );    int  start, end;    double  limit;    end = start = 0;    while  ( end < (int)( arr_rt.size() - 1 ) ) {        limit = arr_rt[ start ] * 0.8;        end = start;        while  ( ( arr_rt[ end ] >= limit )                   &&  ( end < (int)(arr_rt.size() - 1 ) ) )            end++;        printf( "Range: %10.5g - %10.5g: %6d\n",                 arr_rt[ start ], arr_rt[ end - 1 ], end - start );        start = end;    }    //for  ( int  ind = 0; ind < 100; ind++ )    //    printf( "%d: %g\n", ind, arr_rt[ ind ] );}void  PolyModel::register_edge( int  a, int  b ){    double  len;    //printf( "registreing edge( %d, %d)  vertices: %d\n", a, b,    //        (int)vertices.size() );    len = pnt_distance( vertices[ a ], vertices[ b ] );    if  ( len > p_longest_edge[ a ] )         p_longest_edge[ a ] = len;    if  ( len > p_longest_edge[ b ] )         p_longest_edge[ b ] = len;        //printf( "bogi1\n" );    if  ( f_first_edge_registeration ) {        f_first_edge_registeration = false;        longest_edge = shortest_edge = len;    }    //printf( "bogi2\n" );    if  ( len > 0.0 ) {        if  ( len > longest_edge )            longest_edge = len;        if  ( len < shortest_edge )            shortest_edge = len;    }}void  PolyModel::compute_longest_edges(){    //printf( "computing longest edges\n" );    p_longest_edge = (double *)malloc( sizeof( double ) * vertices_num );    assert( p_longest_edge != NULL );    for  ( int  ind = 0; ind < vertices_num; ind++ )        p_longest_edge[ ind ] = 0;    for  ( int  ind = 0; ind < faces_num; ind++ ) {        //printf( "ind: %d\n", ind );        //printf( "faces.size: %d\n", (int)faces.size() );        register_edge( faces[ ind ].a, faces[ ind ].b );        register_edge( faces[ ind ].b, faces[ ind ].c );        register_edge( faces[ ind ].c, faces[ ind ].a );    }}void   PolyModel::find_bbox_nn( Point3d  & pnt,                                  int  vert_id,                                  double  & curr,                                 int  bbox_ind ){    int  start, end;        start = getBBoxStart( bbox_ind );    end   = getBBoxEnd( bbox_ind );        for  ( int  jnd = start; jnd <= end; jnd++ ) {        if  ( jnd == vert_id )             continue;        double  dist = pnt_distance( pnt, vertices[ jnd ] );        if  ( dist < curr )             curr = dist;    }}double  PolyModel::find_nn( int   vert_id ) {    Point3d  & pnt( vertices[ vert_id ] );    double  curr;    int  chunk_done;    curr = pnt_distance( pnt, vertices[ 0 ] );    chunk_done = vert_id / BBOX_CHUNK;    find_bbox_nn( pnt, vert_id, curr, chunk_done );    for  ( int  ind = 0; ind < boxes_num; ind++ ) {        if  ( ind == chunk_done )            continue;        Point3d   proj = vert_bboxes[ ind ].project( pnt );                if  ( pnt_distance( pnt, proj ) > curr )             continue;        find_bbox_nn( pnt, vert_id, curr, ind  );    }    return  curr;}void    PolyModel::find_nn_all(){    p_dist_nn = (double *)malloc( sizeof( double ) * vertices_num );    assert( p_dist_nn != NULL );    //printf( "Computing NN...\n" );    for  ( int  ind = 0; ind < vertices_num; ind++ ) {        if  ( ( ind & 0x7ff ) == 0 ) {            printf( "%7d     \r", ind );            fflush( stdout );        }        p_dist_nn[ ind ] = find_nn( ind );    }}void  PolyModel::init_vertices_bboxes(){    boxes_num = ((vertices_num - 1) / BBOX_CHUNK) + 1;    vert_bboxes.init( boxes_num, 85947 );    for  ( int  ind = 0; ind < boxes_num; ind++ ) {        int  start, end;        start = getBBoxStart( ind );        end   = getBBoxEnd( ind );        BBox3d   bb;        bb.init();        for  ( int  jnd = start; jnd <= end; jnd++ )             bb.bound( vertices[ jnd ] );        vert_bboxes.pushx( bb );    }}void  PolyModel::read_poly_file( const char  * filename ){    FILE  * fl;    char  line[ LINE_SIZE ];    int  args;    printf( "Model: %s\n", filename );    //printf( "bogi\n" );    vertices.init( 10, 3454 );    faces.init( 20, 53332 );    fl = fopen( filename, "rt" );    if  ( fl == NULL ) {        fprintf( stderr, "Unable to open file: [%s]\n",                 filename );        exit( -1 );    }    line[ 0 ] = 0;    vertices_num = faces_num = -1;    //printf( "mogi\n" );    //fflush( stdout );    while  ( ( ! feof( fl ) )               &&  ( ! str_prefix_eq( line, "end_header" ) ) ) {        get_line( fl, line );        //printf( "shogi\n" );        if  ( str_prefix_eq( line, "element vertex" ) ) {            args = sscanf( line, "element vertex %d", &vertices_num );            if  ( args < 1 ) {                fprintf( stderr, "Vertex num info non decipherable!\n" );                exit( -1 );            }            assert( vertices_num > 0 );        }                      if  ( str_prefix_eq( line, "element face" ) ) {            args = sscanf( line, "element face %d", &faces_num );            if  ( args < 1 ) {                fprintf( stderr, "Vertex num info non decipherable!\n" );                exit( -1 );            }            assert( faces_num > 0 );        }             }        if  ( feof( fl ) ) {        fprintf( stderr, "Vertex/face num info not found!\n" );        exit( -1 );    }    if  ( vertices_num < 0 ) {        printf( "Vertices # not found!\n" );        exit( -1 );    }    if  ( faces_num < 0 ) {        printf( "Faces # not found!\n" );        exit( -1 );    }    printf( "Model: Vertices #: %d  Faces #: %d\n", vertices_num, faces_num );         //printf( "Reading vertices\n" );    // read the vertices    for  ( int  ind = 0; ind < vertices_num; ind++ ) {        double  x, y, z;        get_line( fl, line );        if  ( feof( fl ) ) {            fprintf( stderr, "unexpected end of file!\n" );            exit( -1 );        }        args = sscanf( line, "%lg %lg %lg", &x, &y, &z );        Point3d  pnt;        pnt.setCoord( 0, x  );        pnt.setCoord( 1, y );        pnt.setCoord( 2, z );        vertices.pushx( pnt );    }    // read the vertices    //printf( "Reading faces\n" );    for  ( int  ind = 0; ind < faces_num; ind++ ) {        int  a, b, c, r;        get_line( fl, line );        if  ( feof( fl ) ) {            fprintf( stderr, "unexpected end of file!\n" );            exit( -1 );        }        args = sscanf( line, "%d %d %d %d", &r, &a, &b, &c );        assert( r == 3 );        FaceIds  fi;        fi.a = a;        fi.b = b;        fi.c = c;        assert( ( 0 <= a )  &&  ( a < vertices_num ) );        assert( ( 0 <= b )  &&  ( b < vertices_num ) );        assert( ( 0 <= c )  &&  ( c < vertices_num ) );         faces.pushx( fi );    }    printf( "Reading done!\n" );}bool  str_prefix_eq( char  * line, char  * prefix ){    while  ( *prefix ) {        if  ( *line != *prefix )            return  false;        line++;        prefix++;    }    return  true;}void   ply_get_stats( char  * filename ){    PolyModel  * p_model;    Timer  tm;    tm.start();    p_model = new PolyModel;        p_model->init();    p_model->read_poly_file( filename );    p_model->init_vertices_bboxes();    p_model->find_nn_all();    p_model->compute_longest_edges();    //p_model->compute_longest_edges();    p_model->print_stat( filename );    tm.end();    printf( "Time: %g\n", tm.seconds() );}void   PolyModel::computeBBox(){    modelBB.init();    for  ( int  ind = 0; ind < vertices.size(); ind++ )        modelBB.bound( vertices[ ind ] );}/* strech.C - End of File ------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -