void update_poly_extents(meta_parameters *meta) { int size_x, size_y; compute_extent(meta, &g_poly->extent_y_min, &g_poly->extent_y_max, &g_poly->extent_x_min, &g_poly->extent_x_max, &size_y, &size_x); char subset_info[128]; snprintf(subset_info, 128, "Extent: Line %d-%d, Sample %d-%d\nOutput will be %dx%d LxS", g_poly->extent_y_min, g_poly->extent_y_max, g_poly->extent_x_min, g_poly->extent_x_max, size_y, size_x); put_string_to_label("subset_info_label", subset_info); }
buffered_points_ren_t ( bufobj_ptr_t ver_buf, bufobj_ptr_t idx_buf, bufobj_ptr_t col_buf) { m_ver_bo = ver_buf; m_col_bo = col_buf; m_idx_bo = idx_buf; if ( m_ver_bo->id() == 0 && m_ver_bo->src_ptr() == NULL ) { throw std::invalid_argument ( "no vertex data specified neither in cpu nor gpu" ); } enum e_render_func {DIRECT_WOC,DIRECT_WC,INDEXED_WOC,INDEXED_WC}; e_render_func render_func_type = (e_render_func) ( (( m_col_bo->id() == 0 && m_col_bo->src_ptr() == NULL )?(0):(1) )| (( m_idx_bo->id() == 0 && m_idx_bo->src_ptr() == NULL )?(0):(2))); switch(render_func_type) { case DIRECT_WOC: render_func = &buffered_points_ren_t::render_without_color_dir; m_num_points = m_ver_bo->get_num_items();break; case DIRECT_WC: render_func = &buffered_points_ren_t::render_with_color_dir; m_num_points = m_ver_bo->get_num_items();break; case INDEXED_WOC: render_func = &buffered_points_ren_t::render_without_color_idx; m_num_points = m_idx_bo->get_num_items();break; case INDEXED_WC: render_func = &buffered_points_ren_t::render_with_color_idx; m_num_points = m_idx_bo->get_num_items();break; default: throw std::logic_error("renderfunc type undetermined"); } compute_extent ( m_ver_bo, m_extent ); }
static int save_as_csv(ImageInfo *ii, const char *out_file, int what_to_save, int strict_boundary, int load) { int i,j; assert (g_poly->n > 0); assert (crosshair_line > 0 && crosshair_samp > 0); meta_parameters *meta = ii->meta; int line_min, line_max, samp_min, samp_max, nl, ns; compute_extent(meta, &line_min, &line_max, &samp_min, &samp_max, &nl, &ns); if (nl>500 || ns>500) { // too big for csv -- Excel etc. will choke char errbuf[1024]; snprintf(errbuf, 1024, "\nRegion is too large (%dx%d) to export as CSV (500x500 max)\n\n", nl, ns); message_box(errbuf); printf("%s", errbuf); return FALSE; // failure } FILE *outFp = fopen(out_file, "w"); if (!outFp) { // failed to open the output file! char errbuf[1024]; snprintf(errbuf, 1024, "Failed to open %s: %s", out_file, strerror(errno)); message_box(errbuf); strcat(errbuf, "\n"); printf("%s", errbuf); return FALSE; // failure } printf("Generating %s...\n", out_file); // define clipping region, if necessary double xp[MAX_POLY_LEN+2], yp[MAX_POLY_LEN+2]; int n=0; if (strict_boundary) define_clipping_region(meta, &n, xp, yp); // generate csv fprintf(outFp, ","); for (j=0; j<ns; ++j) { if (what_to_save==LAT_LON_2_BAND) fprintf(outFp, "%d,%s", samp_min+j, j==ns-1 ? "\n" : ","); else fprintf(outFp, "%d%s", samp_min+j, j==ns-1 ? "\n" : ","); } if (what_to_save==LAT_LON_2_BAND) { fprintf(outFp, ","); for (j=0; j<ns; ++j) { fprintf(outFp, "Lat,Lon%s", j==ns-1 ? "\n" : ","); } } for (i=0; i<nl; ++i) { int l = line_min+i; fprintf(outFp, "%d,", l); for (j=0; j<ns; ++j) { int s = samp_min+j; if (what_to_save==LAT_LON_2_BAND) { float lat, lon; if (!strict_boundary || pnpoly(n, xp, yp, s, l)) { double dlat, dlon; meta_get_latLon(meta, l, s, 0, &dlat, &dlon); lat = (float)dlat; lon = (float)dlon; } else { lat = lon = 0.; } fprintf(outFp, "%f,%f%s", lat, lon, j==ns-1 ? "\n" : ","); } else { float val; if (!strict_boundary || pnpoly(n, xp, yp, s, l)) { val = get_data(ii, what_to_save, l, s); } else { val = 0; } fprintf(outFp, "%f%s", val, j==ns-1 ? "\n" : ","); } } asfLineMeter(i,nl); } fclose(outFp); // if requested, open up the csv with an external viewer if (load) open_csv(out_file); return TRUE; }
static int save_as_asf(ImageInfo *ii, const char *out_file, int what_to_save, int strict_boundary, int load) { // See if we can open the output file up front FILE *outFp = fopen(out_file, "wb"); if (!outFp) { // failed to open the output file! char errbuf[1024]; snprintf(errbuf, 1024, "Failed to open %s: %s", out_file, strerror(errno)); message_box(errbuf); strcat(errbuf, "\n"); printf("%s", errbuf); return FALSE; // failure } assert (g_poly->n > 0); assert (crosshair_line > 0 && crosshair_samp > 0); meta_parameters *meta = ii->meta; // figure out where to chop int line_min, line_max, samp_min, samp_max, nl, ns; compute_extent(meta, &line_min, &line_max, &samp_min, &samp_max, &nl, &ns); // generate metadata char *out_metaname = appendExt(out_file, ".meta"); printf("Generating %s...\n", out_metaname); // data will be saved as floating point, except scaled pixel values, // which we can make bytes. data_type_t data_type = REAL32; if (what_to_save == SCALED_PIXEL_VALUE) data_type = ASF_BYTE; meta_parameters *out_meta = build_metadata(meta, out_file, nl, ns, line_min, samp_min, data_type, what_to_save); // put_float_line() will always dump BYTE data if the optical block // is present... we want to be in control of the data type, so we must // wipe out this block if (out_meta->optical) { FREE(out_meta->optical); out_meta->optical=NULL; } if (what_to_save == LAT_LON_2_BAND) { out_meta->general->band_count = 2; strcpy(out_meta->general->bands, "LAT,LON"); } // define clipping region, if necessary double xp[MAX_POLY_LEN+2], yp[MAX_POLY_LEN+2]; int i,j,n=0; if (strict_boundary) define_clipping_region(meta, &n, xp, yp); float ndv = 0; if (meta_is_valid_double(out_meta->general->no_data)) ndv = out_meta->general->no_data; else if (strict_boundary) // need to set a no data value in this case out_meta->general->no_data = 0.; meta_write(out_meta, out_metaname); // now actually write the data printf("Generating %s...\n", out_file); if (what_to_save == LAT_LON_2_BAND) { // dump a 2-band image, lat & lon data float *lats = MALLOC(sizeof(float)*ns); float *lons = MALLOC(sizeof(float)*ns); for (i=0; i<nl; ++i) { int l = line_min+i; for (j=0; j<ns; ++j) { int s = samp_min+j; if (!strict_boundary || pnpoly(n, xp, yp, s, l)) { double lat, lon; meta_get_latLon(meta, l, s, 0, &lat, &lon); lats[j] = (float)lat; lons[j] = (float)lon; } else { lats[j] = ndv; lons[j] = ndv; } } put_band_float_line(outFp, out_meta, 0, i, lats); put_band_float_line(outFp, out_meta, 1, i, lons); asfLineMeter(i,nl); } free(lats); free(lons); } else { // normal case float *buf = MALLOC(sizeof(float)*ns); for (i=0; i<nl; ++i) { int l = line_min+i; for (j=0; j<ns; ++j) { int s = samp_min+j; float val; if (!strict_boundary || pnpoly(n, xp, yp, s, l)) { val = get_data(ii, what_to_save, l, s); } else { val = ndv; } buf[j] = val; } put_float_line(outFp, out_meta, i, buf); asfLineMeter(i,nl); } free(buf); } fclose(outFp); meta_free(out_meta); // load the generated file if we were told to if (load) load_file(out_file); return TRUE; }