- Sketch projection partly works again :)
This commit is contained in:
parent
842799b35f
commit
d75d59f311
@ -684,9 +684,9 @@ class SketchWidget(QWidget):
|
|||||||
pen_normal = QPen(Qt.gray)
|
pen_normal = QPen(Qt.gray)
|
||||||
pen_normal.setWidthF(2 / self.zoom)
|
pen_normal.setWidthF(2 / self.zoom)
|
||||||
|
|
||||||
pen_construct = QPen(Qt.blue)
|
pen_construct = QPen(Qt.cyan)
|
||||||
pen_construct.setStyle(Qt.PenStyle.DashLine)
|
pen_construct.setStyle(Qt.PenStyle.DotLine)
|
||||||
pen_construct.setWidthF(2 / self.zoom)
|
pen_construct.setWidthF(1 / self.zoom)
|
||||||
|
|
||||||
pen_solver = QPen(Qt.green)
|
pen_solver = QPen(Qt.green)
|
||||||
pen_solver.setWidthF(2 / self.zoom)
|
pen_solver.setWidthF(2 / self.zoom)
|
||||||
|
@ -436,8 +436,60 @@ class VTKWidget(QtWidgets.QWidget):
|
|||||||
|
|
||||||
return xy_coordinates
|
return xy_coordinates
|
||||||
|
|
||||||
def compute_2d_coordinates_line(self, line_source, normal):
|
def compute_2d_coordinates_line(self, projected_mesh, normal):
|
||||||
|
# Normalize the normal vector
|
||||||
|
normal = np.array(normal)
|
||||||
|
normal = normal / np.linalg.norm(normal)
|
||||||
|
|
||||||
|
# Create a vtkTransform
|
||||||
|
transform = vtk.vtkTransform()
|
||||||
|
transform.PostMultiply() # This ensures transforms are applied in the order we specify
|
||||||
|
|
||||||
|
# Rotate so that the normal aligns with the Z-axis
|
||||||
|
rotation_axis = np.cross(normal, [0, 0, 1])
|
||||||
|
angle = np.arccos(np.dot(normal, [0, 0, 1])) * 180 / np.pi # Convert to degrees
|
||||||
|
|
||||||
|
if np.linalg.norm(rotation_axis) > 1e-6: # Check if rotation is needed
|
||||||
|
transform.RotateWXYZ(angle, rotation_axis[0], rotation_axis[1], rotation_axis[2])
|
||||||
|
|
||||||
|
# Get the transformation matrix
|
||||||
|
matrix = transform.GetMatrix()
|
||||||
|
self.local_matrix = [matrix.GetElement(i, j) for i in range(4) for j in range(4)]
|
||||||
|
|
||||||
|
# Apply the transform to the polydata
|
||||||
|
transformFilter = vtk.vtkTransformPolyDataFilter()
|
||||||
|
transformFilter.SetInputData(projected_mesh)
|
||||||
|
transformFilter.SetTransform(transform)
|
||||||
|
transformFilter.Update()
|
||||||
|
|
||||||
|
# Get the transformed points
|
||||||
|
transformed_polydata = transformFilter.GetOutput()
|
||||||
|
points = transformed_polydata.GetPoints()
|
||||||
|
lines = transformed_polydata.GetLines()
|
||||||
|
|
||||||
|
# Extract 2D coordinates
|
||||||
|
xy_coordinates = []
|
||||||
|
|
||||||
|
if points and lines:
|
||||||
|
points_data = points.GetData()
|
||||||
|
line_ids = vtk.vtkIdList()
|
||||||
|
|
||||||
|
# Loop through all the lines in the vtkCellArray
|
||||||
|
lines.InitTraversal()
|
||||||
|
while lines.GetNextCell(line_ids):
|
||||||
|
line_coordinates = []
|
||||||
|
for j in range(line_ids.GetNumberOfIds()):
|
||||||
|
point_id = line_ids.GetId(j)
|
||||||
|
point = points.GetPoint(point_id)
|
||||||
|
line_coordinates.append((point[0], point[1])) # Only take x, y
|
||||||
|
xy_coordinates.append(line_coordinates)
|
||||||
|
|
||||||
|
return xy_coordinates
|
||||||
|
|
||||||
|
|
||||||
|
def compute_2d_coordinates_line_bak(self, line_source, normal):
|
||||||
# Ensure the input is a vtkLineSource
|
# Ensure the input is a vtkLineSource
|
||||||
|
print("line", line_source)
|
||||||
if not isinstance(line_source, vtk.vtkLineSource):
|
if not isinstance(line_source, vtk.vtkLineSource):
|
||||||
raise ValueError("Input must be a vtkLineSource")
|
raise ValueError("Input must be a vtkLineSource")
|
||||||
|
|
||||||
@ -702,12 +754,16 @@ class VTKWidget(QtWidgets.QWidget):
|
|||||||
# Extract 2D coordinates
|
# Extract 2D coordinates
|
||||||
self.project_tosketch_points = self.compute_2d_coordinates(projected_polydata, self.selected_normal)
|
self.project_tosketch_points = self.compute_2d_coordinates(projected_polydata, self.selected_normal)
|
||||||
|
|
||||||
# Seperately rotate selected edges for drawing
|
# Green indicator mesh needs to be translated to xy point paris start end.
|
||||||
|
self.project_tosketch_lines = self.compute_2d_coordinates_line(projected_polydata, self.selected_normal)
|
||||||
|
|
||||||
|
print("result", self.project_tosketch_lines)
|
||||||
|
"""# Seperately rotate selected edges for drawing
|
||||||
self.project_tosketch_lines.clear()
|
self.project_tosketch_lines.clear()
|
||||||
for vtk_line in self.selected_vtk_line:
|
for vtk_line in self.selected_vtk_line:
|
||||||
proj_vtk_line = self.compute_2d_coordinates_line(vtk_line, self.selected_normal)
|
proj_vtk_line = self.compute_2d_coordinates_line(vtk_line, self.selected_normal)
|
||||||
self.project_tosketch_lines.append(proj_vtk_line)
|
self.project_tosketch_lines.append(proj_vtk_line)
|
||||||
print("outgoing lines", self.project_tosketch_lines)
|
print("outgoing lines", self.project_tosketch_lines)"""
|
||||||
|
|
||||||
# Create a mapper and actor for the projected data
|
# Create a mapper and actor for the projected data
|
||||||
mapper = vtk.vtkPolyDataMapper()
|
mapper = vtk.vtkPolyDataMapper()
|
||||||
|
10
main.py
10
main.py
@ -393,11 +393,12 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
selected = self.ui.sketch_list.currentItem()
|
selected = self.ui.sketch_list.currentItem()
|
||||||
name = selected.text()
|
name = selected.text()
|
||||||
|
|
||||||
# TODO: add selected element from timeline
|
# TODO: add selected element from timeline
|
||||||
sel_compo = self.project.timeline[-1]
|
sel_compo = self.project.timeline[-1]
|
||||||
print(sel_compo)
|
#print(sel_compo)
|
||||||
sketch = sel_compo.sketches[name]
|
sketch = sel_compo.sketches[name]
|
||||||
print(sketch)
|
#print(sketch)
|
||||||
points = sketch.sdf_points
|
points = sketch.sdf_points
|
||||||
|
|
||||||
if points[-1] == points[0]:
|
if points[-1] == points[0]:
|
||||||
@ -407,10 +408,10 @@ class MainWindow(QMainWindow):
|
|||||||
dialog = ExtrudeDialog(self)
|
dialog = ExtrudeDialog(self)
|
||||||
if dialog.exec():
|
if dialog.exec():
|
||||||
length, is_symmetric, invert, cut, union_with, rounded = dialog.get_values()
|
length, is_symmetric, invert, cut, union_with, rounded = dialog.get_values()
|
||||||
print(f"Extrude length: {length}, Symmetric: {is_symmetric} Invert: {invert}")
|
#print(f"Extrude length: {length}, Symmetric: {is_symmetric} Invert: {invert}")
|
||||||
else:
|
else:
|
||||||
length = 0
|
length = 0
|
||||||
print("Extrude cancelled")
|
#print("Extrude cancelled")
|
||||||
|
|
||||||
normal = self.custom_3D_Widget.selected_normal
|
normal = self.custom_3D_Widget.selected_normal
|
||||||
#print("Normie enter", normal)
|
#print("Normie enter", normal)
|
||||||
@ -429,6 +430,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
f = sketch.extrude(length, is_symmetric, invert, 0)
|
f = sketch.extrude(length, is_symmetric, invert, 0)
|
||||||
|
|
||||||
|
# Create body element and assign known stuff
|
||||||
name_op = f"extrd-{name}"
|
name_op = f"extrd-{name}"
|
||||||
sel_compo.body
|
sel_compo.body
|
||||||
body = Body()
|
body = Body()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user