⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epr_band.c

📁 Insar图像处理软件
💻 C
📖 第 1 页 / 共 5 页
字号:
    EPR_ESampleModel band_smod;    uint rec_size;    uint rec_numb;    int iY, raster_pos, delta_raster_pos;    int offset_x_mirrored = 0;    ulong scan_line_length;    EPR_FLineDecoder decode_func;    uint scene_width;    product_id = band_id->product_id;    if (strncmp(EPR_ENVISAT_PRODUCT_MERIS, product_id->id_string, 3) == 0){        sph_record = product_id->sph_record;        field = epr_get_field(sph_record, "LINE_LENGTH");        scan_line_length = epr_get_field_elem_as_ulong(field, 0);    } else if (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) == 0){        scan_line_length = EPR_ATS_LINE_LENGTH;    } else if (strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 0){        scan_line_length = epr_get_scene_width(product_id);    } else {        epr_set_err(e_err_illegal_arg,                     "epr_read_band_measurement_data: scan line length unknown");        return epr_get_last_err_code();    }    dataset_id = band_id->dataset_ref.dataset_id;    /*the length of measurement record size*/    rec_size = dataset_id->dsd->dsr_size;    /*the number of measurement records*/    rec_numb = dataset_id->dsd->num_dsr;    /*data type in the band*/    band_datatype = band_id->data_type;    /*data model in the band*/    band_smod = band_id->sample_model;    record = epr_create_record(dataset_id);    field_info = (EPR_SFieldInfo*)epr_get_ptr_array_elem_at(record->info->field_infos, band_id->dataset_ref.field_index - 1);    datatype_id = field_info->data_type_id;    /* if the user raster (or part of) is outside bbox in source coordinates*/    if (offset_x + raster->raster_width > (int)scan_line_length) {        epr_set_err(e_err_illegal_arg,                     "epr_read_band_measurement_data: raster x co-ordinates out of bounds");        epr_free_record(record);        return epr_get_last_err_code();    }    if (offset_y + raster->raster_height > (int)(rec_numb)) {        epr_set_err(e_err_illegal_arg,                     "epr_read_band_measurement_data: raster y co-ordinates out of bounds");        epr_free_record(record);        return epr_get_last_err_code();    }    raster_pos = 0;    delta_raster_pos = (int)floor((raster->source_width - 1) / raster->source_step_x) + 1;    /*select the correspondent function to scaling and transform data type*/    decode_func = select_line_decode_function(band_datatype, band_smod, datatype_id);    if (decode_func == NULL){        epr_set_err(e_err_illegal_data_type,                     "epr_read_band_measurement_data: internal error: unknown data type");        epr_free_record(record);        return epr_get_last_err_code();    }    scene_width = band_id->product_id->scene_width;    if (band_id->lines_mirrored) {        offset_x_mirrored = (scene_width - 1) - (offset_x + raster->source_width - 1);    } else {        offset_x_mirrored = offset_x;    }    for (iY = offset_y; (uint)iY < offset_y + raster->source_height; iY += raster->source_step_y ) {                /*get the next record by the given name*/        record = epr_read_record(dataset_id, iY, record);        /*get the field at its number*/        field = epr_get_field_at(record, band_id->dataset_ref.field_index - 1);         /*get the scaled "line" of physical values*/        decode_func(field->elems, band_id, offset_x_mirrored, raster->source_width, raster->source_step_x, raster->buffer, raster_pos);        /*locate "data point" for the next "line"*/        raster_pos += delta_raster_pos;    }    if (band_id->lines_mirrored) {        if (band_datatype == e_tid_float){            mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);        } else if (band_datatype == e_tid_uchar){            mirror_uchar_array((uchar*)raster->buffer, raster->raster_width, raster->raster_height);        } else if (band_datatype == e_tid_ushort){            mirror_ushort_array((ushort*)raster->buffer, raster->raster_width, raster->raster_height);        } else if (band_datatype == e_tid_ulong){            mirror_ulong_array((ulong*)raster->buffer, raster->raster_width, raster->raster_height);        } else {            epr_set_err(e_err_illegal_data_type,                         "epr_read_band_measurement_data: internal error: unknown data type");            epr_free_record(record);            return epr_get_last_err_code();        }    }    epr_free_record(record);    return 0;}/** * Reads the annotation data and converts its into physical values. * * @param band_id the information about properties and quantities of ENVISAT data. * @param offset_x X-coordinate in pixel co-ordinates (zero-based) of the upper right corner raster to search * @param offset_y Y-coordinate in pixel co-ordinates (zero-based) of the upper right corner raster to search * @param raster the instance to the buffer information was used * * @return zero for success, an error code otherwise */int epr_read_band_annotation_data(EPR_SBandId* band_id,                        int offset_x,                        int offset_y,                        EPR_SRaster* raster){    EPR_SProductId* product_id = NULL;    const EPR_SField* field = NULL;    const EPR_SField* field_beg = NULL;    const EPR_SField* field_end = NULL;    EPR_SFieldInfo* field_info = NULL;    EPR_SDatasetId* dataset_id = NULL;    EPR_SRecord* record = NULL;    EPR_SRecord* record_beg = NULL;    EPR_SRecord* record_end = NULL;    EPR_SRecord* sph_record = NULL;    EPR_EDataTypeId band_datatype = 0, datatype_id = 0;    EPR_ESampleModel band_smod = 0;    uint rec_size = 0;    uint rec_numb = 0;    ulong lines_per_tie_pt, samples_per_tie_pt, scan_line_length;    int iY, raster_pos, delta_raster_pos;    EPR_FArrayTransformer transform_array_func = NULL;    int y_beg, y_end, y_beg_old, y_end_old;    int offset_x_mirrored = 0;    uint num_elems = 0;    float y_mod = 0;    float scan_offset_x = 0;    float scan_offset_y = 0;    void* line_beg_buffer = NULL;    void* line_end_buffer = NULL;    product_id = band_id->product_id;    dataset_id = band_id->dataset_ref.dataset_id;    /*the length of annotation record size*/    rec_size = dataset_id->dsd->dsr_size;    /*the number of annotation records*/    rec_numb = dataset_id->dsd->num_dsr;    /*data type in the band*/    band_datatype = band_id->data_type;    /*data model in the band*/    band_smod = band_id->sample_model;    record = epr_create_record(dataset_id);    field_info = (EPR_SFieldInfo*)epr_get_ptr_array_elem_at(record->info->field_infos, band_id->dataset_ref.field_index - 1);    datatype_id = field_info->data_type_id;    /*find LINES_PER_TIE_PT & SAMPLES_PER_TIE_PT for different products*/    if (strncmp(EPR_ENVISAT_PRODUCT_MERIS, product_id->id_string, 3) == 0){        /*elements number in the band (e.g.71)*/        scan_offset_x = 0.0F; /*!! was 0.5F !!*/        scan_offset_y = 0.0F; /*!! was 0.5F !!*/        num_elems = field_info->num_elems;        sph_record = product_id->sph_record;        field = epr_get_field(sph_record, "LINES_PER_TIE_PT");        lines_per_tie_pt = epr_get_field_elem_as_ulong(field, 0);        field = epr_get_field(sph_record, "SAMPLES_PER_TIE_PT");        samples_per_tie_pt = epr_get_field_elem_as_ulong(field, 0);        field = epr_get_field(sph_record, "LINE_LENGTH");        scan_line_length = epr_get_field_elem_as_ulong(field, 0);    } else if (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) == 0){        scan_offset_y = 0.5F;         scan_line_length = EPR_ATS_LINE_LENGTH;        lines_per_tie_pt = EPR_AATSR_LINES_PER_TIE_PT;        num_elems = field_info->num_elems;        if (num_elems == EPR_ATS_NUM_PER_POINT_ACROSS_LOCAT){            scan_offset_x = -19.0F;            samples_per_tie_pt = 25;        } else if (num_elems == EPR_ATS_NUM_PER_POINT_ACROSS_SOLAR){                scan_offset_x = 6.0F;                samples_per_tie_pt = 50;        } else {            epr_set_err(e_err_invalid_value, "epr_read_band_annotation_data: internal error: illegal value for samples_per_tie_pt");            epr_free_record(record);            return epr_get_last_err_code();        }    } else if (strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 0){        EPR_SDatasetId* dataset_id = NULL;        uint num_rec;		scan_offset_x = 0.5F; /* @todo CHECK THIS FOR ASAR! */        scan_offset_y = 0.5F;         scan_line_length = epr_get_scene_width(product_id);        samples_per_tie_pt = scan_line_length / (EPR_ASAR_NUM_PER_POINT_ACROSS_LOCAT - 1);        dataset_id = epr_get_dataset_id(product_id, "GEOLOCATION_GRID_ADS");        num_rec = epr_get_num_records(dataset_id);        lines_per_tie_pt = epr_get_scene_height(product_id) / (num_rec - 1);        num_elems = field_info->num_elems;    } else {        epr_set_err(e_err_illegal_arg,                     "epr_read_band_annotation_data: unhandled ENVISAT product type");        epr_free_record(record);        return epr_get_last_err_code();    }    /*memory allocate for the increasingly begin tie point line*/    line_beg_buffer = calloc(sizeof(float), num_elems);    if (line_beg_buffer == NULL) {        epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out of memory");        epr_free_record(record);        return epr_get_last_err_code();    }    /*memory allocate for the increasingly end tie point line*/    line_end_buffer = calloc(sizeof(float), num_elems);    if (line_end_buffer == NULL)  {        epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out of memory");        epr_free_record(record);        free(line_beg_buffer);        return epr_get_last_err_code();    }    /* if the user raster (or its part) is outside of orbit in source coordinates*/    if (offset_x + raster->raster_width > (int)scan_line_length) {        epr_set_err(e_err_illegal_arg,                     "epr_read_band_data: raster x co-ordinates out of bounds");        epr_free_record(record);        free(line_beg_buffer);        free(line_end_buffer);        return epr_get_last_err_code();    }    if (offset_y + raster->raster_height > (int)(rec_numb * lines_per_tie_pt)) {        epr_set_err(e_err_illegal_arg,                     "epr_read_band_data: raster y co-ordinates out of bounds");        epr_free_record(record);        free(line_beg_buffer);        free(line_end_buffer);        return epr_get_last_err_code();    }    raster_pos = 0;    delta_raster_pos = (int)floor((raster->source_width - 1) / raster->source_step_x) + 1;    /*select the correspondent function to scaling and transform data type*/    transform_array_func = select_transform_array_function(band_datatype, datatype_id);    if (transform_array_func == NULL){        epr_set_err(e_err_illegal_data_type,                     "epr_read_band_annotation_data: internal error: illegal data type");        epr_free_record(record);        free(line_beg_buffer);        free(line_end_buffer);        return epr_get_last_err_code();    }    y_beg_old = 9999;    y_end_old = 9999;    if (band_id->lines_mirrored) {        offset_x_mirrored = num_elems - (offset_x + raster->source_width - 1) - 1;    } else {        offset_x_mirrored = offset_x;    }    for (iY = offset_y; (uint)iY < offset_y + raster->source_height; iY += raster->source_step_y ) {            /*find the increasing neighbour begin and end tie point lines*/        y_mod = ((float)iY - scan_offset_y) / lines_per_tie_pt;		y_beg = (uint)floor(y_mod);		if (y_beg < 0) {			y_beg = 0;		}		if ((uint)y_beg > dataset_id->dsd->num_dsr - 2) {			y_beg = dataset_id->dsd->num_dsr - 2;		}        y_mod -= y_beg;        y_end = y_beg + 1;        /*as long as between increasing neighbour tie point lines, not to change them*/        if (y_beg_old != y_beg) {            record_beg = epr_read_record(dataset_id, y_beg, record_beg);            y_beg_old = y_beg;        }        if (y_end_old != y_end) {            record_end = epr_read_record(dataset_id, y_end, record_end);            y_end_old = y_end;        }        /*get the values for the increasing neighbour tie point lines*/        field_beg = epr_get_field_at(record_beg, band_id->dataset_ref.field_index - 1);         field_end = epr_get_field_at(record_end, band_id->dataset_ref.field_index - 1);        /*transform and scale the values for the increasing neighbour tie point lines*/        transform_array_func(field_beg->elems, band_id, line_beg_buffer, num_elems);        transform_array_func(field_end->elems, band_id, line_end_buffer, num_elems);        /*get the "line" of interpolated physical values from tie point data*/        decode_tiepoint_band(line_beg_buffer, line_end_buffer,                             samples_per_tie_pt, num_elems, band_id, offset_x, scan_offset_x, y_mod,                              raster->source_width, raster->source_step_x, raster->buffer, raster_pos);        /*locate "data point" for the next "line"*/        raster_pos += delta_raster_pos;    }    if (strncmp(EPR_ENVISAT_PRODUCT_MERIS, product_id->id_string, 3) == 0){        mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);    } else {        if (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) == 0){            mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);        } else {            if (strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 0                && strncmp(product_id->id_string, "ASA_IMG", 7) != 0                && strncmp(product_id->id_string, "ASA_APG", 7) != 0){                mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);            }        }    }    epr_free_record(record);    free(line_beg_buffer);    free(line_end_buffer);    return 0;}ulong epr_get_raster_width(EPR_SRaster* raster){    if (raster == NULL) {        epr_set_err(e_err_invalid_raster, "epr_get_raster_width: raster must not be NULL");        return 0;    }    return raster->raster_width;}ulong epr_get_raster_height(EPR_SRaster* raster){    if (raster == NULL) {        epr_set_err(e_err_invalid_raster, "epr_get_raster_height: raster must not be NULL");        return 0;    }    return raster->raster_height;}/******************************************************************/EPR_FLineDecoder select_line_decode_function(EPR_EDataTypeId band_daty,                                              EPR_ESampleModel band_smod,                                              EPR_EDataTypeId daty_id){    EPR_FLineDecoder decode_func;    if (band_daty == e_tid_uchar             && band_smod == e_smod_1OF2            && daty_id == e_tid_uchar)       decode_func = decode_line_uchar_1_of_2_to_uchar;    else if (band_daty == e_tid_uchar 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -