int load_polygon_model(char *filename,int n_textures,grs_bitmap ***textures) #endif { #ifdef DRIVE #define r NULL #endif Assert(N_polygon_models < MAX_POLYGON_MODELS); Assert(n_textures < MAX_POLYOBJ_TEXTURES); Assert(strlen(filename) <= 12); strcpy(Pof_names[N_polygon_models],filename); read_model_file(&Polygon_models[N_polygon_models],filename,r); polyobj_find_min_max(&Polygon_models[N_polygon_models]); g3_init_polygon_model(Polygon_models[N_polygon_models].model_data); if (highest_texture_num+1 != n_textures) Error("Model <%s> references %d textures but specifies %d.",filename,highest_texture_num+1,n_textures); Polygon_models[N_polygon_models].n_textures = n_textures; Polygon_models[N_polygon_models].first_texture = first_texture; Polygon_models[N_polygon_models].simpler_model = 0; // Assert(polygon_models[N_polygon_models]!=NULL); N_polygon_models++; return N_polygon_models-1; }
/* GENERATE_CLSF 15nov94 wmt: pass n_data = 0, rather than 300 to read_database; use apply_search_start_fn 25apr95 wmt: add binary data file capability 20may95 wmt: added G_prediction_p Generates and returns a classification from data-base and model(s). Checks for data-base and model(s) already available in *db-list* and *model-list* and if found uses them, otherwise it generates data-base and model(s) by combining information from data-file, header-file, and model-file. Optionally initializes the classification using the start-fn. N-CLASSES is the initial value for the initialized classification. DATA-FILE is fully qualified pathname (file type forced to *data-file-type*). HEADER-FILE can be omitted (gets the same file name as data-file), be a file name (gets the same root as data-file), or be a fully qualified pathname. In all cases, the file type is forced to *header-file-type*. MODEL-FILE has same behavior as header-file. The file type is forced to *model-file-type*. LOG-FILE-P can be nil (no log file produced). If t the file type is forced to be *log-file-type*. OUTPUT-FILES-DEFAULT (names the log file) can be omitted (gets the same root as data-file and file-name of <data-file file name>&<header-file file name>& <model-file file name>, be a file name (gets the same root as data-file), or be a fully qualified pathname. (REREAD_P T) forces a re-read of data-file, and (REGENERATE_P T) forces a re-generation of the model(s) even if they are found in *db-list* and *model-list*. CLSF-INIT-FUN specifies the classification initialization function. (DISPLAY-WTS T) will display class weights produced by the initialization. *package* is bound for interns by read. */ clsf_DS generate_clsf( int n_classes, FILE *header_file_fp, FILE *model_file_fp, FILE *log_file_fp, FILE *stream, int reread_p, int regenerate_p, char *data_file_ptr, char *header_file_ptr, char *model_file_ptr, char *log_file_ptr, int restart_p, char *start_fn_type, unsigned int initial_cycles_p, int max_data, int start_j_list_from_s_params) { int total_error_cnt, total_warning_cnt, num_models = 0; clsf_DS clsf; database_DS db; model_DS *models; int expand_p = FALSE; /* read_database & read_model_file are done here because jtp designed it this way, moving them to process_data_header_model_files breaks the program - wmt */ log_header(log_file_fp, stream, data_file_ptr, header_file_ptr, model_file_ptr, log_file_ptr); db = read_database( header_file_fp, log_file_fp, data_file_ptr, header_file_ptr, max_data, reread_p, stream); models = read_model_file(model_file_fp, log_file_fp, db, regenerate_p, expand_p, stream, &num_models, model_file_ptr); process_data_header_model_files( log_file_fp, regenerate_p, stream, db, models, num_models, &total_error_cnt, &total_warning_cnt); if ((G_prediction_p == FALSE) && (start_j_list_from_s_params == FALSE) && (restart_p == FALSE) && (db->n_data > 1000)) { to_screen_and_log_file("\nWARNING: the default start_j_list may not find the correct\n" " number of classes in your data set!\n", log_file_fp, stream, TRUE); total_warning_cnt++; } check_stop_processing( total_error_cnt, total_warning_cnt, log_file_fp, stderr); if ((G_prediction_p == TRUE) && (G_training_clsf != NULL)) models = G_training_clsf->models; clsf = set_up_clsf( n_classes, db, models, num_models); if ((restart_p == FALSE) && (G_prediction_p == FALSE)) apply_search_start_fn (clsf, start_fn_type, initial_cycles_p, n_classes, log_file_fp, stream); return(clsf); }
int main(int argc, char* argv []) { // Do some output std::cout << "========== Test Suite 1 ==========" << std::endl; std::cout << " Testing computational aspects " << std::endl; // create a variety of stopping power models to test std::vector<StopPow::StopPow*> models; // --------------------------------------- // Set up SRIM models // --------------------------------------- // Load all SRIM models from SRIM directory std::string dir_name("SRIM"); DIR *SRIM_dir = opendir(dir_name.c_str()); if(SRIM_dir) // dir is open { // loop over all files: dirent* result = readdir(SRIM_dir); while( (result=readdir(SRIM_dir)) != NULL ) { // try to load SRIM: try { // construct relative file path/name: std::string fname(dir_name); fname.append("/"); fname.append(result->d_name); // create model and add to the vector: StopPow::StopPow* s = new StopPow::StopPow_SRIM(fname); models.push_back(s); } // catch and ignore all exceptions catch(...){} } } std::cout << models.size() << " SRIM model(s) loaded" << std::endl; // test the SRIM models: bool SRIM_passed = run_tests(models,argc,argv); if(SRIM_passed) std::cout << "Passed!" << std::endl; else { std::cout << "FAILED!" << std::endl; return 1; } // clear the models: for( StopPow::StopPow* s : models ) delete s; models.clear(); // --------------------------------------- // Set up Li-Petrasso models // --------------------------------------- // plasma parameters read from file: std::string fname("test1/LiPetrasso.csv"); std::vector< std::vector<double> > file_data = read_model_file(fname); // construct the models: double mt = 1; double Zt = 1; for(int i=0; i<file_data.size()-3; i+=4) { StopPow::StopPow * s = new StopPow::StopPow_LP(mt,Zt, file_data[i],file_data[i+1], file_data[i+2],file_data[i+3] ); models.push_back(s); } std::cout << models.size() << " Li-Petrasso model(s) loaded" << std::endl; // test the L-P models: bool LP_passed = run_tests(models,argc,argv); if(LP_passed) std::cout << "Passed!" << std::endl; else { std::cout << "FAILED!" << std::endl; return 1; } // clear the models: for( StopPow::StopPow* s : models ) delete s; models.clear(); // --------------------------------------- // Set up Li-Petrasso models // --------------------------------------- // plasma parameters read from file: fname = "test1/BetheBloch.csv"; file_data = read_model_file(fname); // construct the models: mt = 1; Zt = 1; for(int i=0; i<file_data.size()-2; i+=4) { StopPow::StopPow * s = new StopPow::StopPow_BetheBloch(mt,Zt, file_data[i],file_data[i+1], file_data[i+2] ); models.push_back(s); } std::cout << models.size() << " Bethe-Bloch model(s) loaded" << std::endl; // test the L-P models: bool BB_passed = run_tests(models,argc,argv); if(BB_passed) std::cout << "Passed!" << std::endl; else { std::cout << "FAILED!" << std::endl; return 1; } std::cout << "All tests passed" << std::endl; return 0; }
/* see mesh_run.h */ void mesh_run(const struct args *args, struct model_error *model1, struct model_error *model2, struct outbuf *out, struct prog_reporter *progress) { clock_t start_time; struct dist_surf_surf_stats stats; struct dist_surf_surf_stats stats_rev; double bbox1_diag,bbox2_diag; struct model_info *m1info,*m2info; double abs_sampling_step,abs_sampling_dens; int nv_empty,nf_empty; /* Read models from input files */ memset(model1,0,sizeof(*model1)); memset(model2,0,sizeof(*model2)); m1info = (struct model_info*) xa_malloc(sizeof(*m1info)); m2info = (struct model_info*) xa_malloc(sizeof(*m2info)); outbuf_printf(out,"Reading %s ... ",args->m1_fname); outbuf_flush(out); start_time = clock(); model1->mesh = read_model_file(args->m1_fname); outbuf_printf(out,"Done (%.2f secs)\n", (double)(clock()-start_time)/CLOCKS_PER_SEC); outbuf_printf(out,"Reading %s ... ",args->m2_fname); outbuf_flush(out); start_time = clock(); model2->mesh = read_model_file(args->m2_fname); outbuf_printf(out,"Done (%.2f secs)\n", (double)(clock()-start_time)/CLOCKS_PER_SEC); outbuf_flush(out); /* Analyze models (we don't need normals for model 1, so we don't request * for it to be oriented). */ start_time = clock(); bbox1_diag = dist_v(&model1->mesh->bBox[0], &model1->mesh->bBox[1]); bbox2_diag = dist_v(&model2->mesh->bBox[0], &model2->mesh->bBox[1]); analyze_model(model1->mesh,m1info,0,args->verb_analysis,out,"model 1"); model1->info = m1info; analyze_model(model2->mesh,m2info,1,args->verb_analysis,out,"model 2"); model2->info = m2info; /* Adjust sampling step size */ abs_sampling_step = args->sampling_step*bbox2_diag; abs_sampling_dens = 1/(abs_sampling_step*abs_sampling_step); /* Print available model information */ outbuf_printf(out,"\n Model information\n" " (degenerate faces ignored for manifold/closed info)\n\n"); outbuf_printf(out,"Number of vertices: \t%11d\t%11d\n", model1->mesh->num_vert,model2->mesh->num_vert); outbuf_printf(out,"Number of triangles: \t%11d\t%11d\n", model1->mesh->num_faces,model2->mesh->num_faces); outbuf_printf(out,"Degenerate triangles: \t%11d\t%11d\n", m1info->n_degenerate,m2info->n_degenerate); outbuf_printf(out,"BoundingBox diagonal: \t%11g\t%11g\n", bbox1_diag,bbox2_diag); outbuf_printf(out,"Number of disjoint parts:\t%11d\t%11d\n", m1info->n_disjoint_parts,m2info->n_disjoint_parts); outbuf_printf(out,"Manifold: \t%11s\t%11s\n", (m1info->manifold ? "yes" : "no"), (m2info->manifold ? "yes" : "no")); outbuf_printf(out,"Originally oriented: \t%11s\t%11s\n", (m1info->orig_oriented ? "yes" : "no"), (m2info->orig_oriented ? "yes" : "no")); outbuf_printf(out,"Orientable: \t%11s\t%11s\n", (m1info->orientable ? "yes" : "no"), (m2info->orientable ? "yes" : "no")); outbuf_printf(out,"Closed: \t%11s\t%11s\n", (m1info->closed ? "yes" : "no"), (m2info->closed ? "yes" : "no")); outbuf_flush(out); /* Compute the distance from one model to the other */ dist_surf_surf(model1,model2->mesh,abs_sampling_dens,args->min_sample_freq, &stats,!args->no_gui,(args->quiet ? NULL : progress)); /* Print results */ outbuf_printf(out,"Surface area: \t%11g\t%11g\n", stats.m1_area,stats.m2_area); outbuf_printf(out,"\n Distance from model 1 to model 2\n\n"); outbuf_printf(out," \t Absolute\t%% BBox diag\n"); outbuf_printf(out," \t \t (Model 2)\n"); outbuf_printf(out,"Min: \t%11g\t%11g\n", stats.min_dist,stats.min_dist/bbox2_diag*100); outbuf_printf(out,"Max: \t%11g\t%11g\n", stats.max_dist,stats.max_dist/bbox2_diag*100); outbuf_printf(out,"Mean: \t%11g\t%11g\n", stats.mean_dist,stats.mean_dist/bbox2_diag*100); outbuf_printf(out,"RMS: \t%11g\t%11g\n", stats.rms_dist,stats.rms_dist/bbox2_diag*100); outbuf_printf(out,"\n"); outbuf_flush(out); if (args->do_symmetric) { /* Invert models and recompute distance */ outbuf_printf(out," Distance from model 2 to model 1\n\n"); dist_surf_surf(model2,model1->mesh,abs_sampling_dens,args->min_sample_freq, &stats_rev,0,(args->quiet ? NULL : progress)); free_face_error(model2->fe); model2->fe = NULL; outbuf_printf(out," \t Absolute\t%% BBox diag\n"); outbuf_printf(out," \t \t (Model 2)\n"); outbuf_printf(out,"Min: \t%11g\t%11g\n", stats_rev.min_dist,stats_rev.min_dist/bbox2_diag*100); outbuf_printf(out,"Max: \t%11g\t%11g\n", stats_rev.max_dist,stats_rev.max_dist/bbox2_diag*100); outbuf_printf(out,"Mean: \t%11g\t%11g\n", stats_rev.mean_dist,stats_rev.mean_dist/bbox2_diag*100); outbuf_printf(out,"RMS: \t%11g\t%11g\n", stats_rev.rms_dist,stats_rev.rms_dist/bbox2_diag*100); outbuf_printf(out,"\n"); /* Print symmetric distance measures */ outbuf_printf(out, " Symmetric distance between model 1 and model 2\n\n"); outbuf_printf(out," \t Absolute\t%% BBox diag\n"); outbuf_printf(out," \t \t (Model 2)\n"); outbuf_printf(out,"Min: \t%11g\t%11g\n", max(stats.min_dist,stats_rev.min_dist), max(stats.min_dist,stats_rev.min_dist)/bbox2_diag*100); outbuf_printf(out,"Max: \t%11g\t%11g\n", max(stats.max_dist,stats_rev.max_dist), max(stats.max_dist,stats_rev.max_dist)/bbox2_diag*100); outbuf_printf(out,"Mean: \t%11g\t%11g\n", max(stats.mean_dist,stats_rev.mean_dist), max(stats.mean_dist,stats_rev.mean_dist)/bbox2_diag*100); outbuf_printf(out,"RMS: \t%11g\t%11g\n", max(stats.rms_dist,stats_rev.rms_dist), max(stats.rms_dist,stats_rev.rms_dist)/bbox2_diag*100); outbuf_printf(out,"\n"); } outbuf_printf(out," \tAbsolute\t %% BBox diag\t " "Expected samples\n" " \t \t model 2 \t " "model 1\tmodel 2\n"); if (!args->do_symmetric) { outbuf_printf(out,"Sampling step: \t%8g\t %7g \t %7d\t%7d\n", abs_sampling_step,abs_sampling_step/bbox2_diag*100, (int)(stats.m1_area*abs_sampling_dens),0); outbuf_printf(out,"\n"); outbuf_printf(out," \t Total\t Avg. / triangle\t\t" "Tot (%%) area of\n" " \t \tmodel 1\tmodel 2 \t\t" "sampled triang.\n"); outbuf_printf(out,"Samples:\t%9d\t%7.2g\t%7.2g\t\t%15.2f\n",stats.m1_samples, ((double)stats.m1_samples)/model1->mesh->num_faces, ((double)stats.m1_samples)/model2->mesh->num_faces, stats.st_m1_area/stats.m1_area*100.0); } else { outbuf_printf(out,"Sampling step: \t%8g\t %7g \t %7d\t%7d\n", abs_sampling_step,abs_sampling_step/bbox2_diag*100, (int)(stats.m1_area*abs_sampling_dens), (int)(stats.m2_area*abs_sampling_dens)); outbuf_printf(out,"\n"); outbuf_printf(out," \t Total\t Avg. / triangle\t\t" "Tot (%%) area of\n" " \t \tmodel 1 \tmodel 2 \t" "sampled triang.\n"); outbuf_printf(out,"Samples (1->2):\t%9d\t%7.2g\t%15.2g\t%18.2f\n", stats.m1_samples, ((double)stats.m1_samples)/model1->mesh->num_faces, ((double)stats.m1_samples)/model2->mesh->num_faces, stats.st_m1_area/stats.m1_area*100.0); outbuf_printf(out,"Samples (2->1):\t%9d\t%7.2g\t%15.2g\t%18.2f\n", stats_rev.m1_samples, ((double)stats_rev.m1_samples)/model1->mesh->num_faces, ((double)stats_rev.m1_samples)/model2->mesh->num_faces, stats_rev.st_m1_area/stats_rev.m1_area*100.0); } outbuf_printf(out,"\n"); if (!args->do_symmetric) { outbuf_printf(out, " \t X\t Y\t Z\t Total\n"); outbuf_printf(out,"Partitioning grid size:\t%6d\t%5d\t%4d\t%8d\n", stats.grid_sz.x,stats.grid_sz.y,stats.grid_sz.z, stats.grid_sz.x*stats.grid_sz.y*stats.grid_sz.z); outbuf_printf(out,"\nAvg. number of triangles per non-empty cell:\t%.2f\n", stats.n_t_p_nec); outbuf_printf(out,"Proportion of non-empty cells: \t%.2f%%\n", (double)stats.n_ne_cells/(stats.grid_sz.x*stats.grid_sz.y* stats.grid_sz.z)*100.0); } else { outbuf_printf(out," \t " "X\t Y\t Z\t Total\n"); outbuf_printf(out,"Partitioning grid size (1 to 2):\t%6d\t%5d\t%4d\t%8d\n", stats.grid_sz.x,stats.grid_sz.y,stats.grid_sz.z, stats.grid_sz.x*stats.grid_sz.y*stats.grid_sz.z); outbuf_printf(out,"Partitioning grid size (2 to 1):\t%6d\t%5d\t%4d\t%8d\n", stats_rev.grid_sz.x,stats_rev.grid_sz.y,stats_rev.grid_sz.z, stats_rev.grid_sz.x*stats_rev.grid_sz.y*stats_rev.grid_sz.z); outbuf_printf(out,"\nAvg. number of triangles per non-empty cell (1 to 2):" "\t%.2f\n",stats.n_t_p_nec); outbuf_printf(out,"Avg. number of triangles per non-empty cell (2 to 1):" "\t%.2f\n",stats_rev.n_t_p_nec); outbuf_printf(out, "Proportion of non-empty cells (1 to 2): \t%.2f%%\n", (double)stats.n_ne_cells/(stats.grid_sz.x*stats.grid_sz.y* stats.grid_sz.z)*100.0); outbuf_printf(out, "Proportion of non-empty cells (2 to 1): \t%.2f%%\n", (double)stats_rev.n_ne_cells/ (stats_rev.grid_sz.x*stats_rev.grid_sz.y* stats_rev.grid_sz.z)*100.0); } outbuf_printf(out,"\n"); outbuf_printf(out,"Analysis and measuring time (secs.):\t%.2f\n", (double)(clock()-start_time)/CLOCKS_PER_SEC); outbuf_flush(out); if(!args->no_gui){ /* Get the per vertex error metric */ nv_empty = nf_empty = 0; /* keep compiler happy */ calc_vertex_error(model1,&nv_empty,&nf_empty); if (nv_empty>0) { outbuf_printf(out, "WARNING: %.2f%% of vertices (%i out of %i) have no error " "samples\n",100.0*nv_empty/model1->mesh->num_vert, nv_empty,model1->mesh->num_vert); } if (nf_empty>0) { outbuf_printf(out, "WARNING: %.2f%% of faces (%i out of %i) have no error " "samples\n",100.0*nf_empty/model1->mesh->num_faces, nf_empty,model1->mesh->num_faces); } outbuf_flush(out); } }