Implicit fields
FieldGenerator objects are given to a PointSampler object to be called on all the sampled points.
Example
import implicitlab as IL
sampler = PointSampler(
geometry, # some loaded geometry
IL.sampling_strategy.UniformBox(geometry), # the sampling strategy
IL.fields.Occupancy(geometry, v_in=-1, v_out=1, v_on=-1) # the field to compute
)
points, field_values = sampler.sampler(10_000)
This example wil sample 10k points uniformly in a bounding box around the geometry object. It returns the points and an occupancy value for each point.
Available fields
Distance(geom, signed=True, square=False)
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Mesh
|
description |
required |
signed
|
bool
|
description. Defaults to True. |
True
|
square
|
bool
|
description. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
UnsupportedGeometryFormat
|
description |
Occupancy(geom, v_in, v_out, v_on)
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Mesh
|
description |
required |
v_in
|
float
|
description |
required |
v_out
|
float
|
description |
required |
v_on
|
float
|
description |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedGeometryFormat
|
description |
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
description |
WindingNumber(geom)
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Mesh
|
description |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedGeometryFormat
|
description |
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
description |
References
Nearest(geom)
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Mesh
|
description |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedGeometryFormat
|
description |
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
description |
Constant(value)
Bases: FieldGenerator
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
description |
required |
compute_on(query)
summary
Note
Defining this function is optional. By default, compute_on(query) returns the value of compute(query). Since values of a field are sometimes known for query points on the geometry (for instance: a distance field has value 0 on the surface), it can be useful to avoid the field computation and overwrite this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
ndarray
|
the query points |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: the value of the field at each query point. |
CustomFunction(fun, fun_on=None)
Bases: FieldGenerator
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun
|
Callable
|
description |
required |
fun_on
|
Callable
|
description. Defaults to None. |
None
|
Make your custom field
The list of possible fields can be expanded by writing a custom class that inherits from the base abstract class FieldGenerator.
FieldGenerator
Bases: ABC
Base class for an implicit field.
compute(query)
abstractmethod
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
ndarray
|
the query points |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: the value of the field at each query point |
compute_on(query)
summary
Note
Defining this function is optional. By default, compute_on(query) returns the value of compute(query). Since values of a field are sometimes known for query points on the geometry (for instance: a distance field has value 0 on the surface), it can be useful to avoid the field computation and overwrite this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
ndarray
|
the query points |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: the value of the field at each query point. |
The custom class only needs to define the compute method. Additionnally, the compute_on method can be provided.