From e1dd1d7d83300dab5b9ed7545703219f5bfb11cb Mon Sep 17 00:00:00 2001 From: marcomusy Date: Mon, 27 Nov 2023 22:30:42 +0100 Subject: [PATCH] correct self.pos(p) to self.transform = LinearTransform().translate(p) --- docs/changes.md | 6 +++++- examples/other/madcad1.py | 2 +- vedo/pyplot.py | 1 - vedo/shapes.py | 45 +++++++++++++++++++++++++-------------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 4f0b876f..5f37bba4 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -37,7 +37,11 @@ tests/issues/discussion_800.py tests/issues/issue_905.py gyroscope1.py broken markpoint.py -examples/other/pygmsh_cut.py ust cut tetmesh to gen ugrid +cut_and_cap.py + +volumetric/streamlines1.py +mousehover1.py +mousehover2.py (unstable hovering?) ``` #### Broken Projects diff --git a/examples/other/madcad1.py b/examples/other/madcad1.py index 58f666d4..53470baf 100644 --- a/examples/other/madcad1.py +++ b/examples/other/madcad1.py @@ -51,7 +51,7 @@ print(vmesh) scalar = vmesh.vertices[:, 0] -vmesh.cmap("rainbow", scalar).add_scalarbar(title="x-value") +vmesh.cmap("rainbow", scalar, on="points").add_scalarbar(title="x-value") vedo.show("Generating a path", vmesh, axes=7).close() ########################################################################## diff --git a/vedo/pyplot.py b/vedo/pyplot.py index fad0b6df..706baf93 100644 --- a/vedo/pyplot.py +++ b/vedo/pyplot.py @@ -1297,7 +1297,6 @@ def __init__( axes_opts["htitle"] = htitle axes_opts["htitle_justify"] = "bottom-left" axes_opts["htitle_size"] = 0.0175 - axes_opts["htitle_offset"] = [-0.49, 0.01, 0] ############################################### Figure init super().__init__(xlim, ylim, aspect, padding, **fig_kwargs) diff --git a/vedo/shapes.py b/vedo/shapes.py index fd86230d..4b1156ee 100644 --- a/vedo/shapes.py +++ b/vedo/shapes.py @@ -392,7 +392,7 @@ def __init__( class Line(Mesh): """ - Build the line segment between points `p0` and `p1`. + Build the line segment between point `p0` and point `p1`. If `p0` is already a list of points, return the line connecting them. @@ -409,10 +409,6 @@ def __init__(self, p0, p1=None, closed=False, res=2, lw=1, c="k1", alpha=1.0): (only relevant if only 2 points are specified) lw : (int) line width in pixel units - c : (color), int, str, list - color name, number, or list of [R,G,B] colors - alpha : (float) - opacity in range [0,1] """ if isinstance(p1, Points): @@ -422,14 +418,23 @@ def __init__(self, p0, p1=None, closed=False, res=2, lw=1, c="k1", alpha=1.0): if isinstance(p0, Points): p0 = p0.vertices - # detect if user is passing a list of points: - if isinstance(p0, vtk.vtkPolyData): + # try: + # p1 = p1.pos() + # p0 = p0.pos() + # except AttributeError: + # pass + + # try: + # p0 = p0.vertices + # except AttributeError: + # pass + if isinstance(p0, vtk.vtkPolyData): poly = p0 top = np.array([0,0,1]) base = np.array([0,0,0]) - elif utils.is_sequence(p0[0]): + elif utils.is_sequence(p0[0]): # detect if user is passing a list of points p0 = utils.make3d(p0) ppoints = vtk.vtkPoints() # Generate the polyline @@ -2037,7 +2042,7 @@ def __init__( super().__init__(tf.GetOutput(), c, alpha) - # self.transform = LinearTransform(t) + self.transform = LinearTransform().translate(start_pt) # self.pos(start_pt) self.phong().lighting("plastic") @@ -2230,7 +2235,7 @@ def __init__( phi = np.arctan2(axis[1], axis[0]) t = vtk.vtkTransform() - # t.Translate(start_pt) # brakes examples/pyplot/plot_empty.py + t.Translate(start_pt) if phi: t.RotateZ(np.rad2deg(phi)) if theta: @@ -2245,7 +2250,7 @@ def __init__( super().__init__(tf.GetOutput(), c, alpha) - self.pos(start_pt) # brakes examples/pyplot/plot_empty.py + self.transform = LinearTransform().translate(start_pt) self.lighting("off") self.actor.DragableOff() @@ -3125,6 +3130,7 @@ def __init__( """ if isinstance(pos, vtk.vtkPolyData): super().__init__(pos, c, alpha) + # self.transform = LinearTransform().translate(pos) else: ps = vtk.new("PlaneSource") @@ -3318,6 +3324,7 @@ def __init__( if len(pos) == 6: src.SetBounds(pos) + pos = [(pos[0] + pos[1]) / 2, (pos[2] + pos[3]) / 2, (pos[4] + pos[5]) / 2] elif len(size) == 3: length, width, height = size src.SetXLength(length) @@ -3362,6 +3369,7 @@ def __init__( vtc = utils.numpy2vtk(tc) pd.GetPointData().SetTCoords(vtc) super().__init__(pd, c, alpha) + self.transform = LinearTransform().translate(pos) self.name = "Box" @@ -3510,9 +3518,15 @@ def __init__( """ Build a cylinder of specified height and radius `r`, centered at `pos`. - If `pos` is a list of 2 points, e.g. `pos=[v1,v2]`, build a cylinder with base + If `pos` is a list of 2 points, e.g. `pos=[v1, v2]`, build a cylinder with base centered at `v1` and top at `v2`. + Arguments: + cap : (bool) + enable/disable the caps of the cylinder + res : (int) + resolution of the cylinder sides + ![](https://raw.githubusercontent.com/lorensen/VTKExamples/master/src/Testing/Baseline/Cxx/GeometricObjects/TestCylinder.png) """ if utils.is_sequence(pos[0]): # assume user is passing pos=[base, top] @@ -3553,6 +3567,7 @@ def __init__( self.phong() self.base = base self.top = top + self.transform = LinearTransform().translate(pos) self.name = "Cylinder" @@ -4889,9 +4904,6 @@ def __init__(self, formula, pos=(0, 0, 0), s=1.0, bg=None, res=150, usetex=False ![](https://vedo.embl.es/images/pyplot/latex.png) """ - self.formula = formula - - # try: from tempfile import NamedTemporaryFile import matplotlib.pyplot as mpltib @@ -4931,10 +4943,11 @@ def build_img_plt(formula, tfile): build_img_plt(formula, tmp_file.name) super().__init__(tmp_file.name, channels=4) - self.pos(pos) self.alpha(alpha) self.scale([0.25 / res * s, 0.25 / res * s, 0.25 / res * s]) + self.pos(pos) self.name = "Latex" + self.formula = formula # except: # printc("Error in Latex()\n", formula, c="r")