Skip to content

Commit

Permalink
filter out triangle strips from extrusion
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Nov 17, 2023
1 parent f7a6e55 commit 43821d8
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 90 deletions.
6 changes: 4 additions & 2 deletions docs/changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Main changes
Major internal refactoring.

- fixes to `extrude()` thanks to @JeffreyWardman
- filter out triangle strips in Ribbon and extrude()
- improvements in doc strings

## Breaking changes

Expand Down Expand Up @@ -31,7 +34,6 @@ trackviewer (some problems with removing a track)
#### Broken Exports to .npz:
boolean.py
cartoony.py
flatarrow.py
mesh_lut.py
mesh_map2cell.py
texturecubes.py
Expand Down
2 changes: 0 additions & 2 deletions examples/advanced/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions examples/basic/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions examples/other/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions examples/pyplot/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions examples/simulations/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions examples/volumetric/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

61 changes: 28 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from setuptools import setup

try:
VERSIONFILE = "vedo/version.py"
verstrline = open(VERSIONFILE, "rt").read()
verstr = verstrline.split("=")[1].replace("\n", "").replace("'", "")
except:
verstr = "unknown"
with open("vedo/version.py", "r") as fh:
verstrline = fh.read()
verstr = verstrline.split("=")[1].replace("'", "").strip()

##############################################################
setup(
Expand All @@ -16,6 +13,31 @@
license="MIT",
license_files=['LICENSE', 'FONT.LICENSE'],

description="A python module for scientific analysis and visualization of 3D objects and point clouds based on VTK and Numpy.",
long_description="A python module for scientific visualization, analysis of 3D objects and point clouds based on VTK and Numpy. Check out https://vedo.embl.es for documentation.",

author="Marco Musy",
author_email="[email protected]",
maintainer="Marco Musy",
url="https://github.com/marcomusy/vedo",

keywords="vtk numpy 3D science analysis visualization mesh",
classifiers=[
"Intended Audience :: Science/Research",
"Intended Audience :: Education",
"Intended Audience :: Information Technology",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
"Topic :: Scientific/Engineering :: Information Analysis",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: MacOS",
],

packages=[
"vedo",
"vedo.examples.basic",
Expand All @@ -24,8 +46,6 @@
"vedo.examples.simulations",
"vedo.examples.volumetric",
"vedo.examples.other",
"vedo.examples.other.dolfin",
"vedo.examples.other.trimesh",
],

package_dir={
Expand All @@ -36,8 +56,6 @@
'vedo.examples.simulations': 'examples/simulations',
'vedo.examples.volumetric': 'examples/volumetric',
'vedo.examples.other': 'examples/other',
'vedo.examples.other.dolfin': 'examples/other/dolfin',
'vedo.examples.other.trimesh': 'examples/other/trimesh',
},

entry_points={
Expand All @@ -47,27 +65,4 @@
install_requires=["vtk", "numpy", "Pygments"],
include_package_data=True,

description="A python module for scientific analysis and visualization of 3D objects and point clouds based on VTK.",
long_description="A python module for scientific visualization, analysis of 3D objects and point clouds based on VTK. Check out https://vedo.embl.es for documentation.",

author="Marco Musy",
author_email="[email protected]",
maintainer="Marco Musy",
url="https://github.com/marcomusy/vedo",
keywords="vtk 3D science analysis visualization mesh numpy",
classifiers=[
"Intended Audience :: Science/Research",
"Intended Audience :: Education",
"Intended Audience :: Information Technology",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
"Topic :: Scientific/Engineering :: Information Analysis",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: MacOS",
],
)
11 changes: 4 additions & 7 deletions vedo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,18 @@ def box(self, scale=1, padding=0):
scale : (float)
box size can be scaled by a factor
padding : (float, list)
a constant padding can be added (can be a list [padx,pady,padz])
Examples:
- [latex.py](https://github.com/marcomusy/vedo/tree/master/examples/pyplot/latex.py)
a constant padding can be added (can be a list `[padx,pady,padz]`)
"""
b = self.bounds()
if not utils.is_sequence(padding):
padding = [padding, padding, padding]
length, width, height = b[1] - b[0], b[3] - b[2], b[5] - b[4]
tol = (length + width + height) / 30000 # useful for boxing 2D text
tol = (length + width + height) / 30000 # useful for boxing text
pos = [(b[0] + b[1]) / 2, (b[3] + b[2]) / 2, (b[5] + b[4]) / 2 - tol]
bx = vedo.shapes.Box(
pos,
length * scale + padding[0],
width * scale + padding[1],
width * scale + padding[1],
height * scale + padding[2],
c="gray",
)
Expand All @@ -497,7 +494,7 @@ def box(self, scale=1, padding=0):
bx.properties = pr
except (AttributeError, TypeError):
pass
bx.flat().lighting("off")
bx.flat().lighting("off").wireframe(True)
return bx

def bounds(self):
Expand Down
23 changes: 15 additions & 8 deletions vedo/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ def compute_normals(self, points=True, cells=True, feature_angle=None, consisten
else:
pdnorm.SetSplitting(False)
pdnorm.Update()
self.dataset.GetPointData().SetNormals(pdnorm.GetOutput().GetPointData().GetNormals())
self.dataset.GetCellData().SetNormals(pdnorm.GetOutput().GetCellData().GetNormals())
if points:
self.dataset.GetPointData().SetNormals(pdnorm.GetOutput().GetPointData().GetNormals())
if cells:
self.dataset.GetCellData().SetNormals(pdnorm.GetOutput().GetCellData().GetNormals())
return self

def reverse(self, cells=True, normals=False):
Expand Down Expand Up @@ -715,20 +717,20 @@ def triangulate(self, verts=True, lines=True):
Arguments:
verts : (bool)
if True, break input vertex cells into individual vertex cells
(one point per cell). If False, the input vertex cells will be ignored.
if True, break input vertex cells into individual vertex cells (one point per cell).
If False, the input vertex cells will be ignored.
lines : (bool)
if True, break input polylines into line segments.
If False, input lines will be ignored and the output will have no lines.
"""
if self.dataset.GetNumberOfPolys() or self.dataset.GetNumberOfStrips():
# print("vtkTriangleFilter")
# print("Using vtkTriangleFilter")
tf = vtk.new("TriangleFilter")
tf.SetPassLines(lines)
tf.SetPassVerts(verts)

elif self.dataset.GetNumberOfLines():
# print("vtkContourTriangulator")
# print("Using vtkContourTriangulator")
tf = vtk.new("ContourTriangulator")
tf.TriangulationErrorDisplayOn()

Expand Down Expand Up @@ -1665,7 +1667,13 @@ def extrude(self, zshift=1, direction=(), rotation=0, dr=0, cap=True, res=1):
rf.SetDeltaRadius(dr)
rf.Update()

m = Mesh(rf.GetOutput())
# convert triangle strips to polygonal data
tris = vtk.new("TriangleFilter")
tris.SetInputData(rf.GetOutput())
tris.Update()

m = Mesh(tris.GetOutput())

if len(direction) > 1:
p = self.pos()
LT = vedo.LinearTransform()
Expand All @@ -1679,7 +1687,6 @@ def extrude(self, zshift=1, direction=(), rotation=0, dr=0, cap=True, res=1):
m.apply_transform(LT)

m.copy_properties_from(self).flat().lighting("default")
# m.compute_normals(cells=False)
m.pipeline = OperationNode(
"extrude", parents=[self],
comment=f"#pts {m.dataset.GetNumberOfPoints()}"
Expand Down
7 changes: 6 additions & 1 deletion vedo/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,12 @@ def __str__(self):

npt = self.dataset.GetNumberOfPoints()
npo, nln = self.dataset.GetNumberOfPolys(), self.dataset.GetNumberOfLines()
out+= "elements".ljust(14) + f": vertices={npt:,}, polys={npo:,}, lines={nln:,}\n"
out+= "elements".ljust(14) + f": vertices={npt:,}, polygons={npo:,}, lines={nln:,}"
if self.dataset.GetNumberOfStrips():
out+= f", triangle_strips={self.dataset.GetNumberOfStrips():,}"
out+= "\n"
if self.dataset.GetNumberOfPieces() > 1:
out+= "pieces".ljust(14) + ": " + str(self.dataset.GetNumberOfPieces()) + "\n"

out+= "position".ljust(14) + ": " + f"{utils.precision(self.pos(), 6)}\n"
out+= "scaling".ljust(14) + ": "
Expand Down
4 changes: 0 additions & 4 deletions vedo/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2994,8 +2994,6 @@ def _plot_polar(
if mrg:
mrg.color(bc).alpha(alpha).lighting("off")
rh = Assembly([lines, ptsact, filling] + [mrg])
# rh.base = np.array([0, 0, 0], dtype=float)
# rh.top = np.array([0, 0, 1], dtype=float)
rh.name = "PlotPolar"
return rh

Expand Down Expand Up @@ -3181,8 +3179,6 @@ def _histogram_hex_bin(
asse = Assembly(hexs)
asse.scale([1.2 / n * dx, 1 / m * dy, norm / binmax * (dx + dy) / 4])
asse.pos([xmin, ymin, 0])
# asse.base = np.array([0, 0, 0], dtype=float)
# asse.top = np.array([0, 0, 1], dtype=float)
asse.name = "HistogramHexBin"
return asse

Expand Down
Loading

0 comments on commit 43821d8

Please sign in to comment.