Skip to content

Commit

Permalink
changes to Axes by adding LinTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Nov 27, 2023
1 parent 92ee4c6 commit f69ac9f
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 277 deletions.
1 change: 1 addition & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- improvements in doc strings
- add `utils.madcad2vedo` conversion as per #976 by @JeffreyWardman
- add `utils.camera_to_dict()`
- add `Axes(title_backface_color=...)` keyword

## Breaking changes
- improvements to `shapes.Ellipsoid()` and bug fixes in #978 by @daniel-a-diaz
Expand Down
12 changes: 11 additions & 1 deletion examples/other/madcad1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
##########################################################################
square_profile = square((O, Z), 5).flip()
primitives = [
ArcCentered((5 * X, Y), O, 10 * X),
ArcCentered(( 5 * X, Y), O, 10 * X),
ArcCentered((15 * X, -Y), 10 * X, 20 * X),
]
# Generate a path
Expand All @@ -53,3 +53,13 @@
scalar = vmesh.vertices[:, 0]
vmesh.cmap("rainbow", scalar).add_scalarbar(title="x-value")
vedo.show("Generating a path", vmesh, axes=7).close()

##########################################################################
c1 = Circle((vec3(0), Z), 1)
c2 = Circle((2 * X, X), 0.5)
c3 = (Circle((2 * Y, Y), 0.5), "tangent", 2)
e1 = extrusion(2 * Z, web(c1))

m = junction(e1, c2, c3, tangents="normal")
vm = vedo.utils.madcad2vedo(m)
vedo.show(vm, e1, axes=1, viewup="z").close()
1 change: 0 additions & 1 deletion examples/pyplot/custom_axes2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
ztitle="Inverted Z in :mum",
htitle='My :Gamma^2_ijk plot',
htitle_font='Kanopus',
htitle_justify='bottom-right',
htitle_color='red2',
htitle_size=0.035,
htitle_offset=(0,0.075,0),
Expand Down
4 changes: 3 additions & 1 deletion tests/test_pipeline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pip install pygmsh -U
#pip install pymeshfix -U
#pip install tetgen -U
pip install pymeshlab -U
pip install pymadcad -U
pip install pyshtools -U
pip install rtree
pip install trimesh -U
Expand Down Expand Up @@ -131,7 +132,8 @@ cd $VDIR/docs/pdoc

# check web page examples
cd $VDIR
code www/examples_db.js
code docs/examples_db.js
cp docs/examples_db.js www/examples_db.js
code www/index.html


Expand Down
430 changes: 193 additions & 237 deletions vedo/addons.py

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions vedo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,15 +1542,19 @@ def pos(self, x=None, y=None, z=None):
z = 0

q = self.transform.position
LT = LinearTransform()
LT.translate([x, y, z] - q)
delta = [x, y, z] - q
if delta[0] == delta[1] == delta[2] == 0:
return self
LT = LinearTransform().translate(delta)
return self.apply_transform(LT)

def shift(self, dx=0, dy=0, dz=0):
"""Add a vector to the current object position."""
if utils.is_sequence(dx):
utils.make3d(dx)
dx, dy, dz = dx
if dx == dy == dz == 0:
return self
LT = LinearTransform().translate([dx, dy, dz])
return self.apply_transform(LT)

Expand Down Expand Up @@ -1606,6 +1610,8 @@ def rotate_x(self, angle, rad=False, around=None):
Use `around` to define a pivoting point.
"""
if angle == 0:
return self
LT = LinearTransform().rotate_x(angle, rad, around)
return self.apply_transform(LT)

Expand All @@ -1615,6 +1621,8 @@ def rotate_y(self, angle, rad=False, around=None):
Use `around` to define a pivoting point.
"""
if angle == 0:
return self
LT = LinearTransform().rotate_y(angle, rad, around)
return self.apply_transform(LT)

Expand All @@ -1624,6 +1632,8 @@ def rotate_z(self, angle, rad=False, around=None):
Use `around` to define a pivoting point.
"""
if angle == 0:
return self
LT = LinearTransform().rotate_z(angle, rad, around)
return self.apply_transform(LT)

Expand Down
16 changes: 4 additions & 12 deletions vedo/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3036,12 +3036,11 @@ def _scan_input_return_acts(self, objs):
scanned_acts.append(utils.meshlab2vedo(a))

elif "dolfin" in str(type(a)): # assume a dolfin.Mesh object
import vedo.dolfin as dlf

scanned_acts.append(dlf.MeshActor(a).actor)
import vedo.dolfin as vdlf
scanned_acts.append(vdlf.MeshActor(a).actor)

elif "madcad" in str(type(a)):
scanned_acts.append(utils.madcad2vedo(a))
scanned_acts.append(utils.madcad2vedo(a).actor)

else:
vedo.logger.error(f"cannot understand input in show(): {type(a)}")
Expand Down Expand Up @@ -4032,18 +4031,11 @@ def _keypress(self, iren, event):
self.reset_viewup()

elif key == "w":
if self.clicked_object and self.clicked_object in self.get_meshes():
# self.clicked_object.properties.SetRepresentationToWireframe()
if self.clicked_object:
if self.clicked_object.properties.GetRepresentation() == 1: # toggle
self.clicked_object.properties.SetRepresentationToSurface()
else:
self.clicked_object.properties.SetRepresentationToWireframe()
else:
for a in self.get_meshes():
if a.properties.GetRepresentation() == 1: # toggle
a.properties.SetRepresentationToSurface()
else:
a.properties.SetRepresentationToWireframe()

elif key == "1":
self._icol += 1
Expand Down
4 changes: 4 additions & 0 deletions vedo/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ def rotate(self, angle, axis=(1, 0, 0), point=(0, 0, 0), rad=False):
```
![](https://vedo.embl.es/images/feats/rotate_axis.png)
"""
if not angle:
return self
if rad:
anglerad = angle
else:
Expand All @@ -380,6 +382,8 @@ def rotate(self, angle, axis=(1, 0, 0), point=(0, 0, 0), rad=False):
return self

def _rotatexyz(self, axe, angle, rad, around):
if not angle:
return self
if rad:
angle *= 180 / np.pi

Expand Down
52 changes: 29 additions & 23 deletions vedo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def intersection_ray_triangle(P0, P1, V0, V1, V2):
# Credits: http://geomalgorithms.com/a06-_intersect-2.html
# Get triangle edge vectors and plane normal
# todo : this is slow should check
# https://vtk.org/doc/nightly/html/classvtkCell.html#aa850382213d7b8693f0eeec0209c347b
# https://vtk.org/doc/nightly/html/classvtkCell.html
V0 = np.asarray(V0, dtype=float)
P0 = np.asarray(P0, dtype=float)
u = V1 - V0
Expand Down Expand Up @@ -2385,6 +2385,12 @@ def vedo2open3d(vedo_mesh):
def madcad2vedo(madcad_mesh):
"""
Convert a `madcad.Mesh` to a `vedo.Mesh`.
A pointdata or celldata array named "tracks" is added to the output mesh, indicating
the mesh region each point belongs to.
A metadata array named "madcad_groups" is added to the output mesh, indicating
the mesh groups.
See [pymadcad website](https://pymadcad.readthedocs.io/en/latest/index.html)
for more info.
Expand All @@ -2394,61 +2400,61 @@ def madcad2vedo(madcad_mesh):
except:
pass

ppp = []
madp = []
for p in madcad_mesh.points:
ppp.append([float(p[0]), float(p[1]), float(p[2])])
ppp = np.array(ppp)
madp.append([float(p[0]), float(p[1]), float(p[2])])
madp = np.array(madp)

fff = []
madf = []
try:
for f in madcad_mesh.faces:
fff.append([int(f[0]), int(f[1]), int(f[2])])
fff = np.array(fff).astype(np.uint16)
madf.append([int(f[0]), int(f[1]), int(f[2])])
madf = np.array(madf).astype(np.uint16)
except AttributeError:
# print("no faces")
pass

eee = []
made = []
try:
edges = madcad_mesh.edges
for e in edges:
eee.append([int(e[0]), int(e[1])])
eee = np.array(eee).astype(np.uint16)
made.append([int(e[0]), int(e[1])])
made = np.array(made).astype(np.uint16)
except (AttributeError, TypeError):
# print("no edges")
pass

try:
line = np.array(madcad_mesh.indices).astype(np.uint16)
eee.append(line)
made.append(line)
except AttributeError:
# print("no indices")
pass

ttt = []
madt = []
try:
for t in madcad_mesh.tracks:
ttt.append(int(t))
ttt = np.array(ttt).astype(np.uint16)
madt.append(int(t))
madt = np.array(madt).astype(np.uint16)
except AttributeError:
# print("no tracks")
pass

###############################
poly = vedo.utils.buildPolyData(ppp, fff, eee)
if len(fff) == 0 and len(eee) == 0:
poly = vedo.utils.buildPolyData(madp, madf, made)
if len(madf) == 0 and len(made) == 0:
m = vedo.Points(poly)
else:
m = vedo.Mesh(poly)

if len(ttt) == len(fff):
m.celldata["tracks"] = ttt
maxt = np.max(ttt)
m.mapper.SetScalarRange(0, np.max(ttt))
if len(madt) == len(madf):
m.celldata["tracks"] = madt
maxt = np.max(madt)
m.mapper.SetScalarRange(0, np.max(madt))
if maxt==0: m.mapper.SetScalarVisibility(0)
elif len(ttt) == len(ppp):
m.pointdata["tracks"] = ttt
maxt = np.max(ttt)
elif len(madt) == len(madp):
m.pointdata["tracks"] = madt
maxt = np.max(madt)
m.mapper.SetScalarRange(0, maxt)
if maxt==0: m.mapper.SetScalarVisibility(0)

Expand Down

0 comments on commit f69ac9f

Please sign in to comment.