Calculates a new offset after operations (transformations) to avoid an I32 overflow.
| 11318 | |
| 11319 | /// Calculates a new offset after operations (transformations) to avoid an I32 overflow. |
| 11320 | void LAStransform::adjust_offset(LASreader* lasreader, F64* scale_factor) |
| 11321 | { |
| 11322 | if (!operations || !lasreader) return; |
| 11323 | |
| 11324 | BOOL min_max_known = TRUE; |
| 11325 | F64* adj_offset = new F64[3]{0.0, 0.0, 0.0}; |
| 11326 | F64* transf_min = nullptr; |
| 11327 | F64* transf_max = nullptr; |
| 11328 | F64 transf_x_min = lasreader->get_min_x(); |
| 11329 | F64 transf_x_max = lasreader->get_max_x(); |
| 11330 | F64 transf_y_min = lasreader->get_min_y(); |
| 11331 | F64 transf_y_max = lasreader->get_max_y(); |
| 11332 | F64 transf_z_min = lasreader->get_min_z(); |
| 11333 | F64 transf_z_max = lasreader->get_max_z(); |
| 11334 | F64 adj_offset_x = 0.0; |
| 11335 | F64 adj_offset_y = 0.0; |
| 11336 | F64 adj_offset_z = 0.0; |
| 11337 | |
| 11338 | if (transf_x_min == transf_x_max || transf_y_min == transf_y_max || transf_z_min == transf_z_max) { |
| 11339 | min_max_known = FALSE; |
| 11340 | } |
| 11341 | |
| 11342 | for (U32 i = 0; i < num_operations; i++) |
| 11343 | { |
| 11344 | // setting the original offset and scaling factors |
| 11345 | if (i == 0) |
| 11346 | { |
| 11347 | operations[i]->set_origins(lasreader->header.x_offset, lasreader->header.y_offset, lasreader->header.z_offset, lasreader->header.x_scale_factor, |
| 11348 | lasreader->header.y_scale_factor, lasreader->header.z_scale_factor); |
| 11349 | } |
| 11350 | else if (adj_offset != nullptr && scale_factor != nullptr) |
| 11351 | { |
| 11352 | operations[i]->set_origins(adj_offset[0], adj_offset[1], adj_offset[2], scale_factor[0], scale_factor[1], scale_factor[2]); |
| 11353 | } |
| 11354 | else if (adj_offset != nullptr) |
| 11355 | { |
| 11356 | operations[i]->set_origins(adj_offset[0], adj_offset[1], adj_offset[2], lasreader->header.x_scale_factor, lasreader->header.y_scale_factor, |
| 11357 | lasreader->header.z_scale_factor); |
| 11358 | } |
| 11359 | |
| 11360 | //get min/max coordinate values after the operation (transformation) |
| 11361 | transf_min = operations[i]->transform_coords_for_offset_adjustment(transf_x_min, transf_y_min, transf_z_min); |
| 11362 | transf_max = operations[i]->transform_coords_for_offset_adjustment(transf_x_max, transf_y_max, transf_z_max); |
| 11363 | //calculate the adjusted offset after the operation (transformation) |
| 11364 | if (transf_min != 0 && transf_max != 0) |
| 11365 | { |
| 11366 | if (F64_IS_FINITE(transf_min[0]) && F64_IS_FINITE(transf_max[0])) |
| 11367 | adj_offset_x = ((I64)((transf_min[0] + transf_max[0]) / lasreader->header.x_scale_factor / 20000000)) * 10000000 * lasreader->header.x_scale_factor; |
| 11368 | else |
| 11369 | adj_offset_x = 0.0; |
| 11370 | |
| 11371 | if (F64_IS_FINITE(transf_min[1]) && F64_IS_FINITE(transf_max[1])) |
| 11372 | adj_offset_y = ((I64)((transf_min[1] + transf_max[1]) / lasreader->header.y_scale_factor / 20000000)) * 10000000 * lasreader->header.y_scale_factor; |
| 11373 | else |
| 11374 | adj_offset_y = 0.0; |
| 11375 | |
| 11376 | if (F64_IS_FINITE(transf_min[2]) && F64_IS_FINITE(transf_max[2])) |
| 11377 | adj_offset_z = ((I64)((transf_min[2] + transf_max[2]) / lasreader->header.z_scale_factor / 20000000)) * 10000000 * lasreader->header.z_scale_factor; |
no test coverage detected