Skip to content

Commit e15722e

Browse files
committed
Trying to clean up github
1 parent 817f85e commit e15722e

5 files changed

+164
-5
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
4+
# Made files
5+
.vscode
6+
7+
# data
8+
/Image_based/data/forcindy/CalculatedData/
9+
/Image_based/data/forcindy/DebugImages/

list_read_write.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_class_member(self, l_str):
7373
ret_list = {}
7474
elif type_check == "ndarray":
7575
dim_two = int(check_type[2])
76-
if dim_two is 0:
76+
if dim_two == 0:
7777
ret_list = array([0 for _ in range(0, n_read)])
7878
else:
7979
ret_list = zeros([n_read, dim_two])

sketch_curves_gui/Draw_spline_3D.py

+62-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
import os
12
import sys
3+
sys.path.insert(0, os.path.abspath('./'))
4+
sys.path.insert(0, os.path.abspath('../'))
5+
sys.path.insert(0, os.path.abspath('../Image_based'))
26

37
from PyQt5.QtCore import pyqtSignal, QPoint, QSize, Qt
48
from PyQt5.QtWidgets import (QApplication, QHBoxLayout, QOpenGLWidget, QSlider,
59
QWidget)
6-
10+
from PyQt5.QtGui import QPainter, QBrush, QPen, QFont, QColor
711
import OpenGL.GL as GL
812
import cv2
913
from ctypes import c_uint8
1014

1115
from bezier_cyl_3d_with_detail import BezierCyl3DWithDetail
1216
import numpy as np
1317

18+
from SketchesForCurves import SketchesForCurves
19+
1420

1521
class DrawSpline3D(QOpenGLWidget):
1622
upDownRotationChanged = pyqtSignal(int)
@@ -36,6 +42,7 @@ def __init__(self, gui, parent=None):
3642
self.gui = gui
3743
self.crvs = []
3844

45+
self.firstPos = QPoint()
3946
self.lastPos = QPoint()
4047

4148
self.show = True
@@ -44,6 +51,8 @@ def __init__(self, gui, parent=None):
4451
self.aspect_ratio = 1.0
4552
self.im_size = (0, 0)
4653

54+
self.sketch_curve = SketchesForCurves()
55+
4756
@staticmethod
4857
def get_opengl_info():
4958
info = """
@@ -379,6 +388,35 @@ def draw_crv_2d(self):
379388
GL.glMatrixMode(GL.GL_PROJECTION)
380389
GL.glPopMatrix()
381390

391+
def draw_sketch(self):
392+
""" The marks the user made"""
393+
if not self.gui or not self.gui.crv:
394+
return
395+
qp = QPainter()
396+
qp.begin(self)
397+
pen_backbone = QPen(Qt.yellow, 3, Qt.SolidLine)
398+
pen_cross = QPen(Qt.blue, 4, Qt.SolidLine)
399+
brush = QBrush(Qt.CrossPattern)
400+
qp.setPen(pen_backbone)
401+
qp.setBrush(brush)
402+
for pt in self.sketch_curve.backbone_pts:
403+
qp.drawLine(int(pt[0] - 5), int(pt[1]), int(pt[0] + 5), int(pt[1]))
404+
qp.drawLine(int(pt[0]), int(pt[1] - 5), int(pt[0]), int(pt[1] + 5))
405+
406+
for pt1, pt2 in zip(self.sketch_curve.backbone_pts[0:-1], self.sketch_curve.backbone_pts[1:]):
407+
qp.drawLine(int(pt1[0]), int(pt1[1]), int(pt2[0]), int(pt2[1]))
408+
409+
qp.setPen(pen_cross)
410+
for pts in self.sketch_curve.cross_bars:
411+
for pt in pts:
412+
qp.drawLine(int(pt[0] - 3), int(pt[1]), int(pt[0] + 3), int(pt[1]))
413+
qp.drawLine(int(pt[0]), int(pt[1] - 3), int(pt[0]), int(pt[1] + 3))
414+
if len(pts) > 1:
415+
pt1 = pts[0]
416+
pt2 = pts[1]
417+
qp.drawLine(int(pt1[0]), int(pt1[1]), int(pt2[0]), int(pt2[1]))
418+
qp.end()
419+
382420
def paintGL(self):
383421
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
384422

@@ -402,6 +440,8 @@ def paintGL(self):
402440
if self.show and self.crv_gl_list is not None:
403441
GL.glCallList(self.crv_gl_list)
404442

443+
self.draw_sketch()
444+
405445
@staticmethod
406446
def resizeGL(width, height):
407447
side = min(width, height)
@@ -418,6 +458,7 @@ def resizeGL(width, height):
418458
DrawSpline3D.gl_inited= True
419459

420460
def mousePressEvent(self, event):
461+
self.firstPos = event.pos()
421462
self.lastPos = event.pos()
422463

423464
def mouseMoveEvent(self, event):
@@ -430,6 +471,26 @@ def mouseMoveEvent(self, event):
430471

431472
self.lastPos = event.pos()
432473

474+
def mouseReleaseEvent(self, event):
475+
"""Either add a point to the backbone or a point to the crossbar
476+
Shift: Add a cross bar
477+
Cntr: Remove a point"""
478+
dx = event.x() - self.firstPos.x()
479+
dy = event.y() - self.firstPos.y()
480+
# Not a click
481+
if abs(dx) + abs(dy) > 5:
482+
print(f"Big {dx} {dy}")
483+
return
484+
485+
if event.modifiers() == Qt.ShiftModifier:
486+
self.sketch_curve.add_crossbar_point(event.x(), event.y())
487+
elif event.modifiers() == Qt.ControlModifier:
488+
self.sketch_curve.remove_point(event.x(), event.y())
489+
else:
490+
self.sketch_curve.add_backbone_point(event.x(), event.y())
491+
492+
self.update()
493+
433494
def make_crv_gl_list(self):
434495
if not DrawSpline3D.gl_inited:
435496
return

sketch_curves_gui/Sketch_curves_main_window.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import os
1010
import sys
11+
sys.path.insert(0, os.path.abspath('./'))
12+
sys.path.insert(0, os.path.abspath('./Image_based'))
13+
sys.path.insert(0, os.path.abspath('./sketch_curves_gui'))
1114
sys.path.insert(0, os.path.abspath('../'))
1215
sys.path.insert(0, os.path.abspath('../Image_based'))
1316
from os.path import exists
@@ -51,7 +54,6 @@ def __init__(self):
5154
self.in_reset_file_menus = False
5255
self.in_read_images = False
5356

54-
5557
# Set up the left set of sliders/buttons (read/write, camera)
5658
def _init_left_layout_(self):
5759
# For reading and writing
@@ -418,14 +420,12 @@ def read_images(self):
418420
self.redraw_self()
419421
self.in_read_images = False
420422

421-
422423
def redraw_self(self):
423424
self.glWidget.update()
424425
self.repaint()
425426

426427

427428
if __name__ == '__main__':
428-
429429
app = QApplication([])
430430

431431
gui = SketchCurvesMainWindow()
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
3+
import math as math
4+
5+
6+
# Keep all of the sketching data until it is time to actually make a spline curve
7+
# There's the curve backbone (2 o4 more points)
8+
# Plus 1 (or more) perpendicular cross bars to indicate width
9+
#
10+
# Regular clicking makes more backbone points (needs to bee in order)
11+
# Shift click does a left-right pair across the backbone
12+
# Cntrl clicking over a point erases it
13+
# Keep all points in width/height - convert at the end
14+
15+
class SketchesForCurves:
16+
def __init__(self):
17+
""" Nothing in it to start"""
18+
self.backbone_pts = []
19+
self.cross_bars = []
20+
21+
def add_backbone_point(self, x, y):
22+
""" Add the x,y point to the backbone
23+
@param x
24+
@param y
25+
"""
26+
self.backbone_pts.append([x, y])
27+
28+
def add_crossbar_point(self, x, y):
29+
""" Add the x,y point to the crossbar
30+
@param x
31+
@param y
32+
"""
33+
if self.cross_bars == []:
34+
self.cross_bars.append([[x, y]])
35+
elif len(self.cross_bars[-1]) == 1:
36+
self.cross_bars[-1].append([x, y])
37+
else:
38+
self.cross_bars.append([[x, y]])
39+
40+
def remove_point(self, x, y, eps=5):
41+
""" Remove either a backbone point or a cross bar point
42+
@param x
43+
@param y
44+
"""
45+
d_closest = 1e30
46+
i_closest = -1
47+
for i, pt in enumerate(self.backbone_pts):
48+
d_dist = math.fabs(pt[0] - x) + math.fabs(pt[1] - y)
49+
if d_dist < d_closest:
50+
d_closest = d_dist
51+
i_closest = i
52+
53+
d_closest_cross = 1e30
54+
i_closest_cross = -1
55+
for i, pts in enumerate(self.cross_bars):
56+
for pt in pts:
57+
d_dist = math.fabs(pt[0] - x) + math.fabs(pt[1] - y)
58+
if d_dist < d_closest_cross:
59+
d_closest_cross = d_dist
60+
i_closest_cross = i
61+
62+
if i_closest == -1 and i_closest_cross == -1:
63+
return
64+
65+
if d_closest > eps and d_closest_cross > eps:
66+
return
67+
68+
if d_closest < d_closest_cross:
69+
self.backbone_pts.pop(i_closest)
70+
else:
71+
self.cross_bars.pop(i_closest_cross)
72+
73+
74+
if __name__ == '__main__':
75+
sk = SketchesForCurves()
76+
sk.add_backbone_point(10, 10)
77+
sk.add_backbone_point(100, 20)
78+
sk.add_backbone_point(200, 30)
79+
sk.add_crossbar_point(-5, 10)
80+
sk.add_crossbar_point(25, 10)
81+
sk.add_crossbar_point(85, 30)
82+
sk.add_crossbar_point(120, 10)
83+
sk.remove_point(10, 10, 2)
84+
sk.remove_point(120, 10, 2)
85+
86+
print(sk.backbone_pts)
87+
print(sk.cross_bars)
88+
89+

0 commit comments

Comments
 (0)