Point Cloud Functions

This group of functions works with clouds of points – imported, or made from a MeshGeom such as the one a planar slice produces – and narrows them down to the points wanted. In the GUI a cloud is whittled down by selecting and hiding points with the mouse, which projects a screen rectangle into three dimensions and is only as good as that projection. Through the API the points are handed about as plain vectors of coordinates and filtered by where they actually are, which is both exact and repeatable. Filters come in keep and remove pairs, so a selection is inverted by asking for the other one, and there are set operations for combining the results.

CreatePtCloudGeomFromPts(pt_vec, name)

Make a Point Cloud Geom out of a set of points.

KeepPtsInBBox(pt_vec, min_pt, max_pt)

Keep the points inside an axis aligned box.

RemovePtsInBBox(pt_vec, min_pt, max_pt)

Drop the points inside an axis aligned box, keeping the rest.

KeepPtsInRange(pt_vec, dir_index, low, high)

Keep the points whose coordinate along one axis falls between two values, inclusive.

RemovePtsInRange(pt_vec, dir_index, low, high)

Drop the points whose coordinate along one axis falls between two values, keeping the rest.

KeepPtsAbove(pt_vec, dir_index, val)

Keep the points whose coordinate along one axis is greater than a value.

KeepPtsBelow(pt_vec, dir_index, val)

Keep the points whose coordinate along one axis is less than or equal to a value.

KeepPtsNearPt(pt_vec, center, radius)

Keep the points within a distance of a given point.

RemovePtsNearPt(pt_vec, center, radius)

Drop the points within a distance of a given point, keeping the rest.

KeepPtsNearGeom(pt_vec, geom_id, surf_indx, tol)

Keep the points lying within tol of a surface.

RemovePtsNearGeom(pt_vec, geom_id, ...)

Drop the points lying within tol of a surface, keeping the rest.

UniquePts(pt_vec, tol)

Drop the repeated points of a set, keeping one of each group that falls within tol of one another.

UnionPts(pt_vec_a, pt_vec_b, tol)

Put two sets of points together, keeping one of any that fall within tol of one another.

IntersectPts(pt_vec_a, pt_vec_b, tol)

Keep the points of the first set that also appear, within tol, in the second.

SubtractPts(pt_vec_a, pt_vec_b, tol)

Keep the points of the first set that do not appear, within tol, in the second.

CreatePtCloudGeom(geom_id)

Make a Point Cloud Geom out of the vertices of a MeshGeom.

Details

openvsp.CreatePtCloudGeomFromPts(pt_vec, name)[source]

Make a Point Cloud Geom out of a set of points. This is how a set worked out in a script is put back into the model, so it can be looked at in the GUI and saved with the file. The counterpart of GetPtCloudPnts.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
cloud_id = CreatePtCloudGeomFromPts( pts, "ScriptCloud" )

assert len( GetPtCloudPnts( cloud_id ) ) == 4, "CreatePtCloudGeomFromPts did not keep the points"

See also: GetPtCloudPnts, CreatePtCloudGeom :param [in]: pt_vec vector<vec3d> Points to place in the new Geom :param [in]: name string Name for the new Geom, or an empty string for the default :rtype: string :return: string Geom ID of the new Point Cloud Geom

openvsp.KeepPtsInBBox(pt_vec, min_pt, max_pt)[source]

Keep the points inside an axis aligned box. This is what the GUI’s rectangle selection is reaching for, done in three dimensions rather than through a screen projection.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
inside = KeepPtsInBBox( pts, vec3d( 1.0, -1.0, -1.0 ), vec3d( 5.0, 1.0, 1.0 ) )

assert len( inside ) == 2, "KeepPtsInBBox did not keep the points inside the box"

See also: RemovePtsInBBox, KeepPtsInRange :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: min_pt vec3d Corner of the box with the smallest coordinates :param [in]: max_pt vec3d Corner of the box with the largest coordinates :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points inside the box

openvsp.RemovePtsInBBox(pt_vec, min_pt, max_pt)[source]

Drop the points inside an axis aligned box, keeping the rest. The complement of KeepPtsInBBox, which is how a selection is inverted.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
outside = RemovePtsInBBox( pts, vec3d( 1.0, -1.0, -1.0 ), vec3d( 5.0, 1.0, 1.0 ) )

assert len( outside ) == 2, "RemovePtsInBBox did not drop the points inside the box"

See also: KeepPtsInBBox :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: min_pt vec3d Corner of the box with the smallest coordinates :param [in]: max_pt vec3d Corner of the box with the largest coordinates :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points outside the box

openvsp.KeepPtsInRange(pt_vec, dir_index, low, high)[source]

Keep the points whose coordinate along one axis falls between two values, inclusive.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
mid = KeepPtsInRange( pts, X_DIR, 1.0, 5.0 )

assert len( mid ) == 2, "KeepPtsInRange did not keep the points in range"

See also: RemovePtsInRange, KeepPtsAbove, KeepPtsBelow :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: dir_index int Direction index enum (i.e. X_DIR) :param [in]: low double Lowest coordinate to keep :param [in]: high double Highest coordinate to keep :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points within the range

openvsp.RemovePtsInRange(pt_vec, dir_index, low, high)[source]

Drop the points whose coordinate along one axis falls between two values, keeping the rest.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
ends = RemovePtsInRange( pts, X_DIR, 1.0, 5.0 )

assert len( ends ) == 2, "RemovePtsInRange did not drop the points in range"

See also: KeepPtsInRange :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: dir_index int Direction index enum (i.e. X_DIR) :param [in]: low double Lowest coordinate to drop :param [in]: high double Highest coordinate to drop :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points outside the range

openvsp.KeepPtsAbove(pt_vec, dir_index, val)[source]

Keep the points whose coordinate along one axis is greater than a value. Together with KeepPtsBelow this splits a set in two: the two answers are complements, so no separate remove call is wanted.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
aft = KeepPtsAbove( pts, X_DIR, 3.0 )

assert len( aft ) == 2, "KeepPtsAbove did not keep the points above the value"

See also: KeepPtsBelow, KeepPtsInRange :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: dir_index int Direction index enum (i.e. X_DIR) :param [in]: val double Value to compare against :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points above the value

openvsp.KeepPtsBelow(pt_vec, dir_index, val)[source]

Keep the points whose coordinate along one axis is less than or equal to a value. The complement of KeepPtsAbove.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
fwd = KeepPtsBelow( pts, X_DIR, 3.0 )

assert len( fwd ) == 2, "KeepPtsBelow did not keep the points below the value"

See also: KeepPtsAbove, KeepPtsInRange :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: dir_index int Direction index enum (i.e. X_DIR) :param [in]: val double Value to compare against :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points at or below the value

openvsp.KeepPtsNearPt(pt_vec, center, radius)[source]

Keep the points within a distance of a given point.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
near = KeepPtsNearPt( pts, vec3d( 4.0, 0.0, 0.0 ), 1.0 )

assert len( near ) == 1, "KeepPtsNearPt did not keep the points near the point"

See also: RemovePtsNearPt :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: center vec3d Point to measure from :param [in]: radius double Distance within which to keep points :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points within the radius

openvsp.RemovePtsNearPt(pt_vec, center, radius)[source]

Drop the points within a distance of a given point, keeping the rest.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
far = RemovePtsNearPt( pts, vec3d( 4.0, 0.0, 0.0 ), 1.0 )

assert len( far ) == 3, "RemovePtsNearPt did not drop the points near the point"

See also: KeepPtsNearPt :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: center vec3d Point to measure from :param [in]: radius double Distance within which to drop points :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points outside the radius

openvsp.KeepPtsNearGeom(pt_vec, geom_id, surf_indx, tol)[source]

Keep the points lying within tol of a surface. This narrows a cloud – a slice through a whole model, say – down to the component being fitted. Unlike the other filters this one costs a surface projection for every point rather than a comparison, so on a large cloud it is worth cutting the set down with one of the cheap filters first.

pid = AddGeom( "POD" )

Update()

pts = []

pts.append( CompPnt01( pid, 0, 0.5, 0.25 ) )
pts.append( vec3d( 0.0, 100.0, 0.0 ) )

on_body = KeepPtsNearGeom( pts, pid, 0, 1e-4 )

assert len( on_body ) == 1, "KeepPtsNearGeom did not keep the point on the surface"

See also: RemovePtsNearGeom, KeepPtsInBBox :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: geom_id string Geom ID of the surface to measure against :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: tol double Distance within which to keep points :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points lying within tol of the surface

openvsp.RemovePtsNearGeom(pt_vec, geom_id, surf_indx, tol)[source]

Drop the points lying within tol of a surface, keeping the rest. Useful for taking one component’s points out of a cloud that covers several. Costs a surface projection per point.

pid = AddGeom( "POD" )

Update()

pts = []

pts.append( CompPnt01( pid, 0, 0.5, 0.25 ) )
pts.append( vec3d( 0.0, 100.0, 0.0 ) )

off_body = RemovePtsNearGeom( pts, pid, 0, 1e-4 )

assert len( off_body ) == 1, "RemovePtsNearGeom did not drop the point on the surface"

See also: KeepPtsNearGeom :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: geom_id string Geom ID of the surface to measure against :param [in]: surf_indx int Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1 :param [in]: tol double Distance within which to drop points :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points lying further than tol from the surface

openvsp.UniquePts(pt_vec, tol)[source]

Drop the repeated points of a set, keeping one of each group that falls within tol of one another. Answered with a spatial tree rather than by comparing every pair.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
twice = pts + pts

once = UniquePts( twice, 1e-8 )

assert len( once ) == 4, "UniquePts did not drop the repeats"

See also: UnionPts :param [in]: pt_vec vector<vec3d> Points to filter :param [in]: tol double Distance within which two points count as the same point :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points with the repeats removed

openvsp.UnionPts(pt_vec_a, pt_vec_b, tol)[source]

Put two sets of points together, keeping one of any that fall within tol of one another.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
fwd = KeepPtsBelow( pts, X_DIR, 3.0 )
aft = KeepPtsAbove( pts, X_DIR, 3.0 )

all_pts = UnionPts( fwd, aft, 1e-8 )

assert len( all_pts ) == 4, "UnionPts did not put the two halves back together"

See also: SubtractPts, IntersectPts, UniquePts :param [in]: pt_vec_a vector<vec3d> First set of points :param [in]: pt_vec_b vector<vec3d> Second set of points :param [in]: tol double Distance within which two points count as the same point :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points of either set

openvsp.IntersectPts(pt_vec_a, pt_vec_b, tol)[source]

Keep the points of the first set that also appear, within tol, in the second. Answered with a spatial tree over the second set rather than by comparing every pair.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
mid = KeepPtsInRange( pts, X_DIR, 1.0, 5.0 )

both = IntersectPts( pts, mid, 1e-8 )

assert len( both ) == 2, "IntersectPts did not keep the shared points"

See also: SubtractPts, UnionPts :param [in]: pt_vec_a vector<vec3d> Set to take points from :param [in]: pt_vec_b vector<vec3d> Set to test against :param [in]: tol double Distance within which two points count as the same point :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points of the first set that appear in the second

openvsp.SubtractPts(pt_vec_a, pt_vec_b, tol)[source]

Keep the points of the first set that do not appear, within tol, in the second. This is how a group already dealt with is taken back out of a working set.

pts = []

pts.append( vec3d( 0.0, 0.0, 0.0 ) )
pts.append( vec3d( 2.0, 0.0, 0.0 ) )
pts.append( vec3d( 4.0, 0.0, 0.0 ) )
pts.append( vec3d( 6.0, 0.0, 0.0 ) )
mid = KeepPtsInRange( pts, X_DIR, 1.0, 5.0 )

rest = SubtractPts( pts, mid, 1e-8 )

assert len( rest ) == 2, "SubtractPts did not remove the shared points"

See also: IntersectPts, UnionPts :param [in]: pt_vec_a vector<vec3d> Set to take points from :param [in]: pt_vec_b vector<vec3d> Set to remove :param [in]: tol double Distance within which two points count as the same point :rtype: std::vector< vec3d,std::allocator< vec3d > > :return: vector<vec3d> Points of the first set that do not appear in the second

openvsp.CreatePtCloudGeom(geom_id)[source]

Make a Point Cloud Geom out of the vertices of a MeshGeom. This is the Mesh screen’s Convert to Point Cloud button, and it is the usual way into a fit: take a planar slice of a model, which leaves a MeshGeom, and turn that into points to match.

pid = AddGeom( "POD" )

Update()

mesh_id = ComputePlaneSlice( SET_ALL, 3, vec3d( 1.0, 0.0, 0.0 ), True )

cloud_id = CreatePtCloudGeom( mesh_id )

assert len( GetPtCloudPnts( cloud_id ) ) > 0, "CreatePtCloudGeom made no points"

See also: GetPtCloudPnts, CreatePtCloudGeomFromPts, ComputePlaneSlice :param [in]: geom_id string MeshGeom ID to take the vertices of :rtype: string :return: string Geom ID of the new Point Cloud Geom