Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
--------
:func:`read_surface`
"""
if otype is None:
otype = opth.split('.')[-1]
writer = _select_writer(otype)
writer.filename = opth
if otype not in ['vtp', 'tri', 'gii', 'obj']:
if oformat == 'ascii' or otype == 'asc':
writer.SetFileTypeToASCII()
else:
writer.SetFileTypeToBinary()
serial_connect(ifilter, writer, update=True, as_data=False, port=None)
ext = ext[1:]
fmts1 = {'bmp', 'jpeg', 'jpg', 'png', 'tif', 'tiff'}
fmts2 = {'eps', 'pdf', 'ps', 'svg'}
if ext in fmts1:
wimg = self._win2img(transparent_bg, scale)
if ext == 'bmp':
writer = BSBMPWriter(filename=filename)
elif ext in ['jpg', 'jpeg']:
writer = BSJPEGWriter(filename=filename)
elif ext == 'png':
writer = BSPNGWriter(filename=filename)
else: # if ext in ['tif', 'tiff']:
writer = BSTIFFWriter(filename=filename)
serial_connect(wimg, writer, as_data=False)
elif ext in fmts2:
self._check_closed()
self._check_offscreen()
orig_sz = self.ren_win.size
self.ren_win.size = np.array(scale) * orig_sz
w = BSGL2PSExporter(input=self.ren_win, fileFormat=ext,
compress=False, simpleLineOffset=True,
filePrefix=pth_no_ext,
title='', write3DPropsAsRasterImage=True)
w.UsePainterSettings()
w.Update()
self.ren_win.size = orig_sz
surf : vtkPolyData or BSPolyData
Input surface.
Returns
-------
output : BSPolyData
PolyData with vertex points.
See Also
--------
:func:`to_lines`
:func:`build_polydata`
"""
return serial_connect(surf, vtkVertexGlyphFilter())
def to_notebook(self, transparent_bg=True, scale=(1, 1)):
# if not in_notebook():
# raise ValueError("Cannot find notebook.")
wimg = self._win2img(transparent_bg, scale)
writer = BSPNGWriter(writeToMemory=True)
result = serial_connect(wimg, writer, as_data=False).result
data = memoryview(result).tobytes()
from IPython.display import Image
return Image(data)
points.
"""
s = BSPolyData(points=points)
if cells is not None:
n_cells, n_points_cell = cells.shape
if n_points_cell == 1:
s.SetVerts(cells)
elif n_points_cell == 2:
s.SetLines(cells)
else:
s.SetPolys(cells)
# Triangulation needed
return serial_connect(s, vtkTriangleFilter())
n_pts = surf.GetNumberOfPoints()
# Increase to account for points outside mask
if mask is not None:
keep *= (1 + np.count_nonzero(~mask) / n_pts)
if isinstance(keep, int):
factor = (n_pts - keep) / n_pts
elif 0 < keep < 1:
factor = 1 - keep
else:
ValueError('The value of \'keep\' is not valid.')
cf = vtkDecimatePro()
cf.SetTargetReduction(factor)
decimated_surf = serial_connect(surf, cf)
idx = find_point_correspondence(decimated_surf, surf, eps=0, n_jobs=n_jobs)
sampled_points = np.zeros(n_pts, dtype=np.uint8)
sampled_points[idx] = 1
# Remove points sampled outside mask
if mask is not None:
sampled_points[~mask] = 0
return sampled_points