klampt.model.geometry module¶
Utility functions for operating on geometry. See the Geometry3D
documentation for the core geometry class.
New in version 0.8.6.
[functions moved here from klampt.model.sensing
]
Working with geometric primitives¶
box()
and sphere()
are aliases for the functions in
klampt.model.create.primitives
.
Working with point clouds¶
point_cloud_normals()
estimates normals from a normal-free
PointCloud
.
The fit_plane()
, fit_plane3()
, and PlaneFitter
class help
with plane estimation.
point_cloud_simplify()
simplifies a PointCloud.
point_cloud_colors()
and point_cloud_set_colors()
sets / gets
colors from a PointCloud.
-
class
klampt.model.geometry.
PlaneFitter
(points=None)[source]¶ Bases:
object
Online fitting of planes through 3D point clouds
-
normal
¶ best-fit normal
- Type
3-vector
-
centroid
¶ centroid of points
- Type
3-vector
-
count
¶ # of points
- Type
int
-
sse
¶ fitting sum of squared errors
- Type
float
-
cov
¶ covariance of points
- Type
3x3 array
-
-
klampt.model.geometry.
box
(width, depth, height, center=None, R=None, t=None, world=None, name=None, mass=inf, type='TriangleMesh')[source]¶ Alias for
klampt.model.create.primitives.box()
-
klampt.model.geometry.
fit_plane
(points)[source]¶ Returns a 3D plane equation that is a least squares fit through the points (len(points) >= 3).
-
klampt.model.geometry.
fit_plane3
(point1, point2, point3)[source]¶ Returns a 3D plane equation fitting the 3 points.
The result is (a,b,c,d) with the plane equation ax+by+cz+d=0
-
klampt.model.geometry.
fit_plane_centroid
(points)[source]¶ Similar to
fit_plane()
, but returns a (centroid,normal) pair.
-
klampt.model.geometry.
point_cloud_colors
(pc, format='rgb')[source]¶ Returns the colors of the point cloud in the given format. If the point cloud has no colors, this returns None. If the point cloud has no colors but has opacity, this returns white colors.
- Parameters
pc (PointCloud) – the point cloud
format –
describes the output color format, either:
’rgb’: packed 24bit int, with the hex format 0xrrggbb,
’bgr’: packed 24bit int, with the hex format 0xbbggrr,
’rgba’: packed 32bit int, with the hex format 0xrrggbbaa,
’bgra’: packed 32bit int, with the hex format 0xbbggrraa,
’argb’: packed 32bit int, with the hex format 0xaarrggbb,
’abgr’: packed 32bit int, with the hex format 0xaabbggrr,
(‘r’,’g’,’b’): triple with each channel in range [0,1]
(‘r’,’g’,’b’,’a’): tuple with each channel in range [0,1]
- ’channels’: returns a list of channels, in the form (r,g,b) or
(r,g,b,a), where each value in the channel has range [0,1].
’opacity’: returns opacity only, in the range [0,1].
- Returns
- A list of pc.numPoints() colors corresponding to the points
in the point cloud. If format=’channels’, the return value is a tuple (r,g,b) or (r,g,b,a).
- Return type
list
-
klampt.model.geometry.
point_cloud_normals
(pc, estimation_radius=None, estimation_knn=None, estimation_viewpoint=None, add=True)[source]¶ Returns the normals of the point cloud. If pc has the standard
normal_x, normal_y, normal_z
properties, these will be returned. Otherwise, they will be estimated using plane fitting.The plane fitting method uses scipy nearest neighbor detection if scipy is available. Otherwise it uses a spatial grid. The process is as follows:
If
estimation_radius
is provided, then it will use neighbors within this range. For a spatial grid, this is the grid size.If
estimation_knn
is provided, then planes will be fit to these number of neighbors.If neither is provided, then estimation_radius is set to 3 * max dimension of the point cloud / sqrt(N).
If not enough points are within a neighborhood (either 4 or
estimation_knn
, whichever is larger), then the normal is set to 0.If
estimation_viewpoint
is provided, this must be a 3-list. The normals are oriented such that they point toward the viewpoint.
- Returns
A list of N 3-lists, or an N x 3 numpy array if numpy is available.
If
add=True
, estimated normals will be added to the point cloud under thenormal_x, normal_y, normal_z
properties.
-
klampt.model.geometry.
point_cloud_set_colors
(pc, colors, color_format='rgb', pc_property='auto')[source]¶ Sets the colors of a point cloud.
- Parameters
pc (PointCloud) – the point cloud
colors (list) – the list of colors, which can be either ints, tuples, or channels, depending on color_format.
color_format –
describes the format of each element of
colors
, and can be:’rgb’: packed 24bit int, with the hex format 0xrrggbb,
’bgr’: packed 24bit int, with the hex format 0xbbggrr,
’rgba’: packed 32bit int, with the hex format 0xrrggbbaa,
’bgra’: packed 32bit int, with the hex format 0xbbggrraa,
’argb’: packed 32bit int, with the hex format 0xaarrggbb,
’abgr’: packed 32bit int, with the hex format 0xaabbggrr,
(‘r’,’g’,’b’): triple with each channel in range [0,1]
(‘r’,’g’,’b’,’a’): tuple with each channel in range [0,1]
- ’channels’:
colors
is a list of channels, in the form (r,g,b) or (r,g,b,a), where each value in the channel has range [0,1].
- ’channels’:
’opacity’: opacity only, in the range [0,1].
pc_property (str) – describes to which property the colors should be set. ‘auto’ determines chooses the property from the point cloud if it’s already colored, or color_format if not. ‘channels’ sets the ‘r’, ‘g’, ‘b’, and optionally ‘a’ properties.
- Returns
None
-
klampt.model.geometry.
point_cloud_simplify
(pc, radius)[source]¶ Simplifies a point cloud by averaging points within neighborhoods. Uses a fast hash grid data structure.
- Parameters
pc (Geometry3D or PointCloud) – the point cloud
radius (float) – the neighborhood radius.
-
klampt.model.geometry.
sphere
(radius, center=None, R=None, t=None, world=None, name=None, mass=inf, type='TriangleMesh')[source]¶ Alias for
klampt.model.create.primitives.sphere()