void display_3d(void) { glMatrixMode(GL_MODELVIEW); /* Update viewer position in modelview matrix */ glLoadIdentity(); set_viewpoint(); glTranslatef(-1,0,0); glColor3f(0.5, 0.5, 0.5); int r = 0; std::for_each(maze->begin(), maze->end(), std::bind2nd(draw_row(), &r)); draw_rat(walker->position(), true); draw_floor(); }
/* ingrid is the input grid that contains the header and data. outgrid is the ouutput grid, it has a valid header and data is allocated but has no values yet. the eventlist contains all events for any viewpoint. */ void compute_multiviewshed_radial(MultiviewOptions opt, int DO_EVERY, Grid* ingrid, Grid* outgrid, int nevents, Event* eventlist) { assert(ingrid && outgrid && eventlist); printf("\n----------------------------------------\n"); printf("Starting radial sweep, total %d viewpoints.\n", opt.NVIEWSHEDS); int nvis, nviewsheds=0; Rtimer sweepTotalTime; int nrows, ncols, row, col; Viewpoint vp; /* get raster rows and cols */ nrows = ingrid->hd->nrows; ncols = ingrid->hd->ncols; /* ************************************************************ */ //compute just one viewshed if (opt.NVIEWSHEDS == 1) { rt_start(sweepTotalTime); //compute just one viewshed count set_viewpoint(&vp, opt.vr, opt.vc, get(ingrid, opt.vr, opt.vc)); if (is_nodata_at(ingrid, opt.vr, opt.vc)) printf("point at (%5d,%5d): NODATA\n",opt.vr, opt.vc); else { /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventlist*/ #ifdef SYSTEM_SORT qsort(eventlist, nevents, sizeof(Event), compare_events_angle); #else event_quicksort_radial(eventlist, nevents); #endif /*compute the visibility of the viewpoint */ nvis = sweep_radial(eventlist,nevents, ingrid->grid_data[opt.vr], vp,ingrid); rt_stop(sweepTotalTime); printf("v=(%5d,%5d): nvis=%10d\n", opt.vr, opt.vc, nvis); fflush(stdout); printf("TOTAL time: \n"); char timeused[100]; rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; } /* ************************************************************ */ //else compute VC for many/all viewpoints rt_start(sweepTotalTime); for(row = 0; row < nrows; row++) { for (col = 0; col < ncols; col++) { if (((row*ncols)+col) % DO_EVERY !=0){ /* do not compute the viewshed of this point: set this point in the output as NODATA */ set_nodata(outgrid, row, col); continue; } /*check if this point is nodata. If it is, write it as such in output raster and continue*/ if (is_nodata_at(ingrid, row, col)) { set_nodata(outgrid, row, col); if (opt.NVIEWSHEDS < 10) //don't print unless very few viewsheds printf("point at (%5d,%5d): NODATA; ignoring\n",row, col); fflush(stdout); continue; } /* compute the viewshed of this point */ nviewsheds++; /* print progress to the user: one dot per viewshed computed*/ //printf("."); fflush(stdout); //printf("point at (%5d,%5d): ",row, col); fflush(stdout); /*set the viewpoint to be this point */ float crt_elev = get(ingrid, row, col); set_viewpoint(&vp, row, col, crt_elev); /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventlist*/ /* note: this should be done with an optimized quicksort */ qsort(eventlist, nevents, sizeof(Event), compare_events_angle); /*compute the visibility of the viewpoint */ nvis = sweep_radial(eventlist,nevents, ingrid->grid_data[row],vp,ingrid); /* write nvis to the output raster */ set(outgrid, row, col, nvis); #ifdef INTERPOLATE_RESULT //insert this poitn in the array of computed viewsheds Nvis x = {row,col,nvis}; viewsheds[nvp] = x; nvp++; #endif //print this point if (opt.verbose) printf("v=(%5d,%5d): nvis=%10d\n", row, col, nvis); } /* for col */ } /* for row */ rt_stop(sweepTotalTime); printf("\ndone.\n"); printf("----------------------------------------\n"); printf("RADIAL sweep:\n"); printf("total nviewsheds=%d\n", nviewsheds); if (nviewsheds==0) { printf("%20s: 0\n", "total"); } else { char timeused[100]; rt_sprint_safe_average(timeused, sweepTotalTime, nviewsheds); printf("AVERAGE viewshed time per viewpoint: \n"); printf("%20s: %s\n", "total", timeused); printf("TOTAL time: \n"); rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; }
/* ************************************************************ */ void compute_multiviewshed_distribution(MultiviewOptions opt, int DO_EVERY, Grid* ingrid, Grid* outgrid, int nevents, Event* eventlist) { assert(ingrid && outgrid && eventlist); printf("\n----------------------------------------\n"); printf("Starting distribute sweep"); printf("total %d viewpoints, BASECASE_THRESHOLD=%d NUM_SECTORS=%d\n", opt.NVIEWSHEDS, opt.BASECASE_THRESHOLD,opt.NUM_SECTORS); Viewpoint vp; int nvis; int dropped, total_dropped=0; /* dropped cells during distribution */ int nviewsheds = 0; Rtimer sweepTotalTime; int nrows, ncols, row, col; /* get raster rows and cols */ nrows = ingrid->hd->nrows; ncols = ingrid->hd->ncols; /* ************************************************************ */ //compute just one viewshed if (opt.NVIEWSHEDS == 1) { rt_start(sweepTotalTime); //compute just one viewshed count set_viewpoint(&vp, opt.vr, opt.vc, get(ingrid, opt.vr, opt.vc)); if (is_nodata_at(ingrid, opt.vr, opt.vc)) printf("point at (%5d,%5d): NODATA\n",opt.vr, opt.vc); else { /*set the viewpoint to be this point */ float crt_elev = get(ingrid, opt.vr, opt.vc); set_viewpoint(&vp, opt.vr, opt.vc, crt_elev); /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventlist*/ #ifdef SYSTEM_SORT qsort(eventlist, nevents, sizeof(Event), compare_events_angle); #else event_quicksort_radial(eventlist, nevents); #endif /*compute the visibility of the viewpoint */ dropped = 0; nvis = distribute_and_sweep(eventlist, nevents, opt.NUM_SECTORS, opt.BASECASE_THRESHOLD, &vp, &dropped); /* update total number of drpped cells */ total_dropped += dropped; /* write nvis to output raster */ set(outgrid, opt.vr, opt.vc, nvis); rt_stop(sweepTotalTime); printf("v=(%5d,%5d): nvis=%10d\n", opt.vr, opt.vc, nvis); fflush(stdout); printf("cells dropped = %d\n", total_dropped); char timeused[100]; printf("TOTAL time: \n"); rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; } /* ************************************************************ */ //else compute VC for many/all viewpoints for(row = 0; row < nrows; row++) { for(col = 0; col < ncols; col++) { if(((row*ncols)+col) % DO_EVERY != 0){ /* do not compute the viewshed of this point: set this point in the output as NODATA */ set_nodata(outgrid, row, col); continue; } /* check if this point is nodata. If it is, write it as such in output raster and continue*/ if (is_nodata_at(ingrid, row, col)) { set_nodata(outgrid, row, col); if (opt.NVIEWSHEDS < 10) //don't print unless very few viewsheds printf("point at (%5d,%5d): NODATA; ignoring\n",row, col); fflush(stdout); continue; } /* compute the viewshed of this point */ nviewsheds++; /* print progress to user, one dot per viewpoint */ //printf("."); fflush(stdout); /*set the viewpoint to be this point */ float crt_elev = get(ingrid, row, col); set_viewpoint(&vp, row, col, crt_elev); /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventList by distance */ //printf("\nsorting concentrically.."); fflush(stdout); #ifdef SYSTEM_SORT qsort(eventlist, nevents, sizeof(Event), compare_events_dist); #else event_quicksort_distance(eventlist, nevents); #endif /*distribute and sweep */ dropped = 0; nvis = distribute_and_sweep(eventlist, nevents, opt.NUM_SECTORS, opt.BASECASE_THRESHOLD, &vp, &dropped); /* update total number of drpped cells */ total_dropped += dropped; /* write nvis to output raster */ set(outgrid, row, col, nvis); #ifdef INTERPOLATE_RESULT //insert this poitn in the array of computed viewsheds Nvis x = {row,col,nvis}; viewsheds[nvp] = x; nvp++; #endif // print this point if (opt.verbose) { printf("point at (%5d,%5d): ",row, col); fflush(stdout); printf("nvis=%10d, dropped=%10d\n", nvis, dropped); fflush(stdout); } } /* for col */ } /* for row */ rt_stop(sweepTotalTime); printf("\ndone."); printf("DISTRIBUTION SWEEP: BASECASE_THRESHOLD=%d NUM_SECTORS=%d\n", opt.BASECASE_THRESHOLD,opt.NUM_SECTORS); printf("total nviewsheds=%d\n", nviewsheds); if (nviewsheds==0) { printf("%20s: 0\n", "total"); } else { float avg_dropped; avg_dropped = (float)total_dropped / (float)nviewsheds; printf("average nb. cells dropped = %f (%.2f %%)\n", avg_dropped, avg_dropped/(float)nevents * 100); char timeused[100]; rt_sprint_safe_average(timeused, sweepTotalTime, nviewsheds); printf("AVERAGE TIME PER VIEWPOINT: \n"); printf("\t%20s: %s\n", "viewshed average total", timeused); printf("TOTAL time: \n"); rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; }
//--------------------------------------------------------------------------- void OGL::set_viewpoint(double l,double theta_in,double phi_in) { set_viewpoint(l,theta_in,phi_in,0,0,0, 1.0); }