fix: the onepoint iterator should work

This commit is contained in:
alban 2023-02-25 15:29:37 +01:00
parent f67e7992ba
commit 80c76bfeb1
3 changed files with 66 additions and 76 deletions

View File

@ -1,6 +1,7 @@
import ast
import math
import struct
import sys
import time
import numpy as np
@ -93,57 +94,52 @@ class Status(object):
for l in lines:
print(prefix + l)
class OnePointIterator( ):
def __init__(self, ref):
self.ref = ref
def OnePointIterator(pl):
while True:
for indexpoint, currentpoint in enumerate(pl):
print("cp", indexpoint, currentpoint)
yield currentpoint[0], currentpoint[1], 255, 255, 255
continue
for indexpoint, currentpoint in enumerate(pl):
def __iter__(self):
return self
# We modify the point geometry according to warp settings
# print indexpoint, currentpoint
# xyc = [currentpoint[0], currentpoint[1], currentpoint[2]]
# ref.xyrgb = ref.get_warped_point(xyc)
x, y = ref.get_warped_point(currentpoint[0], currentpoint[1])
r, g, b = ref.int_to_rgb(currentpoint[2])
def __next__(self):
# We modify the point color based on channel specific r,g,b intensity settings
rgb = (round(r * ref.intred / 100), round(g * ref.intgreen / 100),
round(b * ref.intblue / 100))
while True:
# We compute the delta with previous position
delta_x, delta_y = x - ref.prev_x, y - ref.prev_y
# pdb.set_trace()
for indexpoint, currentpoint in enumerate(self.ref.pl):
# We compute the distance from previous postion
if math.hypot(delta_x, delta_y) < 4000:
# For glitch art : decrease lsteps
# l_steps = [ (1.0, 8)]
l_steps = gstt.stepshortline
else:
# For glitch art : decrease lsteps
# l_steps = [ (0.25, 3), (0.75, 3), (1.0, 10)]
l_steps = gstt.stepslongline
# We modify the point geometry according to warp settings
# print indexpoint, currentpoint
# xyc = [currentpoint[0], currentpoint[1], currentpoint[2]]
# self.ref.xyrgb = self.ref.get_warped_point(xyc)
x, y = self.ref.get_warped_point(currentpoint[0], currentpoint[1])
r, g, b = self.ref.int_to_rgb(currentpoint[2])
# We add intermediate points based on settings
for e in l_steps:
step = e[0]
# We modify the point color based on channel specific r,g,b intensity settings
rgb = (round(r * self.ref.intred / 100), round(g * self.ref.intgreen / 100),
round(b * self.ref.intblue / 100))
for i in range(0, e[1]):
ref.xyrgb_step = (ref.prev_x + step * delta_x,
ref.prev_y + step * delta_y) + rgb # + ref.xyrgb_prev[2:]# + rgb
# print(ref.xyrgb_step)
yield ref.xyrgb_step
# We compute the delta with previous position
delta_x, delta_y = x - self.ref.prev_x, y -self.ref.prev_y
ref.prev_x, ref.prev_y = x, y
ref.xyrgb_prev = [x, y]
# We compute the distance from previous postion
if math.hypot(delta_x, delta_y) < 4000:
# For glitch art : decrease lsteps
# l_steps = [ (1.0, 8)]
l_steps = gstt.stepshortline
else:
# For glitch art : decrease lsteps
# l_steps = [ (0.25, 3), (0.75, 3), (1.0, 10)]
l_steps = gstt.stepslongline
# We add intermediate points based on settings
for e in l_steps:
step = e[0]
for i in range(0, e[1]):
self.ref.xyrgb_step = (self.ref.prev_x + step * delta_x,
self.ref.prev_y + step * delta_y) + rgb # + self.ref.xyrgb_prev[2:]# + rgb
# print(self.ref.xyrgb_step)
yield self.ref.xyrgb_step
self.ref.prev_x, self.ref.prev_y = x, y
self.ref.xyrgb_prev = [x, y]
class Tracer(object):
"""A connection to a DAC."""
@ -152,6 +148,8 @@ class Tracer(object):
point_list_number: list
pl: list
client_key: str # /pl/<laser_id> by default
prev_x = 0
prev_y = 0
black_points = [(278.0, 225.0, 0), (562.0, 279.0, 0), (401.0, 375.0, 0), (296.0, 454.0, 0), (298.0, 165.0, 0)]
grid_points = [(300.0, 200.0, 0), (500.0, 200.0, 65280), (500.0, 400.0, 65280), (300.0, 400.0, 65280),
@ -177,7 +175,7 @@ class Tracer(object):
def set_status(self, status: int):
raise Exception("Please override the method")
def get_warped_point(self, x, y ):
def get_warped_point(self, x, y):
"""
A DAC specific point model, ex EtherPoint or HeliosPoint
:param xyc: x,y,color
@ -191,9 +189,6 @@ class Tracer(object):
# def set_ack_status(self, ack_status: int):
# raise Exception("Please override the method")
def prepare(self):
raise Exception("Please override the method")
@ -254,6 +249,8 @@ class Tracer(object):
# @todo si la clef est vide utiliser les points noirs ? -> syntax error -> black points.
try:
self.pl = ast.literal_eval(self.redis.get(self.clientkey + str(self.laser_id)).decode('ascii'))
# print(self.clientkey + str(self.laser_id))
# print(self.pl)
except SyntaxError:
print("BAD POINTLIST on Tracer : laser", self.laser_id, " order 0 : pl : ", self.pl)
@ -284,7 +281,8 @@ class Tracer(object):
if order == 4:
""" 4: Resampler Change, modify the automatic intermediary points settings """
self.resampler = ast.literal_eval(self.redis.get('/resampler/' + str(self.laser_id)).decode('ascii'))
self.resampler = ast.literal_eval(
self.redis.get('/resampler/' + str(self.laser_id)).decode('ascii'))
print("Tracer", self.laser_id, " : resetting lsteps for", self.resampler)
gstt.stepshortline = self.resampler[0]
gstt.stepslongline[0] = self.resampler[1]
@ -329,8 +327,9 @@ class Tracer(object):
# pdb.set_trace()
# How much room?
capacity = self.get_points_capacity()
iterator = iter(OnePointIterator(self.pl))
self.redis.set('/cap/' + str(self.laser_id), capacity)
iterator = OnePointIterator(self)
points = [next(iterator) for i in range(capacity)]
self.write(points)
if not started:

View File

@ -33,7 +33,7 @@ class TracerHelios(Tracer):
self.redis = redis
self.laser_id = laser_id
self.PL = PL
self.pl = [[0, 0, 0]]
self.pl = [[0,0,0]]
self.clientkey = self.redis.get("/clientkey").decode('ascii')
self.xyrgb = self.xyrgb_prev = (0, 0, 0, 0, 0)
self.intensity = 65280
@ -50,7 +50,7 @@ class TracerHelios(Tracer):
pass
def get_points_capacity(self):
return 1000
return 10
# def GetPoints(self, capacity):
# a = [2,3]
@ -92,16 +92,7 @@ class TracerHelios(Tracer):
# print("hello got {} points".format(len(points)))
points = [point for point in points]
for i, point in enumerate(points):
a = 0
# @todo why are there 2 tuples in the object ???
for one_point in point:
x, y, r, g, b = one_point
# x = random.randrange(1500,2500)
# y = random.randrange(1500,2500)
# r = 255
# g = 255
# b = 255
break
x, y, r, g, b = point
print(x,y,r,g,b)
frame[i] = HeliosPoint(int(x), int(y), int(r), int(g), int(b), 255)
statusAttempts = 0

32
main.py
View File

@ -80,28 +80,28 @@ def dac_process(number, pl, dac_family):
from libs3 import gstt
print("Starting dac process", number)
try:
d = tracer.DAC(number, pl, dac_family=dac_family)
while True:
try:
d = tracer.DAC(number, pl, dac_family=dac_family)
while True:
d.play_stream()
except Exception as e:
except Exception as e:
import sys
import traceback
import sys
import traceback
if gstt.debug > 0:
# if True:
log.err('\n---------------------')
log.err('Exception: %s' % e)
log.err('- - - - - - - - - - -')
traceback.print_tb(sys.exc_info()[2])
print("\n")
pass
if gstt.debug > 0:
# if True:
log.err('\n---------------------')
log.err('Exception: %s' % e)
log.err('- - - - - - - - - - -')
traceback.print_tb(sys.exc_info()[2])
print("\n")
pass
except KeyboardInterrupt:
sys.exit(0)
except KeyboardInterrupt:
sys.exit(0)
#