Skip to content

Commit

Permalink
tests/issues/issue_1077.py
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jun 13, 2024
1 parent db0c0bf commit cf01811
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 89 deletions.
5 changes: 3 additions & 2 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- fix add tolerance to contains #1105 by @JeffreyWardman
- fix minor bug in RoundedLine #1104 by @PinkMushroom
- fix avoid overwriting screenshots with "S" key #1100 by @j042
- add support for meshlib
- add support for `meshlib`
- add more kw options to `core.probe()`
- increase precision in writing obj files as per #1119 by @ManuGraiph
- add `plotter.freeze()` to freeze interaction of current renderer in #1122 by @sergei9838
Expand Down Expand Up @@ -48,14 +48,15 @@ examples/advanced/warp4b.py
examples/other/magic-class1.py
examples/other/iminuit2.py
examples/other/meshlib1.py
tests/issues/issue_1077.py
```

### Broken Examples
Examples that are not fully functional and need some fixing:
```
markpoint.py (misplaced leader indicator)
cut_and_cap.py (incomplete capping)
gyroscope1.py (broken physics)
tests/issues/discussion_800.py (incomplete capping of tube)
```

Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/cut_with_points1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
settings.interpolate_scalars_before_mapping = True

s = Sphere()
s.color("white").alpha(0.25).backface_culling(True)
s.pointdata['scalars1'] = np.sqrt(range(s.npoints))
s.color("white").alpha(0.25).backface_culling()
s.pointdata['myscalars'] = s.coordinates[:,1]
print(s)

# Pick a few points on the sphere
Expand All @@ -16,7 +16,7 @@

# Cut the loop region identified by the points
scut = s.clone().cut_with_point_loop(sv, invert=False).scale(1.01)
scut.cmap("Paired", "scalars1").alpha(1).add_scalarbar()
scut.cmap("Paired", "myscalars").alpha(1).add_scalarbar()
print(scut)

show(s, pts, scut, __doc__, axes=1, viewup="z")
11 changes: 6 additions & 5 deletions examples/basic/align6.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
# Set up a Plotter object with 2 subrenderers
plt = Plotter(N=2)

# Show the original mesh, axes, and cube in the left renderer with the script description
plt.at(0).show(msh1, axes1, cube, __doc__)
# Add the original mesh, axes, and cube in the left renderer with the script description
plt.at(0).add(msh1, axes1, cube, __doc__)

# Show the aligned mesh and axes in the right renderer, viewing from the top
plt.at(1).show(msh2, axes2, viewup='z')
# Add the aligned mesh and axes in the right renderer, viewing from the top
plt.at(1).add(msh2, axes2, cube)

# Enable interaction and close the plotter when done
# Show all and close the plotter when done
plt.show(viewup='z', zoom=0.6)
plt.interactive().close()
50 changes: 0 additions & 50 deletions examples/other/dolfin/stokes2.py

This file was deleted.

10 changes: 0 additions & 10 deletions examples/pyplot/donut.py

This file was deleted.

14 changes: 14 additions & 0 deletions examples/pyplot/pie_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from vedo import settings, show
from vedo.pyplot import pie_chart

settings.default_font = "Komika"

title = "A pie chart plot"
fractions = [0.1, 0.2, 0.3, 0.1, 0.3]
colors = [ 1, 2, 3, 4, 'white']
labels = ["stuff_1 ", "stuff_2 ", "comp^A ", "comp^B ", ""]

pc = pie_chart(fractions, c=colors, labels=labels, title=title)
pc2d = pc.clone2d("top-left", size=0.975, ontop=False)

show(pc2d).close()
3 changes: 1 addition & 2 deletions examples/simulations/gyroscope1.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

shaft = Cylinder([[0, 0, 0], Ls * gaxis], r=0.03).c("dark green")
rotor = Cylinder([(Ls - 0.55) * gaxis, (Ls - 0.45) * gaxis], r=R).c("tomato")
bar = Cylinder([Ls*gaxis/2-R*vector(0,1,0), Ls*gaxis/2+R*vector(0,1,0)], r=R/6).c("red5")
gyro = shaft + rotor + bar # group meshes into a single one of type Assembly
gyro = shaft + rotor # group meshes into a single one of type Assembly

spring = Spring(top, gpos, r1=0.06, thickness=0.01).c("gray")
plt += [gyro, spring] # add it to Plotter.
Expand Down
6 changes: 3 additions & 3 deletions examples/simulations/particle_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ def __init__(self, pos, charge, mass, radius, color, vel, fixed, negligible):
#####################################################################################################
if __name__ == "__main__":

plt = Plotter(title="Particle Simulator", bg="black", axes=0, interactive=False)
plt = Plotter(title="Particle Simulator", bg="black", interactive=False)

plt += Cube().c('w').wireframe(True).lighting('off') # a wireframe cube

sim = ParticleSim(dt=1e-5, iterations=60)
sim = ParticleSim(dt=1e-5, iterations=50)
sim.add_particle((-0.4, 0, 0), color="w", charge=3e-6, radius=0.01, fixed=True) # the target

positions = np.random.randn(500, 3) / 60 # generate a beam of particles
positions = np.random.randn(100, 3) / 60 # generate a beam of particles
for p in positions:
p[0] = -0.5 # Fix x position. Their charge are small/negligible compared to target:
sim.add_particle(p, charge=0.01e-6, mass=0.1e-6, vel=(1000, 0, 0), negligible=True)
Expand Down
15 changes: 8 additions & 7 deletions examples/simulations/self_org_maps2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# -----------------------------------------------------------------------------
import numpy as np
import scipy.spatial
from vedo import *
from vedo import Sphere, Grid, Plotter, progressbar


class SOM:
Expand All @@ -27,7 +27,7 @@ def learn(self, n_epoch=10000, sigma=(0.25,0.01), lrate=(0.5,0.01)):
I = np.random.randint(0, len(self.samples), n_epoch)
self.samples = self.samples[I]

for i in progressbar(range(n_epoch)):
for i in progressbar(n_epoch):
# Get random sample
data = self.samples[i]

Expand All @@ -49,9 +49,9 @@ def learn(self, n_epoch=10000, sigma=(0.25,0.01), lrate=(0.5,0.01)):
for j in range(n):
grdpts[i*n+j] = (x[i,j], y[i,j], z[i,j])
grd.vertices = grdpts
plt.azimuth(1.0).render()
if plt: plt.azimuth(1.0).render()

plt.interactive().close()
if plt: plt.interactive().close()

return [self.codebook[:,i].reshape(n,n) for i in range(3)]

Expand All @@ -63,12 +63,13 @@ def learn(self, n_epoch=10000, sigma=(0.25,0.01), lrate=(0.5,0.01)):
P = np.c_[X.ravel(), Y.ravel()]
D = scipy.spatial.distance.cdist(P, P)

s = Sphere(res=90).cut_with_plane(origin=(0,-.3,0), normal='y').subsample(0.01)
sphere = Sphere(res=90).cut_with_plane(origin=(0,-.3,0), normal='y')
sphere.subsample(0.01).add_gaussian_noise(0.5).point_size(3)

plt = Plotter(axes=6, interactive=False)
grd = Grid(res=[n-1, n-1]).c('green2')
plt.show(__doc__, s.ps(1), grd)
plt.show(__doc__, sphere, grd)

som = SOM((len(P), 3), D)
som.samples = s.vertices
som.samples = sphere.vertices.copy()
som.learn(n_epoch=4000, sigma=(1, 0.01), lrate=(1, 0.01))
16 changes: 16 additions & 0 deletions tests/issues/issue_1077.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from vedo import *

aline = Line(Circle().coordinates)
spline = Spline([(0,0,0), (1,1,1), (2,3,3), (1,1,4), (0,1,5)])
spline.lw(5)
pts = spline.coordinates

surfs = []
for i in range(1, len(pts)):
p0, p1 = pts[i-1:i+1]
surf = aline.sweep(p1 - p0)
surfs.append(surf)
surface = merge(surfs, flag=True)
surface.c("gold").lw(0.1).pickable(True)

show(spline, surface, aline, axes=1).close()
4 changes: 3 additions & 1 deletion tests/pipeline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ cd ~/Projects/server/trackviewer
./main_test.py
################
cd /g/sharpe/software/clone_viewer2
./clone_viewer3d.py
cd ~/Projects/clonal_analysis/clone_viewer3
./clone_viewer_gio3d.py
################
cd ~/Projects/server/rio_organoid
python main4.py
Expand Down Expand Up @@ -133,6 +134,7 @@ cd ~/Projects/server/brainrender/examples
################
cd ~/Projects/clonal_analysis
python -m analysis_plots2d
python tc_morph4_2d.py
################
cd ~/Projects/server/gustaf
git pull
Expand Down
4 changes: 2 additions & 2 deletions vedo/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,12 +1476,12 @@ def __init__(
self.idmousemove = self.add_callback("MouseMove", self._on_mouse_move)
self.drawmode = False
self.tol = tol # tolerance of point distance
self.cpoints = np.array([])
self.cpoints = []
self.points = None
self.spline = None
self.jline = None
self.topline = None
self.top_pts = np.array([])
self.top_pts = []

def init(self, init_points):
"""Set an initial number of points to define a region"""
Expand Down
1 change: 1 addition & 0 deletions vedo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def exe_convert(args):
"ply",
"stl",
"obj",
"off",
"byu",
"xml",
"vti",
Expand Down
10 changes: 10 additions & 0 deletions vedo/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,16 @@ def write(objct: Any, fileoutput: str, binary=True) -> Any:
outF.write(f"l {ls}\n")
return objct

elif fr.endswith(".off"):
with open(fileoutput, "w", encoding="UTF-8") as outF:
outF.write("OFF\n")
outF.write(str(objct.npoints) + " " + str(objct.ncells) + " 0\n\n")
for p in objct.vertices:
outF.write(" ".join([str(i) for i in p]) + "\n")
for c in objct.cells:
outF.write(str(len(c)) + " " + " ".join([str(i) for i in c]) + "\n")
return objct

elif fr.endswith(".xml"): # write tetrahedral dolfin xml
vertices = objct.vertices.astype(str)
faces = np.array(objct.cells).astype(str)
Expand Down
4 changes: 2 additions & 2 deletions vedo/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"plot",
"histogram",
"fit",
"donut",
"pie_chart",
"violin",
"whisker",
"streamplot",
Expand Down Expand Up @@ -3282,7 +3282,7 @@ def _histogram_spheric(thetavalues, phivalues, rmax=1.2, res=8, cmap="rainbow",
return newsg


def donut(
def pie_chart(
fractions,
title="",
tsize=0.3,
Expand Down
3 changes: 1 addition & 2 deletions vedo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,7 @@ def vtk2numpy(varr):
varr = varr.GetMatrix()
except AttributeError:
pass
n = 4
M = [[varr.GetElement(i, j) for j in range(n)] for i in range(n)]
M = [[varr.GetElement(i, j) for j in range(4)] for i in range(4)]
return np.array(M)
return vtk_to_numpy(varr)

Expand Down

0 comments on commit cf01811

Please sign in to comment.