A segment artist's best hit: on the segments drawn (as drawn: relative ends included; a segment of no length isn't drawn).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(SegmentArtist), | intent(in), | target | :: | a |
the artist |
|
| class(ReferenceFrame), | intent(in), | target | :: | frame |
the frame drawing it (for the hit) |
|
| type(PickCamera), | intent(in) | :: | cam |
the pick camera |
||
| real(kind=wp), | intent(in) | :: | m(4,4) |
the frame's transform to the root frame |
||
| type(PickHit), | intent(inout), | allocatable | :: | hits(:) |
hits are added to hits(1:n) |
|
| integer, | intent(inout) | :: | n |
number of hits |
subroutine segment_artist_pick(a, frame, cam, m, hits, n) class(SegmentArtist), intent(in), target :: a !! the artist class(ReferenceFrame), intent(in), target :: frame !! the frame drawing it (for the hit) type(PickCamera), intent(in) :: cam !! the pick camera real(wp), intent(in) :: m(4,4) !! the frame's transform to the root frame type(PickHit), allocatable, intent(inout) :: hits(:) !! hits are added to hits(1:n) integer, intent(inout) :: n !! number of hits real(wp) :: extra, a0(3), b0(3), px, s, depth, best_px, best_depth, best_s integer :: k, best_k type(PickHit) :: h if (.not. associated(a%traj) .or. a%n_drawn < 1) return extra = 0.5_wp * a%width_ * cam%pixel_ratio best_px = huge(1.0_wp) best_depth = huge(1.0_wp) best_k = 0 best_s = 0.0_wp do k = a%first_drawn_, a%first_drawn_ + a%n_drawn - 1 call a%drawn_segment(k, a0, b0) if (all(a0 == b0)) cycle if (segment_pick(cam, matmul(m(1:3, 1:3), a0) + m(1:3, 4), matmul(m(1:3, 1:3), b0) + m(1:3, 4), & px, s, depth, extra)) then if (better(px, depth, best_px, best_depth)) then best_px = px best_depth = depth best_k = k best_s = s end if end if end do if (best_k == 0) return call a%drawn_segment(best_k, a0, b0) h%kind = PICK_SEGMENT h%frame => frame h%artist => a h%trajectory => a%traj h%index = best_k h%time = a%traj%time(min(a%traj%num_times(), 1 + (best_k - 1) * a%stride_)) h%local = a0 + best_s * (b0 - a0) h%position = matmul(m(1:3, 1:3), h%local) + m(1:3, 4) h%distance = best_depth h%pixels = best_px call add_pick_hit(hits, n, h) end subroutine segment_artist_pick