Skip to content

Commit

Permalink
correct self.pos(p) to self.transform = LinearTransform().translate(p)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Nov 27, 2023
1 parent 37b5e3b commit e1dd1d7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
6 changes: 5 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/other/madcad1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

##########################################################################
Expand Down
1 change: 0 additions & 1 deletion vedo/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 29 additions & 16 deletions vedo/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -3553,6 +3567,7 @@ def __init__(
self.phong()
self.base = base
self.top = top
self.transform = LinearTransform().translate(pos)
self.name = "Cylinder"


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e1dd1d7

Please sign in to comment.