Skip to content

Commit

Permalink
increase precision in writing obj files
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed May 15, 2024
1 parent cb0b514 commit 40a7c99
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 20 deletions.
10 changes: 7 additions & 3 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
- fix minor bug in RoundedLine #1104 by @PinkMushroom
- fix avoid overwriting screenshots with "S" key #1100 by @j042
- add support for meshlib
- add more kw options to `core.probe()`
- increase precision in writing obj files as per #1119 by @ManuGraiph


## Soft-breaking Changes
Changes that will break existing code whose fixing is trivial:

- remove concatenate=True flag from `apply_transform()` in #1111
- remove concatenate=True flag from `apply_transform()` discussed in #1111


## Hard-breaking Changes
Expand All @@ -42,6 +44,7 @@ examples/basic/interaction_modes3.py
examples/advanced/warp4b.py
examples/other/magic-class1.py
examples/other/iminuit2.py
examples/other/meshlib1.py
```

### Broken Examples
Expand All @@ -57,10 +60,11 @@ tests/issues/discussion_800.py (incomplete capping of tube)
make_video
```

#### Broken Projects
umap_viewer3d
#### Broken Projects and Known Issues
umap_viewer3d should be revised
trackviewer (some problems with removing a track, and z spacing)
closing the window in spyder doesnt work anymore.
pyplot.plot cannot plot constant line or single point

#### Broken Exports to .npz:
boolean.py
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/warp4b.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
target = Mesh(dataurl+"290.vtk").color("yellow5")
target.rotate_y(-40)

plt = MorphPlotter(source, target, size=(2490, 850), axes=14)
plt = MorphPlotter(source, target, size=(2400, 850), axes=14)
plt.cmap_name = "RdYlBu_r"
plt.show()
plt.close()
Expand Down
11 changes: 5 additions & 6 deletions examples/basic/silhouette3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
move along with camera position"""
from vedo import *

s = Mesh(dataurl+'shark.ply').c('gray',0.1).lw(1).lc('k')

# this call creates the camera object needed by silhouette()
show(s, bg='db', bg2='lb', interactive=False)
# Need to create a Plotter instance to access the camera
plt = Plotter(bg='blue4', bg2='white')

sil = s.silhouette().c('darkred',0.9).lw(3)
s = Mesh(dataurl+'shark.ply').c('gray',0.1).lw(1).lc('k')
silh = s.silhouette().c('red3',0.9).lw(3)

show(s, sil, __doc__).interactive().close()
plt.show(s, silh, __doc__).close()
6 changes: 3 additions & 3 deletions tests/snippets/test_docs_sniplets.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ def fibonacci_sphere(n):
print("cube1 position", c1.pos())
T = c1.transform # rotate by 5 degrees, sum 2 to x and 1 to y
c2 = Cube().c('r4')
c2.apply_transform(T) # ignore previous movements
c2.apply_transform(T, concatenate=True)
c2.apply_transform(T, concatenate=True)
c2.apply_transform(T)
c2.apply_transform(T)
c2.apply_transform(T)
print("cube2 position", c2.pos())
if doshow:
show(c1, c2, axes=1).close()
Expand Down
29 changes: 27 additions & 2 deletions vedo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,15 +1253,31 @@ def vorticity(self, array_name=None, on="points", fast=False) -> np.ndarray:
vvecs = utils.vtk2numpy(vort.GetOutput().GetCellData().GetArray("Vorticity"))
return vvecs

def probe(self, source) -> Self:
def probe(
self,
source,
categorical=False,
snap=False,
tol=0,
) -> Self:
"""
Takes a data set and probes its scalars at the specified points in space.
Note that a mask is also output with valid/invalid points which can be accessed
with `mesh.pointdata['ValidPointMask']`.
Arguments:
source : any dataset
the data set to probe.
categorical : bool
control whether the source pointdata is to be treated as categorical.
snap : bool
snap to the cell with the closest point if no cell was found
tol : float
the tolerance to use when performing the probe.
Check out also:
`interpolate_data_from()`
`interpolate_data_from()` and `tovolume()`
Examples:
- [probe_points.py](https://github.com/marcomusy/vedo/tree/master/examples/volumetric/probe_points.py)
Expand All @@ -1271,6 +1287,15 @@ def probe(self, source) -> Self:
probe_filter = vtki.new("ProbeFilter")
probe_filter.SetSourceData(source.dataset)
probe_filter.SetInputData(self.dataset)
probe_filter.PassCellArraysOn()
probe_filter.PassFieldArraysOn()
probe_filter.PassPointArraysOn()
probe_filter.SetCategoricalData(categorical)
probe_filter.ComputeToleranceOff()
if tol:
probe_filter.ComputeToleranceOn()
probe_filter.SetTolerance(tol)
probe_filter.SetSnapToCellWithClosestPoint(snap)
probe_filter.Update()
self._update(probe_filter.GetOutput(), reset_locators=False)
self.pipeline = utils.OperationNode("probe", parents=[self, source])
Expand Down
2 changes: 1 addition & 1 deletion vedo/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ def write(objct: Any, fileoutput: str, binary=True) -> Any:
outF.write("# File generated by vedo\n")

for p in objct.vertices:
outF.write("v {:.5g} {:.5g} {:.5g}\n".format(*p))
outF.write("v {:.8g} {:.8g} {:.8g}\n".format(*p))

ptxt = objct.dataset.GetPointData().GetTCoords()
if ptxt:
Expand Down
10 changes: 7 additions & 3 deletions vedo/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3155,18 +3155,22 @@ def densify(self, target_distance=0.1, nclosest=6, radius=None, niter=1, nmax=No
"""
src = vtki.new("ProgrammableSource")
opts = self.vertices
# zeros = np.zeros(3)

def _read_points():
output = src.GetPolyDataOutput()
points = vtki.vtkPoints()
for p in opts:
# print(p)
# if not np.array_equal(p, zeros):
points.InsertNextPoint(p)
output.SetPoints(points)

src.SetExecuteMethod(_read_points)

dens = vtki.new("DensifyPointCloudFilter")
dens.SetInputConnection(src.GetOutputPort())
# dens.SetInputData(self.dataset) # this does not work
dens.InterpolateAttributeDataOn()
dens.SetTargetDistance(target_distance)
dens.SetMaximumNumberOfIterations(niter)
Expand All @@ -3183,11 +3187,11 @@ def _read_points():
vedo.logger.error("set either radius or nclosest")
raise RuntimeError()
dens.Update()
pts = utils.vtk2numpy(dens.GetOutput().GetPoints().GetData())
cld = Points(pts, c=None).point_size(self.properties.GetPointSize())

cld = Points(dens.GetOutput())
cld.copy_properties_from(self)
cld.interpolate_data_from(self, n=nclosest, radius=radius)
cld.name = "DensifiedCloud"

cld.pipeline = utils.OperationNode(
"densify",
parents=[self],
Expand Down
9 changes: 9 additions & 0 deletions vedo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def __init__(self) -> None:
self.k3d_line_shader = "thick"

self.font_parameters = dict(

Normografo=dict(
mono=False,
fscale=0.75,
Expand Down Expand Up @@ -486,6 +487,14 @@ def __init__(self) -> None:
dotsep="x",
islocal=False,
),
Darwin=dict(
mono=False,
fscale=0.8,
hspacing=0.75,
lspacing=0.15,
dotsep="x",
islocal=False,
),
Vega=dict(
mono=False,
fscale=0.8,
Expand Down
2 changes: 1 addition & 1 deletion vedo/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_version = '2024.5.1+dev14'
_version = '2024.5.1+dev15'

0 comments on commit 40a7c99

Please sign in to comment.