📄 main.c
字号:
//// Qt OpenGL example: Box//// A small example showing how a GLWidget can be used just as any Qt widget// // File: main.cpp//// The main() function // #include <iostream>#include <assert.h>#include <stdlib.h>#include <stdio.h>#include <time.h>#include <queue>#include <malloc.h>#include <math.h>#include <qapplication.h>#include <qgl.h>#include <GL/glut.h>//#include "scape/vector3d.h"//#include "line.h"#include "globjwin.h"#include "_generic.h"#include "sarray.h"#include "real.h"#include "point.h"#include "bbox.h"#include "ftree.h"#include "ftree2d.h"#include "ftreeptr.h"#include "TreeDiam.h"#include "misc.h"#include "algorithm.h"#include "glbox.h"#include "strech.h"//#include "dmalloc.h"//#include "terrain.h"/* The main program is here. *///typedef priority_queue<FSPair, vector<FSPair>, lt_fspair> heap_pairs; //typedef Array<FSPair> FSPairArray;//#define THRESHOLD 10#define LINE_SIZE 1024static void get_line( FILE * fl, char * line ){ char * out; out = fgets( line, 1024, fl ); assert( out != NULL );}void read_poly_file( ArrPoint3d & arr, char * file_name ){ FILE * fl; char line[ LINE_SIZE ]; int vertices, args; arr.init( 10, 3454 ); fl = fopen( file_name, "rt" ); if ( fl == NULL ) { fprintf( stderr, "Unable to open file: [%s]\n", file_name ); exit( -1 ); } while ( ( ! feof( fl ) ) && ( ! str_prefix_eq( line, "element vertex" ) ) ) get_line( fl, line ); if ( feof( fl ) ) { fprintf( stderr, "Vertex num info not found!\n" ); exit( -1 ); } args = sscanf( line, "element vertex %d", &vertices ); if ( args < 1 ) { fprintf( stderr, "Vertex num info non decipherable!\n" ); exit( -1 ); } assert( vertices > 0 ); // skip till end of header while ( ( ! feof( fl ) ) && ( ! str_prefix_eq( line, "end_header" ) ) ) get_line( fl, line ); if ( feof( fl ) ) { fprintf( stderr, "header termination not found!\n" ); exit( -1 ); } // read the vertices for ( int ind = 0; ind < vertices; 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 ); arr.pushx( pnt ); }}void test_array( ArrPoint3d & arr ){ // Using heap Timer tm_heap, tm; tm_heap.start(); TreeDiamAlg td_heap( arr ); td_heap.compute_by_heap( 0.0 ); tm_heap.end(); printf( "points : %d\n", arr.size() ); printf( "td.diameter heap : %g\n", td_heap.diameter() ); printf( " time : %g\n", tm_heap.seconds() ); printf( " nodes : %d\n", td_heap.nodes_number() ); //printf( " nodes : %d\n", td_heap.nodes_num() ); // Regular tm.start(); TreeDiamAlg td( arr ); td.compute_by_level( 0.0 ); tm.end(); printf( "td.diameter : %g\n", td.diameter() ); printf( " time : %g\n", tm.seconds() ); printf( " nodes : %d\n", td.nodes_number() ); //printf( " nodes : %d\n", td.nodes_num() ); Timer tm1; tm1.start(); PointPair diam_pair; double val = brute_diameter( arr, diam_pair ); tm1.end(); printf( "brute diameter: %g\n", val ); printf( " time : %g\n", tm1.seconds() ); Timer tm2; tm2.start(); PointPair diam_pair_2; val = brute_diameter_local( arr, diam_pair_2 ); tm2.end(); printf( "brute diameter (local) : %g\n", val ); printf( " time : %g\n", tm2.seconds() );}#ifdef OPENGL_MAIN_XXint main( int argc, char **argv ){ ArrPoint3d arr; if ( argc == 1 ) { (void)fill_array_cube; (void)fill_array_sphere; fill_array_sphere( arr, 10000 ); //fill_array( arr, 1000 ); test_array( arr ); return 0; } for ( int ind = 1; ind < argc; ind++ ) { printf( "args: %s\n", argv[ ind ] ); read_poly_file( arr, argv[ ind ] ); test_array( arr ); arr.reset(); } return 0;}#endif#ifdef STRANGEint cc = 1234;int dd = 4843;void set_int( int &aa, int &ba ){ aa = cc; ba = dd;}void test_div_speed(){ div_t x; int aa, ba; Timer t; set_int( aa, ba ); t.start(); for ( int ind = 0; ind < 10000000; ind++ ) { x = div( aa, ba ); } t.end(); printf( "time: %.3f\n", t.seconds() ); t.start(); for ( int ind = 0; ind < 10000000; ind++ ) { x.quot = aa / ba; x.rem = aa % ba; } t.end(); printf( "time: %.3f\n", t.seconds() );}#endif // STRANGEint qt_main( int argc, char **argv ){ glutInit( &argc, argv ); QApplication::setColorSpec( QApplication::CustomColor ); QApplication a(argc,argv); //test_div_speed(); if ( !QGLFormat::hasOpenGL() ) { warning( "This system has no OpenGL support. Exiting." ); return -1; } //Terrain terr; //terr.init( "inputs/ashby.stm" ); GLObjectWindow w( 0, 0 ); //w.resize( 1024, 758 ); //w.maximumWidth(), w.maximumHeight() ); //w.showMaximized(); a.setMainWidget( &w ); w.show(); return a.exec();}#define INP_CLOCK 1 #define INP_BUNNY 2 #define INP_DRAGON_3DS 3 #define INP_DS9 4 #define INP_HAND 5 #define INP_DRAGON 6 #define INP_BUDDHA 7 #define INP_BLADE 8 #define INP_SPHERE_1000 9#define INP_SPHERE_10000 10#define INP_SPHERE_100000 11#define INP_SPHERE_200000 12#define INP_COUNTER_1000 13#define INP_COUNTER_10000 14#define INP_COUNTER_100000 15#define INP_COUNTER_200000 16#define INP_CUBE_1000 17#define INP_CUBE_100000 18static void test_input( int input, int mode ){ ArrPoint3d * p_arr; char description[ 1000 ]; p_arr = new ArrPoint3d; p_arr->init( 10, 43283 ); //read_3ds( file_name, *p_arr ); //read_poly_file( *p_arr, file_name ); printf( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" ); switch ( input ) { case INP_CUBE_1000 : printf( "INPUT: Cube 1000\n" ); fill_array_cube( *p_arr, 1000 ); strcpy( description, "cube 10^3" ); break; case INP_CUBE_100000 : printf( "INPUT: Cube 1000\n" ); fill_array_cube( *p_arr, 100000 ); strcpy( description, "cube 10^5" ); break; case INP_SPHERE_1000 : printf( "INPUT: Sphere 1000\n" ); fill_array_sphere( *p_arr, 1000 ); strcpy( description, "sphere 10^3" ); break; case INP_SPHERE_10000 : printf( "INPUT: Sphere 10000\n" ); fill_array_sphere( *p_arr, 10000 ); strcpy( description, "sphere 10^4"); break; case INP_SPHERE_100000 : printf( "INPUT: Sphere 100000\n" ); fill_array_sphere( *p_arr, 100000 ); strcpy( description, "sphere 10^5"); break; case INP_SPHERE_200000 : printf( "INPUT: Sphere 200,000\n" ); fill_array_sphere( *p_arr, 200000 ); strcpy( description, "sphere 10^6"); break; case INP_COUNTER_1000 : printf( "INPUT: Counter 1000\n" ); fill_array_two_arcs( *p_arr, 1000 ); strcpy( description, "ARCS 10^3"); break; case INP_COUNTER_10000 : printf( "INPUT: Counter 10000\n" ); fill_array_two_arcs( *p_arr, 10000 ); strcpy( description, "ARCS 10^4"); break; case INP_COUNTER_100000 : printf( "INPUT: Counter 100000\n" ); fill_array_two_arcs( *p_arr, 100000 ); strcpy( description, "ARCS 10^5"); break; case INP_COUNTER_200000 : printf( "INPUT: Counter 200000\n" ); fill_array_two_arcs( *p_arr, 200000 ); strcpy( description, "ARCS 2*10^5"); break; case INP_DS9 : // DS9.3ds printf( "INPUT: ds9.ply\n" ); read_poly_file( *p_arr, "inputs/ds9.ply" ); strcpy( description, "DS9"); break; case INP_BLADE : // blade.ply printf( "INPUT: blade.ply\n" ); read_poly_file( *p_arr, "inputs/blade.ply" ); strcpy( description, "Blade"); break; case INP_DRAGON : // dragon.ply printf( "INPUT: dragon.ply\n" ); read_poly_file( *p_arr, "inputs/dragon.ply" ); strcpy( description, "Dragon"); break; case INP_DRAGON_3DS : // Dragon.3ds printf( "INPUT: dragon_3ds.ply\n" ); read_poly_file( *p_arr, "inputs/dragon_3ds.ply" ); strcpy( description, "Dragon II"); break; case INP_CLOCK : // clock.3ds printf( "INPUT: clock.ply\n" ); read_poly_file( *p_arr, "inputs/clock.ply" ); strcpy( description, "Clock"); break; case INP_HAND : // hand.ply printf( "INPUT: hand.ply\n" ); read_poly_file( *p_arr, "inputs/hand.ply" ); strcpy( description, "Hand"); break; case INP_BUDDHA : // buddha.ply` printf( "INPUT: happy.ply\n" ); read_poly_file( *p_arr, "inputs/happy.ply" ); strcpy( description, "Buddha"); break; case INP_BUNNY : // bunny.ply printf( "INPUT: bunny.ply\n" ); read_poly_file( *p_arr, "inputs/bunny.ply" ); strcpy( description, "Bunny"); break; //read_poly_file( *p_arr, file_name ); default: printf( "Whats going on? - Unknow input.\n" ); exit( -1 ); }; printf( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" ); pnt_array_normalize( *p_arr ); tester_inner( p_arr, description ); delete p_arr; //tester_mode( p_arr, mode );}void conv_3ds_to_ply( char * in_file, char * out_file ){ FILE * out; ArrPoint3d arr; printf( "converting [%s] -> [%s\n", in_file, out_file ); read_3ds( in_file, arr ); //in = safe_fopen( in_file, "rt" ); //fclose( in ); out = safe_fopen( out_file, "wt" ); fprintf( out, "ply\n" "format ascii 1.0\n" "comment zipper output\n" "comment modified by flipply\n" "element vertex %d\n" "property float32 x\n" "property float32 y\n" "property float32 z\n" "element face 0\n" "property list uint8 int32 vertex_indices\n" "end_header\n", arr.size() ); for ( int ind = 0; ind < arr.size(); ind++ ) fprintf( out, "%.10f %.10f %10f\n", arr[ ind ][ 0 ], arr[ ind ][ 1 ], arr[ ind ][ 2 ] ); fclose( out );}void mem_report() { struct mallinfo mem = mallinfo(); printf( "free sb: %10lu " "free bb: %10lu " "used sb: %10lu " "used bb: %10lu " , (long)mem.fsmblks, (long)mem.fordblks, (long)mem.usmblks, (long)mem.uordblks );}int main( int argc, char **argv ){ int mode, inpt; //printf( "double: %d\n", (int)sizeof( double ) ); //printf( "long double: %d\n", (int)sizeof( long double ) ); //printf( "long long double: %d\n", (int)sizeof( long long double ) ); printf( "QT Verision: %s\n", QT_VERSION_STR ); mode = 1; if ( argc == 1 ) return qt_main( argc, argv ); for ( int ind = 1; ind < argc; ind++ ) { if ( strcmp( argv[ ind ], "-S3" ) == 0 ) { assert( ind < ( argc - 1 ) ); ThreeDs_get_stats( argv[ ind + 1 ] ); exit( -1 ); } if ( strcmp( argv[ ind ], "-P" ) == 0 ) { assert( ind < ( argc - 1 ) ); ply_get_stats( argv[ ind + 1 ] ); exit( -1 ); } if ( strcmp( argv[ ind ], "-C" ) == 0 ) { assert( ind < (argc - 2) ); conv_3ds_to_ply( argv[ ind + 1 ], argv[ ind + 2] ); ind += 2; continue; } if ( strcmp( argv[ ind ], "-I" ) == 0 ) { assert( ind < (argc - 1) ); ind++; inpt = atoi( argv[ ind ] ); assert( inpt > 0 ); test_input( inpt, mode ); continue; } if ( strcmp( argv[ ind ], "-M" ) == 0 ) { assert( ind < (argc - 1) ); ind++; mode = atoi( argv[ ind ] ); assert( mode > 0 ); continue; } if ( argv[ ind ][ 0 ] == '-' ) { printf( "Invalid option: [%s]\n", argv[ ind ] ); exit( -1 ); } tester( argv[ ind ], "" ); } // dmalloc_shutdown();}/* main.C - end of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -