示例#1
0
int PerformAlgorithm(char option, std::string filename, std::string output_name, std::string analysis){
  Timer overall,flat_resolution_timer;
  overall.start();

	Array2D<elev_t> elevations(filename,false);

  Array2D<d8_flowdir_t> flowdirs(elevations);

	d8_flow_directions(elevations,flowdirs);

  flat_resolution_timer.start();

  if(option=='1'){
  	Array2D<int32_t> flat_resolution_mask, labels;
  	resolve_flats_barnes(elevations,flowdirs,flat_resolution_mask,labels);
    std::cerr<<"t Seconds used to resolve flats = "<<flat_resolution_timer.lap()<<std::endl;

    //If you want to leave the DEM unaltered, use this command
    d8_flow_flats(flat_resolution_mask,labels,flowdirs);
    std::cerr<<"t Seconds used to resolve flats and determine flow directions = "<<flat_resolution_timer.lap()<<std::endl;
  } else if(option=='2'){
    garbrecht_flat_type flats;
    Garbrecht_FindFlats(flowdirs,flats);
    Array2D<int32_t> inc1;
    Array2D<int32_t> inc2;
    Garbrecht_GradientTowardsLower  (elevations, flowdirs, flats, inc1);
    Garbrecht_GradientAwayFromHigher(elevations, flowdirs, flats, inc2);
    Garbrecht_CombineGradients(elevations, inc1, inc2, 0.001);
    std::cerr<<"t Seconds used to resolve flats = "<<flat_resolution_timer.lap()<<std::endl;
    d8_flow_directions(elevations,flowdirs);
    std::cerr<<"t Seconds used to resolve flats and determine flow directions = "<<flat_resolution_timer.lap()<<std::endl;
  } else if(option=='3'){
    //If you want to alter the DEM to enforce drainage, use these commands instead

    //flowdirs.init(-4);
    //d8_flats_alter_dem(flat_resolution_mask, labels, elevations);
    //d8_flow_directions(elevations,flowdirs);
  }

  flowdirs.saveGDAL(output_name,analysis);
  std::cerr<<"t Wall-time = "<<overall.stop()<<std::endl;

  return 0;
}
int main(int argc, char **argv){
	if(argc!=2){
		printf("%s <INPUT DEM>\n",argv[0]);
		return -1;
	}
  Timer overall,flat_resolution_timer;
  overall.start();

	float_2d elevations;

	load_ascii_data(argv[1],elevations);

	char_2d flowdirs;
	d8_flow_directions(elevations,flowdirs);

  flat_resolution_timer.start();
	int_2d flat_resolution_mask, labels;
	resolve_flats_barnes(elevations,flowdirs,flat_resolution_mask,labels);
  printf("%f seconds used to resolve flats.\n",flat_resolution_timer.lap());

  //If you want to leave the DEM unaltered, use this command
  d8_flow_flats(flat_resolution_mask,labels,flowdirs);
  printf("%f seconds used to resolve flats and determine flow directions.\n",flat_resolution_timer.lap());

  //If you want to alter the DEM to enforce drainage, use these commands instead
/*
  flowdirs.init(-4);
  d8_flats_alter_dem(flat_resolution_mask, labels, elevations);
  d8_flow_directions(elevations,flowdirs);
*/

  output_ascii_data("out_barnes",flowdirs,0);
  write_arrows("out_barnes_arrows",flowdirs);

  overall.stop();
  printf("Barnes algorithm took %f seconds overall.\n",overall.accumulated());

	return 0;
}