Skip to content

Commit

Permalink
removed obsolete stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib committed Apr 5, 2024
1 parent 2ecf530 commit dcd875b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 104 deletions.
90 changes: 0 additions & 90 deletions openptv_python/correspondences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from .calibration import Calibration
from .constants import (
COORD_UNUSED,
CORRES_NONE,
MAX_TARGETS,
MAXCAND,
Expand All @@ -16,95 +15,6 @@
from .find_candidate import find_candidate
from .parameters import ControlPar, VolumePar
from .tracking_frame_buf import Frame, Target, n_tupel_dtype
from .trafo import dist_to_flat, pixel_to_metric


class MatchedCoords:
"""Keep a block of 2D flat coordinates.add().
each with a "point number", the same
as the number on one ``target`` from the block to which this block is kept
matched. This block is x-sorted.
NB: the data is not meant to be directly manipulated at this point. The
coord_2d arrays are most useful as intermediate objects created and
manipulated only by other liboptv functions. Although one can imagine a
use case for direct manipulation in Python, it is rare and supporting it
is a low priority.
"""

def __init__(self, targs, cpar, cal, tol=0.00001, reset_numbers=True):
"""Allocate and initialize the memory.add().
including coordinate conversion and sorting.
Arguments:
TargetArray targs - the TargetArray to be converted and matched.
ControlParams cpar - parameters of image size etc. for conversion.
Calibration cal - representation of the camera parameters to use in
the flat/distorted transforms.
double tol - optional tolerance for the lens distortion correction
phase, see ``optv.transforms``.
reset_numbers - if True (default) numbers the targets too, in their
current order. This shouldn't be necessary since all TargetArray
creators number the targets, but this gets around cases where they
don't.
"""
self._num_pts = len(targs)
self.buf = np.empty(self._num_pts,
dtype=np.dtype([('x', np.float64), ('y', np.float64), ('pnr', np.int32)]))

for tnum, targ in enumerate(targs):
targ = targs[tnum]
if reset_numbers:
targ.pnr = tnum

self.buf[tnum]['x'], self.buf[tnum]['y'] = pixel_to_metric(
targ.x, targ.y, cpar)

self.buf[tnum]['x'], self.buf[tnum]['y'] = dist_to_flat(
self.buf[tnum]['x'], self.buf[tnum]['y'], cal, tol
)
self.buf[tnum]['pnr'] = targ.pnr

self.buf.sort(order='x')

def as_arrays(self):
"""Return the matched coordinates as NumPy arrays.
Returns
-------
pos - (n,2) array, the (x,y) flat-coordinates position of n targets.
pnr - n-length array, the corresponding target number for each point.
"""
pos = np.empty((self._num_pts, 2))
pnr = np.empty(self._num_pts, dtype=np.int_)

for pt in range(self._num_pts):
pos[pt, 0] = self.buf[pt]['x']
pos[pt, 1] = self.buf[pt]['y']
pnr[pt] = self.buf[pt]['pnr']

return pos, pnr

def get_by_pnrs(self, pnrs):
"""Return the flat positions of points whose pnr property is given.
as an (n,2) flat position array. Assumes all pnrs are to be found, otherwise
there will be garbage at the end of the position array.
"""
pos = np.full((len(pnrs), 2), COORD_UNUSED, dtype=np.float64)
for pt in range(self._num_pts):
which = np.flatnonzero(self.buf[pt]['pnr'] == pnrs)
if len(which) > 0:
which = which[0]
pos[which, 0] = self.buf[pt]['x']
pos[which, 1] = self.buf[pt]['y']
return pos

def __del__(self):
del self.buf


Correspond_dtype = np.dtype([
('p1', np.int32), # PT_UNUSED
Expand Down
38 changes: 25 additions & 13 deletions openptv_python/multimed.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def fast_multimed_r_nlay(
y0: float,
z0: float,
pos: np.ndarray
) -> float:
) -> float:
"""Faster mutlimedia model calculation."""
n_iter = 40
X, Y, Z = pos
Expand All @@ -85,7 +85,8 @@ def fast_multimed_r_nlay(
beta2 = np.arcsin(np.sin(beta1) * n1 / n2[0])
beta3 = np.arcsin(np.sin(beta1) * n1 / n3)

rbeta = (z0 - d[0]) * np.tan(beta1) - zout * np.tan(beta3) + np.sum(d * np.tan(beta2))
rbeta = (z0 - d[0]) * np.tan(beta1) - zout * \
np.tan(beta3) + np.sum(d * np.tan(beta2))

rdiff = r - rbeta
rq += rdiff
Expand All @@ -106,7 +107,7 @@ def trans_cam_point(
pos_t, cross_p, cross_c = trans_cam_point(ex, mm, glass, pos, ex_t)
"""
origin = np.r_[ex.x0, ex.y0, ex.z0] # type: ignore
origin = np.r_[ex.x0, ex.y0, ex.z0] # type: ignore
pos = pos.astype(np.float64)

return fast_trans_cam_point(
Expand All @@ -119,7 +120,7 @@ def fast_trans_cam_point(
d: float,
glass_dir: np.ndarray,
pos: np.ndarray
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float]:
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float]:
"""Derive translation of camera point."""
dist_o_glass = float(np.linalg.norm(glass_dir)) # vector length
if dist_o_glass == 0.0:
Expand Down Expand Up @@ -174,8 +175,15 @@ def back_trans_point(
"""
return fast_back_trans_point(glass, mm.d[0], cross_c, cross_p, pos_t)


@njit(fastmath=True, cache=True, nogil=True)
def fast_back_trans_point(glass_direction: np.ndarray, d: float, cross_c, cross_p, pos_t) -> np.ndarray:
def fast_back_trans_point(
glass_direction: np.ndarray,
d: float,
cross_c: np.ndarray,
cross_p: np.ndarray,
pos_t: np.ndarray
) -> np.ndarray:
"""Run numba faster version of back projection."""
# Calculate the glass direction vector

Expand All @@ -199,12 +207,13 @@ def fast_back_trans_point(glass_direction: np.ndarray, d: float, cross_c, cross_

# If the norm of the vector temp is greater than zero, adjust the position
# of the point in the camera coordinate system
if norm_temp > 0.0: # type: ignore
if norm_temp > 0.0: # type: ignore
renorm_temp = temp * (-pos_t[0] / norm_temp)
pos = pos - renorm_temp

return pos


@njit(fastmath=True, cache=True, nogil=True)
def move_along_ray(glob_z: float, vertex: np.ndarray, direct: np.ndarray) -> np.ndarray:
"""Move along the ray to the global z plane.
Expand Down Expand Up @@ -252,7 +261,7 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
z_max_t = z_max

# intersect with image vertices rays
cal_t = Calibration(mmlut = cal.mmlut.copy())
cal_t = Calibration(mmlut=cal.mmlut.copy())

for i in range(2):
for j in range(2):
Expand All @@ -273,9 +282,9 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati

R = vec_norm(
np.r_[xyz_t[0] - cal_t.ext_par.x0,
xyz_t[1] - cal_t.ext_par.y0,
0]
)
xyz_t[1] - cal_t.ext_par.y0,
0]
)

if R > Rmax:
Rmax = R
Expand All @@ -291,7 +300,7 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
z_max_t = xyz_t[2]

R = vec_norm(np.r_[xyz_t[0] - cal_t.ext_par.x0,
xyz_t[1] - cal_t.ext_par.y0, 0])
xyz_t[1] - cal_t.ext_par.y0, 0])

if R > Rmax:
Rmax = R
Expand All @@ -317,8 +326,9 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
for i in range(nr):
for j in range(nz):
xyz = np.r_[Ri[i] + cal_t.ext_par.x0,
cal_t.ext_par.y0, Zi[j]]
cal.mmlut_data.flat[i * nz + j] = multimed_r_nlay(cal_t, cpar.mm, xyz)
cal_t.ext_par.y0, Zi[j]]
cal.mmlut_data.flat[i * nz +
j] = multimed_r_nlay(cal_t, cpar.mm, xyz)

# print(f"filled mmlut data with {data}")
# cal.mmlut_data = data
Expand All @@ -337,6 +347,8 @@ def get_mmf_from_mmlut(cal: Calibration, pos: np.ndarray) -> float:
return fast_get_mmf_from_mmlut(rw, origin, data, nz, nr, pos)

# @njit


def fast_get_mmf_from_mmlut(
rw: int,
origin: np.ndarray,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_corresp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.12.2"
},
"orig_nbformat": 4
},
Expand Down

0 comments on commit dcd875b

Please sign in to comment.