regionator.cc
// Splits the image to be regionated into a set of lower resolution tiles.
Splits the image to be regionated into a set of lower resolution tiles.
Splits the image to be regionated into a set of lower resolution tiles .
void Regionator::Regionate(void) const {
  assert(x_tile_size_ > 0);
  assert(y_tile_size_ > 0);
  if (!IsDirectory(output_directory_) && !CreateDirectory(output_directory_)) {
    fprintf(stderr, "\nCannot create output directory '%s'\n",
            output_directory_.c_str());
    exit(EXIT_FAILURE);
  }
  int width_padded = image_->width() + Pad(image_->width(), x_tile_size_);
  int height_padded = image_->height() + Pad(image_->height(), y_tile_size_);
  SplitTileRecursively(0, 0, 0, width_padded - 1, height_padded - 1);
  KmlNetworkLink network_link = MakeNetworkLink(0, 0, width_padded - 1,
                                                height_padded - 1);
  KmlRegion region = network_link.region.get();
  KmlLod lod = region.lod.get();
  lod.min_lod_pixels.set(0);
  lod.max_lod_pixels.set(-1);
  region.lod.set(lod);
  network_link.region.set(region);
  KmlLink link = network_link.link.get();
  string href = link.href.get();
  link.href.set(output_directory_ + "/" + href);
  network_link.link.set(link);
  Kml kml;
  kml.AddNetworkLink(network_link);
  string kmlfile = output_directory_ + "/" + root_kml_;
  FILE *fp = fopen(root_kml_.c_str(), "w");
  if (!fp) {
    fprintf(stderr, "\nCan't open file '%s' for writing\n", root_kml_.c_str());
    exit(EXIT_FAILURE);
  }
  fprintf(fp, "%s", kml.ToString().c_str());
  fclose(fp);
}
void Regionator :: Regionate ( void ) const { assert ( x_tile_size_ > 0 ) ; assert ( y_tile_size_ > 0 ) ; if ( ! IsDirectory ( output_directory_ ) && ! CreateDirectory ( output_directory_ ) ) { fprintf ( stderr , " \n \n " , output_directory_ . c_str ( ) ) ; exit ( EXIT_FAILURE ) ; } int width_padded = image_ -> width ( ) + Pad ( image_ -> width ( ) , x_tile_size_ ) ; int height_padded = image_ -> height ( ) + Pad ( image_ -> height ( ) , y_tile_size_ ) ; SplitTileRecursively ( 0 , 0 , 0 , width_padded - 1 , height_padded - 1 ) ; KmlNetworkLink network_link = MakeNetworkLink ( 0 , 0 , width_padded - 1 , height_padded - 1 ) ; KmlRegion region = network_link . region . get ( ) ; KmlLod lod = region . lod . get ( ) ; lod . min_lod_pixels . set ( 0 ) ; lod . max_lod_pixels . set ( -1 ) ; region . lod . set ( lod ) ; network_link . region . set ( region ) ; KmlLink link = network_link . link . get ( ) ; string href = link . href . get ( ) ; link . href . set ( output_directory_ + " " + href ) ; network_link . link . set ( link ) ; Kml kml ; kml . AddNetworkLink ( network_link ) ; string kmlfile = output_directory_ + " " + root_kml_ ; FILE * fp = fopen ( root_kml_ . c_str ( ) , " " ) ; if ( ! fp ) { fprintf ( stderr , " \n \n " , root_kml_ . c_str ( ) ) ; exit ( EXIT_FAILURE ) ; } fprintf ( fp , " " , kml . ToString ( ) . c_str ( ) ) ; fclose ( fp ) ; }
Splits the image to be regionated into a set of lower resolution tiles.
Splits the image to be regionated into a set of lower resolution tiles .
// Create the output directory if it doesn't exist. // We pad the input image with transparency so that it is a multiple of the // tile size. // Recursively generate the tiles. // Write the root KML.  The root KML is special because its region should // always be visible, so we must alter the default region to always display. // The root KML lives above the subtile directory.