class
aicafe.PointSet (np.ndarray)
This class represents a set of coordinates (points) in a 3D space. The points are supposed to be arranged regularly to form a grid.
It is a subclass of Numpy's
ndarray, and thus supports all Numpy
functions, methods, and attributes, but also has some additional methods and attributes.
To initialize a point set, see __new__() below.
By default, its shape is [..., 3], where [3] indicates the dimension, and [...] indicates the shape of the
grid, such as [10] or [3, 5]. For example, a PointSet instance with shape of [2, 4, 3] contains the
coordinates of 3D points located on a \(2\times4\) grid.
__new__(cls, array)
To initialize a point set, simply generate an
ArrayLike
data structure, and then pass it to __new__.
No __init__ method is needed because the point set is fully initialized after the __new__ method.
Examples:
You can initialize a point set using numpy array:
or using a list:
The shape of input must be or can be reshaped to [..., 3]. For example, you can input a 1-D list with
length of 6 to get a point set with shape of [2, 3]:
Keep the last dimension equal to 3
There is no restriction on changing the last dimension from 3 to any other number.
However, all methods and properties of a point set are designed to work only when the last dimension is 3.
Therefore, if you want to apply some numpy function or operation to a point set and expect the result
is still a valid instance of PointSet, take care to make sure that the result still has shape of [... , 3].
Returns:
| Type | Description |
|---|---|
PointSet[float]
|
Initialized point set. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
angle(self, p, unit='radian')
Compute the angle of self and p. Both must be able to be broadcast together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
NDArray
|
Shape |
required |
unit
|
str
|
The unit of the result, |
'radian'
|
Returns:
| Type | Description |
|---|---|
np.ndarray
|
Array with broadcast shape. E.g., when self's shape is |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
distance(self, p)
Compute the distances from self to p. See aicafe.img.distance for full documentation.
distance2d(self, p)
Compute the distance from self to p in the x-y plane, i.e., the z coordinate will be regarded as 0. See aicafe.img.distance2d for full documentation.
id_float(self)
id_int(self)
in_box(self, box, allowance=0)
Determine if self is in a bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box
|
'ArrayLike'
|
|
required |
allowance
|
coordinate
|
Distance allowed for self to leave the box. |
0
|
Returns:
| Type | Description |
|---|---|
ndarray[bool]
|
Shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
in_img(self, shape)
Determine if self is in an image's coverage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[coordinate]
|
Image shape; must be 3D. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
ndarray[bool]:
Shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If image shape is not 3D. |
mod(self)
The moduli of vectors from the origin \((0, 0, 0)\) to the points in self. See aicafe.img.mod for the function with the same name.
Returns:
| Type | Description |
|---|---|
NDArray
|
Shape of |
n_points(self)
The number of points in self.
normalize(self)
Normalized self. See aicafe.img.normalize for full documentation.
product(self, p)
Compute the dot product of self and p. Both must be able to be broadcast together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
NDArray
|
Shape [..., 3], array of 3D coordinates. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Array with broadcast shape. E.g., when self's shape is |
round(self, decimals=0)
Return a point set with each element rounded to the given number of decimals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimals
|
int
|
Number of decimal places to round to. If it is negative, it specifies the number of positions to the left of the decimal point. |
0
|
Returns:
| Type | Description |
|---|---|
'PointSet'
|
Its each point equals to the corresponding point in self after np.round(decimals). |