Merge pull request #3643 from vkip/avoid_zero_conndepth

Avoid connection depth = 0 when segment is specified without depth in COMPSEGS
This commit is contained in:
Kai Bao 2023-08-23 23:53:19 +02:00 committed by GitHub
commit b4c30cf93b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,12 +126,12 @@ struct Record {
const double depth_change_segment = segment_depth - interpolation_detph; const double depth_change_segment = segment_depth - interpolation_detph;
const double segment_length = segment_distance - interpolation_distance; const double segment_length = segment_distance - interpolation_distance;
// Use segment depth if length of sement is 0
if (segment_length == 0.) { if (segment_length == 0.) {
throw std::runtime_error("Zero segment length is botained when doing interpolation between segment " center_depth = segment_depth;
+ std::to_string(segment_number) + " and segment " + std::to_string(interpolation_segment_number) ); } else {
center_depth = segment_depth + (center_distance - segment_distance) / segment_length * depth_change_segment;
} }
center_depth = segment_depth + (center_distance - segment_distance) / segment_length * depth_change_segment;
} }
@ -143,35 +143,37 @@ namespace {
// while the depth information is defaulted though, which need to be obtained from the related segment // while the depth information is defaulted though, which need to be obtained from the related segment
for( auto& compseg : compsegs ) { for( auto& compseg : compsegs ) {
// need to determine the related segment number first // need to determine the related segment number first, if not defined
if (compseg.segment_number != 0) continue; if (compseg.segment_number == 0) {
const double center_distance = (compseg.m_distance_start + compseg.m_distance_end) / 2.0; const double center_distance = (compseg.m_distance_start + compseg.m_distance_end) / 2.0;
const int branch_number = compseg.m_branch_number; const int branch_number = compseg.m_branch_number;
int segment_number = 0; int segment_number = 0;
double min_distance_difference = 1.e100; // begin with a big value double min_distance_difference = 1.e100; // begin with a big value
for (std::size_t i_segment = 0; i_segment < segment_set.size(); ++i_segment) { for (std::size_t i_segment = 0; i_segment < segment_set.size(); ++i_segment) {
const Segment& current_segment = segment_set[i_segment]; const Segment& current_segment = segment_set[i_segment];
if( branch_number != current_segment.branchNumber() ) continue; if( branch_number != current_segment.branchNumber() ) continue;
const double distance = current_segment.totalLength(); const double distance = current_segment.totalLength();
const double distance_difference = std::abs(center_distance - distance); const double distance_difference = std::abs(center_distance - distance);
if (distance_difference < min_distance_difference) { if (distance_difference < min_distance_difference) {
min_distance_difference = distance_difference; min_distance_difference = distance_difference;
segment_number = current_segment.segmentNumber(); segment_number = current_segment.segmentNumber();
}
} }
}
if (segment_number == 0) { if (segment_number == 0) {
const std::string msg = const std::string msg =
fmt::format("The connection specified in COMPSEGS with index of " fmt::format("The connection specified in COMPSEGS with index of "
"{} {} {} failed in finding a related segment", "{} {} {} failed in finding a related segment",
compseg.m_i + 1, compseg.m_j + 1, compseg.m_k + 1); compseg.m_i + 1, compseg.m_j + 1, compseg.m_k + 1);
throw std::runtime_error(msg); throw std::runtime_error(msg);
} }
compseg.segment_number = segment_number; compseg.segment_number = segment_number;
}
// when depth is default or zero, we obtain the depth of the connection based on the information // when depth is default or zero, we obtain the depth of the connection based on the information
// of the related segments // of the related segments