Skip to content

Commit

Permalink
working on framebuffer deque or list towards tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib committed Nov 11, 2023
1 parent 82f5235 commit 723e55d
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 280 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,5 @@ tags
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,vim,visualstudiocode,pycharm
tests/testing_fodder/track/img/*
tests/testing_fodder/track/res/*
16 changes: 8 additions & 8 deletions openptv_python/epi.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def epi_mm(xl, yl, cal1, cal2, mmp, vpar) -> tuple[float, float, float, float]:
pos, v = ray_tracing(xl, yl, cal1, mmp)

# calculate min and max depth for position (valid only for one setup)
z_min = vpar.z_min_lay[0] + (pos[0] - vpar.X_lay[0]) * (
z_min = vpar.z_min_lay[0] + (pos[0] - vpar.x_lay[0]) * (
vpar.z_min_lay[1] - vpar.z_min_lay[0]
) / (vpar.X_lay[1] - vpar.X_lay[0])
) / (vpar.x_lay[1] - vpar.x_lay[0])

z_max = vpar.z_max_lay[0] + (pos[0] - vpar.X_lay[0]) * (
z_max = vpar.z_max_lay[0] + (pos[0] - vpar.x_lay[0]) * (
vpar.z_max_lay[1] - vpar.z_max_lay[0]
) / (vpar.X_lay[1] - vpar.X_lay[0])
) / (vpar.x_lay[1] - vpar.x_lay[0])

X = move_along_ray(z_min, pos, v)
xmin, ymin = flat_image_coord(X, cal2, mmp)
Expand Down Expand Up @@ -152,12 +152,12 @@ def epi_mm_2D(
"""
pos, v = ray_tracing(xl, yl, cal1, mmp)

z_min = vpar.z_min_lay[0] + (pos[0] - vpar.X_lay[0]) * (
z_min = vpar.z_min_lay[0] + (pos[0] - vpar.x_lay[0]) * (
vpar.z_min_lay[1] - vpar.z_min_lay[0]
) / (vpar.X_lay[1] - vpar.X_lay[0])
z_max = vpar.z_max_lay[0] + (pos[0] - vpar.X_lay[0]) * (
) / (vpar.x_lay[1] - vpar.x_lay[0])
z_max = vpar.z_max_lay[0] + (pos[0] - vpar.x_lay[0]) * (
vpar.z_max_lay[1] - vpar.z_max_lay[0]
) / (vpar.X_lay[1] - vpar.X_lay[0])
) / (vpar.x_lay[1] - vpar.x_lay[0])

out = move_along_ray(0.5 * (z_min + z_max), pos, v)
return out
Expand Down
22 changes: 13 additions & 9 deletions openptv_python/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def compare_mm_np(mm_np1: MultimediaPar, mm_np2: MultimediaPar) -> bool:
class SequencePar:
"""Sequence parameters."""

num_cams: int = 0
num_cams: int = 1
img_base_name: List[str] | None = None
first: int | None = None
last: int | None = None
Expand All @@ -85,7 +85,7 @@ def set_img_base_name(self, icam, new_name):
if icam > self.num_cams:
raise ValueError("Length of names must be equal to num_cams.")
if self.img_base_name is None:
self.img_base_name = [None] * self.num_cams
self.img_base_name = [""] * self.num_cams

self.img_base_name[icam] = new_name

Expand Down Expand Up @@ -141,6 +141,8 @@ def compare_sequence_par(sp1: SequencePar, sp2: SequencePar) -> bool:

@dataclass
class TrackPar:
"""Tracking parameters."""

dacc: float = 0.0
dangle: float = 0.0
dvxmax: float = 0.0
Expand Down Expand Up @@ -175,7 +177,7 @@ def from_file(self, filename: str):
self.dvzmax = float(fpp.readline().rstrip())
self.add = int(fpp.readline().rstrip())
except IOError as exc:
raise (f"Error reading tracking parameters from {filename}") from exc
raise (f"Error reading tracking parameters from {filename}") from exc # type: ignore

def get_dvxmin(self):
"""Return the minimum velocity in x direction."""
Expand Down Expand Up @@ -248,7 +250,9 @@ def get_dny(self):

def read_track_par(filename: str) -> TrackPar:
"""Read tracking parameters from file and return TrackPar object."""
return TrackPar().from_file(filename)
tpar = TrackPar()
tpar.from_file(filename)
return tpar


def compare_track_par(t1: TrackPar, t2: TrackPar) -> bool:
Expand All @@ -262,10 +266,10 @@ class VolumePar:
/* Volume parameters */
fpp = fopen(filename, "r");
if(fscanf(fpp, &(ret->X_lay[0])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->x_lay[0])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->z_min_lay[0])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->z_max_lay[0])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->X_lay[1])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->x_lay[1])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->z_min_lay[1])) == 0) goto handle_error;
if(fscanf(fpp, &(ret->z_max_lay[1])) == 0) goto handle_error;
Expand All @@ -280,7 +284,7 @@ class VolumePar:
"""

X_lay: List[float] = field(default_factory=list)
x_lay: List[float] = field(default_factory=list)
z_min_lay: List[float] = field(default_factory=list)
z_max_lay: List[float] = field(default_factory=list)
# minimal criteria for number of pixels
Expand Down Expand Up @@ -330,10 +334,10 @@ def from_file(self, filename: str):
"""
with open(filename, "r", encoding="utf-8") as f:
self.X_lay.append(float(f.readline()))
self.x_lay.append(float(f.readline()))
self.z_min_lay.append(float(f.readline()))
self.z_max_lay.append(float(f.readline()))
self.X_lay.append(float(f.readline()))
self.x_lay.append(float(f.readline()))
self.z_min_lay.append(float(f.readline()))
self.z_max_lay.append(float(f.readline()))
self.cnx, self.cny, self.cn, self.csumg, self.corrmin, self.eps0 = [
Expand Down
52 changes: 29 additions & 23 deletions openptv_python/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class Foundpix:
"""A Foundpix object holds the parameters for a found pixel."""

ftnr: int = 0
ftnr: int = TR_UNUSED
freq: int = 0
whichcam: List[int] = field(default_factory=list)

Expand All @@ -60,19 +60,19 @@ class TrackingRun:
npart: int
nlinks: int

def __init__(self):
self.fb: FrameBuf = None # Replace with appropriate default value
self.seq_par: SequencePar = None # Replace with appropriate default value
self.tpar: TrackPar = None # Replace with appropriate default value
self.vpar: VolumePar = None # Replace with appropriate default value
self.cpar: ControlPar = None # Replace with appropriate default value
self.cal: List[Calibration] = [] # Initialize as an empty list
self.flatten_tol: float = 0.0 # Replace with appropriate default value
self.ymin: float = 0.0 # Replace with appropriate default value
self.ymax: float = 0.0 # Replace with appropriate default value
self.lmax: float = 0.0 # Replace with appropriate default value
self.npart: int = 0 # Replace with appropriate default value
self.nlinks: int = 0 # Replace with appropriate default value
# def __init__(self):
# self.fb: FrameBuf # Replace with appropriate default value
# self.seq_par: SequencePar # Replace with appropriate default value
# self.tpar: TrackPar # Replace with appropriate default value
# self.vpar: VolumePar # Replace with appropriate default value
# self.cpar: ControlPar # Replace with appropriate default value
# self.cal: List[Calibration] # Initialize as an empty list
# self.flatten_tol: float # Replace with appropriate default value
# self.ymin: float # Replace with appropriate default value
# self.ymax: float # Replace with appropriate default value
# self.lmax: float # Replace with appropriate default value
# self.npart: int # Replace with appropriate default value
# self.nlinks: int # Replace with appropriate default value


def tr_new_legacy(
Expand Down Expand Up @@ -149,6 +149,14 @@ def track_forward_start(tr: TrackingRun):
tr.fb.prev()


# def track_forward_start(tr):
# # Prime the buffer with first frames
# for step in range(tr.seq_par.first, tr.seq_par.first + TR_BUFSPACE - 1):
# fb_read_frame_at_end(tr.fb, step, 0)
# fb_next(tr.fb)
# fb_prev(tr.fb)


def reset_foundpix_array(arr: List[Foundpix], arr_len: int, num_cams: int) -> None:
"""Set default values for foundpix objects in an array.
Expand All @@ -167,6 +175,8 @@ def reset_foundpix_array(arr: List[Foundpix], arr_len: int, num_cams: int) -> No
for cam in range(num_cams):
arr[i].whichcam[cam] = 0

return None


def copy_foundpix_array(
dest: List[Foundpix], src: List[Foundpix], arr_len: int, num_cams: int
Expand Down Expand Up @@ -548,12 +558,8 @@ def searchquader(
return xr, xl, yd, yu


def sort_candidates_by_freq(item: Foundpix, num_cams: int):
def sort_candidates_by_freq(foundpix: List[Foundpix], num_cams: int) -> int:
"""Sort candidates by frequency."""
MAX_CANDS = 1000
foundpix = [Foundpix() for i in range(num_cams * MAX_CANDS)]
foundpix[: len(item)] = item

different = 0

# where what was found
Expand Down Expand Up @@ -929,8 +935,8 @@ def trackcorr_c_loop(run_info, step):

# volume check
if (
vpar.X_lay[0] < X[4][0]
and X[4][0] < vpar.X_lay[1]
vpar.x_lay[0] < X[4][0]
and X[4][0] < vpar.x_lay[1]
and run_info.ymin < X[4][1]
and X[4][1] < run_info.ymax
and vpar.z_min_lay[0] < X[4][2]
Expand Down Expand Up @@ -985,7 +991,7 @@ def trackcorr_c_loop(run_info, step):

# in volume check
if (
vpar.X_lay[0] < X[3][0] < vpar.X_lay[1]
vpar.x_lay[0] < X[3][0] < vpar.x_lay[1]
and run_info.ymin < X[3][1] < run_info.ymax
and vpar.z_min_lay[0] < X[3][2] < vpar.z_max_lay[1]
):
Expand Down Expand Up @@ -1178,7 +1184,7 @@ def trackback_c(run_info: TrackingRun):

# volume check
if (
vpar.X_lay[0] < X[3][0] < vpar.X_lay[1]
vpar.x_lay[0] < X[3][0] < vpar.x_lay[1]
and Ymin < X[3][1] < Ymax
and vpar.z_min_lay[0] < X[3][2] < vpar.z_max_lay[1]
):
Expand Down
Loading

0 comments on commit 723e55d

Please sign in to comment.