ddg.datastructures.nets.utils module

ddg.datastructures.nets.utils.domain_util(f)[source]

Decorator for domain utilities.

It is assumed that the decorated function returns a list of intervals and that its first argument is the domain to work on. The newly constructed domain will be of the same type as the input and for nets and net collections the wrapped function will change their domain inplace, i.e. replace the domain of the net with the newly constructed one.

Parameters:
fCallable

domain utility function

Returns:
Callablewrapped function

See also

net_util
ddg.datastructures.nets.utils.net_util(f)[source]

Decorator for net utilities.

It is assumed that the decorated function returns a tuple of a function and a list of intervals. The newly constructed net will be if the same type as the input.

Parameters:
fCallable

net utility function

Returns:
Callablewrapped function

See also

domain_util
ddg.datastructures.nets.utils.compose(f, n)[source]

The composition x -> f(n(x)) adapted to nets and net collections.

Parameters:
fcallable or numpy.ndarray
nNet or NetCollection
Returns:
Net or NetCollection

The same type as n.

Examples

>>> import numpy as np
>>> from ddg.datastructures.nets.net import SmoothNet
>>> from ddg.datastructures.nets.utils import compose
>>> line = SmoothNet(lambda t: np.array([t, 0]), [(0, np.pi, True)])
>>> line(2)
array([2, 0])
>>> translated_line = compose(lambda x: x + (0, 1), line)
>>> translated_line(2)
array([2, 1])
>>> linearly_transformed_line = compose(np.array([[2, 1], [0, 1]]), line)
>>> linearly_transformed_line(2)
array([4, 0])

Unlike

def f_after_n(x):
    return f(n(x))

compose retains the net domain(s) by returning a net or net collection.

>>> type(linearly_transformed_line)
<class 'ddg.datastructures.nets.net.SmoothCurve'>
>>> linearly_transformed_line.domain
SmoothInterval([0.0, 3.14..., True])

The parameter n is required to be a net or a net collection. If it isn’t, then there is no need to retain a domain, so

def f_after_n(x):
    return f(n(x))

suffices.

ddg.datastructures.nets.utils.homogenize(net)[source]

Homogenize the values of given net.

Parameters:
netddg.datastructures.nets.net.Net

The net to operate on.

Returns:
A net of the same type.

See also

Net

Notes

  • It is assumed that the values of the net are of type np.array.

ddg.datastructures.nets.utils.dehomogenize(net)[source]

Dehomogenize the values of given net.

Parameters:
netddg.datastructures.nets.net.Net

The net to operate on.

Returns:
A net of the same type.

See also

Net

Notes

  • It is assumed that the values of the net are of type np.array.

ddg.datastructures.nets.utils.embed(net, level=0, component=-1)[source]

Embeds the given net in a space one dimension higher than before.

Parameters:
netddg.datastructures.nets.net.Net

The net to operate on.

levelfloat

(default 0)

componentint (default=-1)

Component to add

Returns:
A net of the same type.

See also

Net

Notes

  • It is assumed that the values of the net are of type np.array.

ddg.datastructures.nets.utils.vertices(net)[source]

Get all vertex values from a given net or net collection.

Parameters:
netddg.datastructures.nets.net.DiscreteNet or NetCollection

The net or net collection to obtain all the vertices from

Returns:
Generator

Generator containing all vertex values.

ddg.datastructures.nets.utils.applicable_to_netcollection(f, creates_new_nets=True)[source]
ddg.datastructures.nets.utils.surface_of_revolution(curve, axis=2, name='Surface of Revolution')[source]

Generate a surface of revolution from a planar curve

Parameters:
curveddg.datastructures.nets.net.SmoothNet

Planar curve.

axis0, 1, 2

Axis of rotation.

name: str

Name of the surface.

Returns:
ddg.datastructures.nets.net.SmoothNet

Surface of revolution.

ddg.datastructures.nets.utils.cylinder(curve, axis=2, name='Cylinder')[source]

Generate a cylinder from a planar base curve

Parameters:
curveddg.datastructures.nets.net.SmoothNet

Planar curve.

axis0, 1, 2

Axis of the cylinder

name: str

Name of the surface.

Returns:
ddg.datastructures.nets.net.SmoothNet

Cylinder.

ddg.datastructures.nets.utils.cone(curve, cone_vertex, name='Cone')[source]

Generate a cone over a given cone.

Parameters:
curveddg.datastructures.nets.net.SmoothNet

Spatial curve.

cone_vertexnumpy.array

Coordinates of a point in space

name: str

Name of the surface.

Returns:
ddg.datastructures.nets.net.SmoothNet

Cone

Notes

  • The cone is generated by connecting all the pointes of the curve with the cone vertex.

ddg.datastructures.nets.utils.sample_interval(interval, sample, option='', atol=None, anchor=None)[source]

Sample an interval.

Parameters:
intervaltuple

tuple containing the boundaries of the interval

samplefloat, int or list

list is containing a float in the first, and int in the second entry Stepsize (or amount of samples if ‘t’ option is set). If given a list for compound sampling, the first entry is the stepsize, while the second is the total amount of samples.

optionstring (default=””)
Options for the sampling.

The supported options are:
‘t’otal amount of samples given
‘s’ymmetric sampling
‘p’eriodic
‘c’ompound sampling, both stepsize and amount of samples given

When option ‘c’ is set, the sampling will choose between the stepsize
and total amount according to the type of interval. In the case of an
unbounded interval, it will also cut off the interval similar to
bound_domain.

When option ‘s’ is set, the sampling will be fit symmetrically inside
the interval.
atolfloat or None (default=None)

Tolerance for the sampling. Is not used when ‘t’ is set or the interval is unbounded.

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.nonexact for details.

anchorfloat or None (default=None)

Point inside the interval. The sampling will be chosen such that the point is part of it.

Returns:
tuple
containing:
[0] the (modified) boundaries of the sampled interval
[1] amount of samples
[2] sampling function
Raises:
NotImplementedError

if given options are not compatible with eachother

ValueError

if sample is not compatible with the given options

See also

bound_domain
ddg.datastructures.nets.utils.coordinate_hypersurface(net, component, value=None)[source]

Generate the (parameterized) level set of a coordinate-direction.

Parameters:
netSmoothNet or DiscreteNet with rectangular domain

Source net.

componentnumpy.ndarray

Coordinate to set to a constant value.

valueValue for the chosen component of the domain.

If no value is given the output net will depend on the value as a Parameter.

Returns:
ddg.datastructures.nets.net.Net

The hypersurface as a net.

Notes

  • The hypersurface is generated by setting one coordinates to a constant given value.

ddg.datastructures.nets.utils.coordinate_line(net, point, direction)[source]

Gives a curve on the net starting at a point in a given direction.

Parameters:
netSmoothNet or DiscreteNet with rectangular domain

Given net.

pointIterable of Real

Point in the domain from where to start the curve.

directionnumpy.array, or int

Direction in the domain as an array, or component as int.

Returns:
ddg.datastructures.nets.net.Net

A line on the net.

Notes

  • If direction is given as an int, the periodicity of the net in the given direction is inherited by the curve.

ddg.datastructures.nets.utils.coordinate_lines(net, direction, sampling, anchor=None, atol=None)[source]

Get coordinate lines in a given coordinate direction.

Parameters:
netddg.datastructures.nets.net.SmoothNet

Given net (must be SmoothNet with rectangular domain).

directionint

Direction of the coordinate lines (component number).

samplinglist, int or float

See sample_smooth_domain

anchorlist, tuple or NONE

Point inside the domain of the net. The sampling will be chosen such that the point is part of it.

atolfloat or None (default=None)

Is used as tolerance for symmetric sampling. See: sample_interval

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.nonexact for details.

Returns:
ddg.datastructures.nets.net.NetCollection

Coordinate lines as a NetCollection.

Notes

  • They will be stepsize apart in all other directions.

  • A set anchor precedes symmetric sampling

ddg.datastructures.nets.utils.coordinate_grid(net, sampling, anchor=None, atol=None)[source]

Get a grid of your net of given sampling (fineness in each direction)

Parameters:
net: ddg.datastructures.nets.net.SmoothNet

Given net (must be SmoothNet with RectangularDomain).

samplinglist, int or float

Determines how the domain is sampled. See sample_smooth_domain.

anchornumpy.ndarray, or None

Point inside the domain of the net. The sampling will be chosen such that the point is part of it.

atolfloat or None (default=None)

Is used as tolerance for symmetric sampling. See: sample_interval

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.nonexact for details.

Returns:
list of NetCollections of coordinate lines in every direction
ddg.datastructures.nets.utils.diagonal_lines(net, direction, sampling, anchor=None, atol=None)[source]

Get coordinate lines in a given coordinate direction.

Parameters:
netddg.datastructures.nets.net.SmoothNet

Given 2-dim net (must be SmoothNet with rectangular domain). Only works for bounded nets.

direction: np.array of dim 2

vector consisting of 1 and -1, determining the direction of the diagonals

samplinglist of length 2 of form [number, “option”] or float (stepsize)

See ddg.datastructures.nets.conversion.sample_smooth_domain

anchornumpy.ndarray, or None

Point inside the domain of the net. The sampling will be chosen such that the point is part of it.

atolfloat or None (default=None)

Is used as tolerance for symmetric sampling. See: sample_interval

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.nonexact for details.

Returns:
ddg.datastructures.nets.net.NetCollection

Coordinate lines as a NetCollection.

Notes

  • They will be stepsize apart in all other directions.

  • A set anchor precedes symmetric sampling

ddg.datastructures.nets.utils.octahedral_grid(net, stepsize, anchor=None, atol=None)[source]

Get diagonal lines in each diagonal direction of the coordinate planes of the domain

Parameters:
netddg.datastructures.nets.net.SmoothNet

Given 3-dimensional net (must be SmoothNet with rectangular domain).

stepsizeint or float

Determines the length of the diagonal of the occuring squares.

anchornumpy.ndarray of dimension 3, or None

Point inside the domain of the net. The sampling will be chosen such that the point is part of it.

atolfloat or None (default=None)

Is used as tolerance for symmetric sampling. See: sample_interval

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.nonexact for details.

Returns:
list of NetCollections
ddg.datastructures.nets.net.NetCollection

Diagonal lines as a NetCollection.

ddg.datastructures.nets.utils.shrink_domain(domain, amount)[source]

Shrinks domain by a given amount from the left and right.

Parameters:
domainddg.datastructures.nets.domain.DiscreteRectangularDomain or SmoothRectangularDomain

Domain to shrink, or a net to take the domain from.

amountlist or float
Specifies how much is taken away in each direction from the domain:
* float - value to take away from left and right in every direction
* list - every entry in the list corresponds to one direction,
and may be None, int, or a tuple of int or None.
Returns:
ddg.datastructures.nets.domain.Domain

Shrunken domain, if the domain was given.

ddg.datastructures.nets.net.Net

The input discrete net containing the new shrunken domain, if the net was given.

Notes

  • Only bounded directions will be shrunken.

  • Periodicity is inherited only for the directions that are not shrunken.

ddg.datastructures.nets.utils.bound_domain(domain, bounding)[source]
Parameters:
domainddg.datastructures.nets.domain.Smooth/DiscreteRectangularDomain or ddg.datastructures.nets.net.Smooth/DiscreteNet

Given (unbounded) rectangular domain to bound, or net whose domain is to be bound

boundingint/float
Bounding range.
If an interval (a,b) in the domain is unbounded,
we bound it in the smooth case by
(1) [a, a+bounding], if a > -inf
(2) [b-bounding, b], if b < inf, or
(3) [-bounding/2, bounding/2] if a == -inf and b == inf.

In the discrete case, bounding is the total amount of points chosen in
an unbounded direction.
(1) [a, a+bounding-1], if a > -inf
(2) [b-bounding+1, b], if b < inf, or
(3) [1-bounding/2, bounding/2] if a == -inf and b == inf.
Returns:
ddg.datastructures.nets.domain.Smooth/DiscreteRectangularDomain or ddg.datastructures.nets.net.Smooth/DiscreteNet

Will be the same type as domain, e.g. a discrete/smooth rectangular domain, if domain was discrete/smooth rectangular domain.

ddg.datastructures.nets.utils.create_subdomain(domain, subdomain)[source]

Create subdomain of a given discrete domain.

WARNING:

To assure that the output is always a subdomain of the given domain, subdomain will be intersected with the domain.

Parameters:
domainddg.datastructures.nets.domain.DiscreteRectangularDomain

Given domain to reduce to a subdomain, or net.

subdomainlist, or DiscreteDomain
Each entry in the list corresponds to a direction:
* int - number of values to take
* tuple - subdomain in given direction
If a DiscreteDomain is given, it will just be returned as is.
Returns:
ddg.datastrucuters.nets.domain.DiscreteRectangularDomain

Subdomain.

ddg.datastructures.nets.net.Net

A discrete net containing the new shrunken domain, if the net was given.

ddg.datastructures.nets.utils.continue_by_reflection(net, direction, reflection, invertdirection=False)[source]

Continue a net by reflection.

Given a net, direction and reflection, the function returns a net with an expanded domain in direction direction. Points outside the domain of the orignal domain will be mapped to a point corresponding to it inside of the domain before the new net evaluates first the function of the original net before applying the reflection.

Parameters:
netddg.datastructures.nets.net.SmoothNet or DiscreteNet

Net to continue by reflection

directionint

Direction in which the domain will be expanded. Points outside the original domain will be mapped to the point corresponding to it and the reflection will be applied after the function was evalued

reflectionint, Iterable, function
If given an integer or an Iterable containing integers, reflection
determines the coordinates changing sign after the original net is
evalued at the point corresponding to the one given outside the
original domain, e.g. for a point p outside of the original domain
corresponding to p~ and reflect the function given by the int/Iterable

newNet(p) == reflect(net(p~))

If a function is given, it will be used instead.

WARNING:
In case a function is given, it will not be checked if it can
accept the output of the net or not.
invertdirectionbool, optional

If set to False, the domain will be expanded in positive direction If set to True, the domain will be expanded in negative direction

Returns:
ddg.datastructures.nets.net.Net

Same type as net

Raises:
IndexError

If direction is not in range of domain dimension

TypeError

If reflection is neither an int, Iterable or function

Examples

>>> import numpy as np
>>> from ddg.datastructures.nets.net import SmoothNet
>>> from ddg.datastructures.nets.utils import continue_by_reflection
>>> net = SmoothNet(lambda *a: np.array(a), [[0, 2]] * 2)
>>> reflectionnet = continue_by_reflection(net, 0, 0)
>>> reflectionnet(3, 0)
array([-1,  0])
ddg.datastructures.nets.utils.concatenate(net, fct)[source]

Create a net which’s function is the conatenation of the function of the original net and fct and has the same domain as the original.

Parameters:
netddg.datastructures.nets.Net or subclass of it

Net with compatible function for fct

fctfunction

Function to concatenate with the net function

Returns:
ddg.datastructures.nets.Net

Exact type is the same as given net

ddg.datastructures.nets.utils.evaluate(net)[source]

Evaluate a discrete net on its entire domain.

This should NOT replace net[net.domain]. Instead use this function if the function of a net has effects outside it, i.e. when a net creates blender object and link them to the scene on its own.

Parameters:
netddg.datastructures.nets.net.DiscreteNet or subclass of it
Returns:
0

If successfull

Raises:
TypeError

if net was not a (subclass of) ddg.datastructures.nets.net.DiscreteNet

ddg.datastructures.nets.utils.delete_direction(domain, direction)[source]

Delete one direction of a domain.

Parameters:
domain: SmoothRectangularDomain or Discrete RectangularDomain

may be parametrized

direction: int
Returns:
domain

of same class of one dimension less

ddg.datastructures.nets.utils.modify_direction(domain, direction, new_interval)[source]
ddg.datastructures.nets.utils.cut_bounding_box(curve, bounding_box=(inf, inf, inf))[source]

Cuts the curve within the given bounding box.

  • only works for curves with infinite domain

  • works best for curves with small sample size (no additional points on the boundary of the bounding_box are set)

Parameters:
curveddg.DiscreteCurve

curve to be cut

bounding_boxiterable of three floats

distances of planes parallel to the coordinate planes For each given entry the curve is cut in positive and negative direction.

Returns:
ddg.NetCollection

NetCollection of the remaining segments of the curve

Raises:
ValueError

if the curves domain is infinite