Skip to content

Commit

Permalink
add evenly intermediate points
Browse files Browse the repository at this point in the history
  • Loading branch information
arch committed Jun 27, 2022
1 parent 2b3a41d commit 35364e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions funscript_editor/algorithms/funscriptgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ def determine_change_points(self, metric: str) -> dict:
if self.params.additional_points == 'distance_minimization':
additional_points_algorithms.append(Signal.AdditionalPointAlgorithm.distance_minimization)

if self.params.additional_points == 'evenly_intermediate':
additional_points_algorithms.append(Signal.AdditionalPointAlgorithm.evenly_intermediate)

signal = Signal(self.video_info.fps)
decimate_indexes = signal.decimate(
self.score[metric],
Expand Down
28 changes: 28 additions & 0 deletions funscript_editor/algorithms/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AdditionalPointAlgorithm(enum.Enum):
""" Available additional point algorithms for the decimate process """
high_second_derivative = 1
distance_minimization = 2
evenly_intermediate = 3


@staticmethod
Expand Down Expand Up @@ -326,6 +327,31 @@ def get_edge_points(self, signal: list, base_points: list, threshold: float = 25
return edge_points


def get_evenly_intermediate_points(self, signal: list, base_points: list) -> list:
""" Get an aditional evenly intermediated point between 2 base points
Args:
signal (list): the predicted signal
base_points (list): current base points
Returns:
list: list with index of the evenly intermediated points (additional points)
"""
if len(base_points) < 2:
return []

base_points.sort()
additional_points = []
for i in range(len(base_points) - 1):
diff = base_points[i+1] - base_points[i]
if diff < 3:
continue

additional_points.append(base_points[i] + round(diff/2))

self.logger.info("Found {} evenly intermediate point candidates".format(len(additional_points)))
return additional_points


def get_local_min_max_points(self, signal: list, filter_len: int = 1) -> list:
""" Get the local max and min positions in given signal
Expand Down Expand Up @@ -579,6 +605,8 @@ def decimate(self,
additional_indexes = self.get_high_second_derivative_points(signal, alpha = self.params.high_second_derivative_points_threshold)
elif algo == self.AdditionalPointAlgorithm.distance_minimization:
additional_indexes = self.get_edge_points(signal, decimated_indexes, threshold = self.params.distance_minimization_threshold)
elif algo == self.AdditionalPointAlgorithm.evenly_intermediate:
additional_indexes = self.get_evenly_intermediate_points(signal, decimated_indexes)
else:
raise NotImplementedError("Selected Additional Points Algorithm is not implemented")

Expand Down
3 changes: 2 additions & 1 deletion funscript_editor/ui/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def __setup_combo_boxes(self):
self.ui.additionalPointsComboBox.addItems([
"None",
"High Second Derivative",
"Distance Minimization"
"Distance Minimization",
"Evenly intermediate"
])

self.ui.processingSpeedComboBox.addItems([
Expand Down

0 comments on commit 35364e8

Please sign in to comment.