Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def write(self, obj):
if not hasattr(self, 'fstream'):
self.onlywrite = True
self.fstream = open(self.filename, 'w')
if not self.onlywrite:
raise IOError('Could not write to file %s' % (self.filename))
"""Write the object in GoTools format. """
if isinstance(obj[0], SplineObject): # input SplineModel or list
for o in obj:
self.write(o)
return
for i in range(obj.pardim):
if obj.periodic(i):
obj = obj.split(obj.start(i), i)
self.fstream.write('{} 1 0 0\n'.format(G2.g2_type[obj.pardim-1]))
self.fstream.write('{} {}\n'.format(obj.dimension, int(obj.rational)))
for b in obj.bases:
self.fstream.write('%i %i\n' % (len(b.knots) - b.order, b.order))
self.fstream.write(' '.join('%.16g' % k for k in b.knots))
self.fstream.write('\n')
for cp in obj:
# -*- coding: utf-8 -*-
from splipy import BSplineBasis, SplineObject
from splipy.utils import ensure_listlike, check_direction, sections
from itertools import chain
import numpy as np
__all__ = ['Volume']
class Volume(SplineObject):
"""Volume()
Represents a volume: an object with a three-dimensional parameter space."""
_intended_pardim = 3
def __init__(self, basis1=None, basis2=None, basis3=None, controlpoints=None, rational=False, **kwargs):
"""__init__([basis1=None], [basis2=None], [basis3=None], [controlpoints=None], [rational=False])
Construct a volume with the given basis and control points.
The default is to create a linear one-element mapping from and to the
unit cube.
:param BSplineBasis basis1: The basis of the first parameter direction
:param BSplineBasis basis2: The basis of the second parameter direction
next(lines) # Skip spline accuracy
knots = [[float(k) for k in islice(lines, nkts)] for nkts in nknots]
bases = [BSplineBasis(p, kts, -1) for p, kts in zip(orders, knots)]
cpts = np.array([float(k) for k in islice(lines, totcoeffs * physdim)])
cpts = cpts.reshape(physdim, *(ncoeffs[::-1])).transpose()
if pardim == 1:
patch = Curve(*bases, controlpoints=cpts, raw=True)
elif pardim == 2:
patch = Surface(*bases, controlpoints=cpts, raw=True)
elif pardim == 3:
patch = Volume(*bases, controlpoints=cpts, raw=True)
else:
patch = SplineObject(bases, controlpoints=cpts, raw=True)
return [patch]
# -*- coding: utf-8 -*-
from splipy import BSplineBasis, Curve, SplineObject
from splipy.SplineObject import evaluate
from splipy.utils import is_singleton
from splipy.utils import ensure_listlike, check_direction, sections
from bisect import bisect_left
from itertools import chain
import numpy as np
__all__ = ['Surface']
class Surface(SplineObject):
"""Surface()
Represents a surface: an object with a two-dimensional parameter space."""
_intended_pardim = 2
def __init__(self, basis1=None, basis2=None, controlpoints=None, rational=False, **kwargs):
""" Construct a surface with the given basis and control points.
The default is to create a linear one-element mapping from and to the
unit square.
:param BSplineBasis basis1: The basis of the first parameter direction
:param BSplineBasis basis2: The basis of the second parameter direction
:param array-like controlpoints: An *n1* × *n2* × *d* matrix of control points
:param bool rational: Whether the surface is rational (in which case the
def write(self, obj):
""" Writes a list of planar curves and surfaces to vector graphics SVG file.
The image will never be stretched, and the geometry will keep width/height ratio
of original geometry, regardless of provided width/height ratio from arguments.
:param obj: Primitives to write
:type obj: List of Curves and/or Surfaces
:returns: None
:rtype : NoneType
"""
# actually this is a dummy method. It will collect all geometries provided
# and ton't actually write them to file until __exit__ is called
if isinstance(obj[0], SplineObject): # input SplineModel or list
for o in obj:
self.write(o)
return
if obj.dimension != 2:
raise RuntimeError('SVG files only applicable for 2D geometries')
# have to clone stuff we put here, in case they change on the outside
self.all_objects.append( obj.clone() )
# -*- coding: utf-8 -*-
from splipy import BSplineBasis
from splipy import SplineObject
from splipy.utils import ensure_listlike, is_singleton
from itertools import chain
from bisect import bisect_left, bisect_right
import numpy as np
import scipy.sparse.linalg as splinalg
__all__ = ['Curve']
class Curve(SplineObject):
"""Curve()
Represents a curve: an object with a one-dimensional parameter space."""
_intended_pardim = 1
def __init__(self, basis=None, controlpoints=None, rational=False, **kwargs):
""" Construct a curve with the given basis and control points.
The default is to create a linear one-element mapping from (0,1) to the
unit interval.
:param BSplineBasis basis: The underlying B-Spline basis
:param array-like controlpoints: An *n* × *d* matrix of control points
:param bool rational: Whether the curve is rational (in which case the
control points are interpreted as pre-multiplied with the weight,
cp = cp.transpose((1, 0, 2))
cp = cp.reshape(n[0] * n[1], cp.shape[2])
# return new resampled curve
return Surface(basis[0], basis[1], cp)
def __repr__(self):
result = str(self.bases[0]) + '\n' + str(self.bases[1]) + '\n'
# print legacy controlpoint enumeration
n1, n2, n3 = self.controlpoints.shape
for j in range(n2):
for i in range(n1):
result += str(self.controlpoints[i, j, :]) + '\n'
return result
get_derivative_surface = SplineObject.get_derivative_spline
# return new resampled curve
return Volume(basis[0], basis[1], basis[2], cp)
def __repr__(self):
result = str(self.bases[0]) + '\n'
result += str(self.bases[1]) + '\n'
result += str(self.bases[2]) + '\n'
# print legacy controlpoint enumeration
n1, n2, n3, dim = self.controlpoints.shape
for k in range(n3):
for j in range(n2):
for i in range(n1):
result += str(self.controlpoints[i, j, k, :]) + '\n'
return result
get_derivative_volume = SplineObject.get_derivative_spline