OpenVSP API Documentation 3.52.0
Loading...
Searching...
No Matches
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. Click here to return to the main page. More...

Functions

std::string vsp::CreatePtCloudGeomFromPts (const std::vector< vec3d > &pt_vec, const std::string &name)
std::vector< vec3dvsp::KeepPtsInBBox (const std::vector< vec3d > &pt_vec, const vec3d &min_pt, const vec3d &max_pt)
std::vector< vec3dvsp::RemovePtsInBBox (const std::vector< vec3d > &pt_vec, const vec3d &min_pt, const vec3d &max_pt)
std::vector< vec3dvsp::KeepPtsInRange (const std::vector< vec3d > &pt_vec, int dir_index, double low, double high)
std::vector< vec3dvsp::RemovePtsInRange (const std::vector< vec3d > &pt_vec, int dir_index, double low, double high)
std::vector< vec3dvsp::KeepPtsAbove (const std::vector< vec3d > &pt_vec, int dir_index, double val)
std::vector< vec3dvsp::KeepPtsBelow (const std::vector< vec3d > &pt_vec, int dir_index, double val)
std::vector< vec3dvsp::KeepPtsNearPt (const std::vector< vec3d > &pt_vec, const vec3d &center, double radius)
std::vector< vec3dvsp::RemovePtsNearPt (const std::vector< vec3d > &pt_vec, const vec3d &center, double radius)
std::vector< vec3dvsp::KeepPtsNearGeom (const std::vector< vec3d > &pt_vec, const std::string &geom_id, int surf_indx, double tol)
std::vector< vec3dvsp::RemovePtsNearGeom (const std::vector< vec3d > &pt_vec, const std::string &geom_id, int surf_indx, double tol)
std::vector< vec3dvsp::UniquePts (const std::vector< vec3d > &pt_vec, double tol)
std::vector< vec3dvsp::UnionPts (const std::vector< vec3d > &pt_vec_a, const std::vector< vec3d > &pt_vec_b, double tol)
std::vector< vec3dvsp::IntersectPts (const std::vector< vec3d > &pt_vec_a, const std::vector< vec3d > &pt_vec_b, double tol)
std::vector< vec3dvsp::SubtractPts (const std::vector< vec3d > &pt_vec_a, const std::vector< vec3d > &pt_vec_b, double tol)
std::string vsp::CreatePtCloudGeom (const std::string &geom_id)

Detailed Description

Function Documentation

◆ CreatePtCloudGeom()

std::string vsp::CreatePtCloudGeom ( const std::string & geom_id)
extern

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.

string pid = AddGeom( "POD" );
string mesh_id = ComputePlaneSlice( SET_ALL, 3, vec3d( 1.0, 0.0, 0.0 ), true );
string cloud_id = CreatePtCloudGeom( mesh_id );
if ( GetPtCloudPnts( cloud_id ).size() == 0 ) { Print( "ERROR: CreatePtCloudGeom" ); __failure++; }
void Print(const std::string &data, bool new_line=true)
std::string ComputePlaneSlice(int set, int num_slices, const vec3d &norm, bool auto_bnd, double start_bnd=0, double end_bnd=0, bool measureduct=false)
@ SET_ALL
std::vector< vec3d > GetPtCloudPnts(const std::string &geom_id)
std::string AddGeom(const std::string &type, const std::string &parent=std::string())
std::string CreatePtCloudGeom(const std::string &geom_id)
void Update(bool update_managers=true)
Definition Vec3d.h:238
See also
GetPtCloudPnts, CreatePtCloudGeomFromPts, ComputePlaneSlice
Parameters
[in]geom_idstring MeshGeom ID to take the vertices of
Returns
string Geom ID of the new Point Cloud Geom
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePtCloudGeomFromPts()

std::string vsp::CreatePtCloudGeomFromPts ( const std::vector< vec3d > & pt_vec,
const std::string & name )
extern

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.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
string cloud_id = CreatePtCloudGeomFromPts( pts, "ScriptCloud" );
if ( GetPtCloudPnts( cloud_id ).size() != 4 ) { Print( "ERROR: CreatePtCloudGeomFromPts" ); __failure++; }
std::string CreatePtCloudGeomFromPts(const std::vector< vec3d > &pt_vec, const std::string &name)
See also
GetPtCloudPnts, CreatePtCloudGeom
Parameters
[in]pt_vecvector<vec3d> Points to place in the new Geom
[in]namestring Name for the new Geom, or an empty string for the default
Returns
string Geom ID of the new Point Cloud Geom
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IntersectPts()

std::vector< vec3d > vsp::IntersectPts ( const std::vector< vec3d > & pt_vec_a,
const std::vector< vec3d > & pt_vec_b,
double tol )
extern

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.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > mid = KeepPtsInRange( pts, X_DIR, 1.0, 5.0 );
array < vec3d > both = IntersectPts( pts, mid, 1e-8 );
if ( both.size() != 2 ) { Print( "ERROR: IntersectPts" ); __failure++; }
@ X_DIR
Definition APIDefines.h:421
std::vector< vec3d > KeepPtsInRange(const std::vector< vec3d > &pt_vec, int dir_index, double low, double high)
std::vector< vec3d > IntersectPts(const std::vector< vec3d > &pt_vec_a, const std::vector< vec3d > &pt_vec_b, double tol)
See also
SubtractPts, UnionPts
Parameters
[in]pt_vec_avector<vec3d> Set to take points from
[in]pt_vec_bvector<vec3d> Set to test against
[in]toldouble Distance within which two points count as the same point
Returns
vector<vec3d> Points of the first set that appear in the second
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepPtsAbove()

std::vector< vec3d > vsp::KeepPtsAbove ( const std::vector< vec3d > & pt_vec,
int dir_index,
double val )
extern

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.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > aft = KeepPtsAbove( pts, X_DIR, 3.0 );
if ( aft.size() != 2 ) { Print( "ERROR: KeepPtsAbove" ); __failure++; }
std::vector< vec3d > KeepPtsAbove(const std::vector< vec3d > &pt_vec, int dir_index, double val)
See also
KeepPtsBelow, KeepPtsInRange
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]dir_indexint Direction index enum (i.e. X_DIR)
[in]valdouble Value to compare against
Returns
vector<vec3d> Points above the value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepPtsBelow()

std::vector< vec3d > vsp::KeepPtsBelow ( const std::vector< vec3d > & pt_vec,
int dir_index,
double val )
extern

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

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > fwd = KeepPtsBelow( pts, X_DIR, 3.0 );
if ( fwd.size() != 2 ) { Print( "ERROR: KeepPtsBelow" ); __failure++; }
std::vector< vec3d > KeepPtsBelow(const std::vector< vec3d > &pt_vec, int dir_index, double val)
See also
KeepPtsAbove, KeepPtsInRange
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]dir_indexint Direction index enum (i.e. X_DIR)
[in]valdouble Value to compare against
Returns
vector<vec3d> Points at or below the value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepPtsInBBox()

std::vector< vec3d > vsp::KeepPtsInBBox ( const std::vector< vec3d > & pt_vec,
const vec3d & min_pt,
const vec3d & max_pt )
extern

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.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > inside = KeepPtsInBBox( pts, vec3d( 1.0, -1.0, -1.0 ), vec3d( 5.0, 1.0, 1.0 ) );
if ( inside.size() != 2 ) { Print( "ERROR: KeepPtsInBBox" ); __failure++; }
std::vector< vec3d > KeepPtsInBBox(const std::vector< vec3d > &pt_vec, const vec3d &min_pt, const vec3d &max_pt)
See also
RemovePtsInBBox, KeepPtsInRange
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]min_ptvec3d Corner of the box with the smallest coordinates
[in]max_ptvec3d Corner of the box with the largest coordinates
Returns
vector<vec3d> Points inside the box
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepPtsInRange()

std::vector< vec3d > vsp::KeepPtsInRange ( const std::vector< vec3d > & pt_vec,
int dir_index,
double low,
double high )
extern

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

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > mid = KeepPtsInRange( pts, X_DIR, 1.0, 5.0 );
if ( mid.size() != 2 ) { Print( "ERROR: KeepPtsInRange" ); __failure++; }
See also
RemovePtsInRange, KeepPtsAbove, KeepPtsBelow
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]dir_indexint Direction index enum (i.e. X_DIR)
[in]lowdouble Lowest coordinate to keep
[in]highdouble Highest coordinate to keep
Returns
vector<vec3d> Points within the range
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepPtsNearGeom()

std::vector< vec3d > vsp::KeepPtsNearGeom ( const std::vector< vec3d > & pt_vec,
const std::string & geom_id,
int surf_indx,
double tol )
extern

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.

string pid = AddGeom( "POD" );
array < vec3d > pts;
pts.push_back( CompPnt01( pid, 0, 0.5, 0.25 ) );
pts.push_back( vec3d( 0.0, 100.0, 0.0 ) );
array < vec3d > on_body = KeepPtsNearGeom( pts, pid, 0, 1e-4 );
if ( on_body.size() != 1 ) { Print( "ERROR: KeepPtsNearGeom" ); __failure++; }
std::vector< vec3d > KeepPtsNearGeom(const std::vector< vec3d > &pt_vec, const std::string &geom_id, int surf_indx, double tol)
vec3d CompPnt01(const std::string &geom_id, const int &surf_indx, const double &u, const double &w)
See also
RemovePtsNearGeom, KeepPtsInBBox
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]geom_idstring Geom ID of the surface to measure against
[in]surf_indxint Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1
[in]toldouble Distance within which to keep points
Returns
vector<vec3d> Points lying within tol of the surface
Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepPtsNearPt()

std::vector< vec3d > vsp::KeepPtsNearPt ( const std::vector< vec3d > & pt_vec,
const vec3d & center,
double radius )
extern

Keep the points within a distance of a given point.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > near = KeepPtsNearPt( pts, vec3d( 4.0, 0.0, 0.0 ), 1.0 );
if ( near.size() != 1 ) { Print( "ERROR: KeepPtsNearPt" ); __failure++; }
std::vector< vec3d > KeepPtsNearPt(const std::vector< vec3d > &pt_vec, const vec3d &center, double radius)
See also
RemovePtsNearPt
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]centervec3d Point to measure from
[in]radiusdouble Distance within which to keep points
Returns
vector<vec3d> Points within the radius
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemovePtsInBBox()

std::vector< vec3d > vsp::RemovePtsInBBox ( const std::vector< vec3d > & pt_vec,
const vec3d & min_pt,
const vec3d & max_pt )
extern

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

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > outside = RemovePtsInBBox( pts, vec3d( 1.0, -1.0, -1.0 ), vec3d( 5.0, 1.0, 1.0 ) );
if ( outside.size() != 2 ) { Print( "ERROR: RemovePtsInBBox" ); __failure++; }
std::vector< vec3d > RemovePtsInBBox(const std::vector< vec3d > &pt_vec, const vec3d &min_pt, const vec3d &max_pt)
See also
KeepPtsInBBox
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]min_ptvec3d Corner of the box with the smallest coordinates
[in]max_ptvec3d Corner of the box with the largest coordinates
Returns
vector<vec3d> Points outside the box
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemovePtsInRange()

std::vector< vec3d > vsp::RemovePtsInRange ( const std::vector< vec3d > & pt_vec,
int dir_index,
double low,
double high )
extern

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

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > ends = RemovePtsInRange( pts, X_DIR, 1.0, 5.0 );
if ( ends.size() != 2 ) { Print( "ERROR: RemovePtsInRange" ); __failure++; }
std::vector< vec3d > RemovePtsInRange(const std::vector< vec3d > &pt_vec, int dir_index, double low, double high)
See also
KeepPtsInRange
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]dir_indexint Direction index enum (i.e. X_DIR)
[in]lowdouble Lowest coordinate to drop
[in]highdouble Highest coordinate to drop
Returns
vector<vec3d> Points outside the range
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemovePtsNearGeom()

std::vector< vec3d > vsp::RemovePtsNearGeom ( const std::vector< vec3d > & pt_vec,
const std::string & geom_id,
int surf_indx,
double tol )
extern

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.

string pid = AddGeom( "POD" );
array < vec3d > pts;
pts.push_back( CompPnt01( pid, 0, 0.5, 0.25 ) );
pts.push_back( vec3d( 0.0, 100.0, 0.0 ) );
array < vec3d > off_body = RemovePtsNearGeom( pts, pid, 0, 1e-4 );
if ( off_body.size() != 1 ) { Print( "ERROR: RemovePtsNearGeom" ); __failure++; }
std::vector< vec3d > RemovePtsNearGeom(const std::vector< vec3d > &pt_vec, const std::string &geom_id, int surf_indx, double tol)
See also
KeepPtsNearGeom
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]geom_idstring Geom ID of the surface to measure against
[in]surf_indxint Index of the surface of that Geom, from 0 to GetNumTotalSurfs() - 1
[in]toldouble Distance within which to drop points
Returns
vector<vec3d> Points lying further than tol from the surface
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemovePtsNearPt()

std::vector< vec3d > vsp::RemovePtsNearPt ( const std::vector< vec3d > & pt_vec,
const vec3d & center,
double radius )
extern

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

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > far = RemovePtsNearPt( pts, vec3d( 4.0, 0.0, 0.0 ), 1.0 );
if ( far.size() != 3 ) { Print( "ERROR: RemovePtsNearPt" ); __failure++; }
std::vector< vec3d > RemovePtsNearPt(const std::vector< vec3d > &pt_vec, const vec3d &center, double radius)
See also
KeepPtsNearPt
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]centervec3d Point to measure from
[in]radiusdouble Distance within which to drop points
Returns
vector<vec3d> Points outside the radius
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SubtractPts()

std::vector< vec3d > vsp::SubtractPts ( const std::vector< vec3d > & pt_vec_a,
const std::vector< vec3d > & pt_vec_b,
double tol )
extern

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.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > mid = KeepPtsInRange( pts, X_DIR, 1.0, 5.0 );
array < vec3d > rest = SubtractPts( pts, mid, 1e-8 );
if ( rest.size() != 2 ) { Print( "ERROR: SubtractPts" ); __failure++; }
std::vector< vec3d > SubtractPts(const std::vector< vec3d > &pt_vec_a, const std::vector< vec3d > &pt_vec_b, double tol)
See also
IntersectPts, UnionPts
Parameters
[in]pt_vec_avector<vec3d> Set to take points from
[in]pt_vec_bvector<vec3d> Set to remove
[in]toldouble Distance within which two points count as the same point
Returns
vector<vec3d> Points of the first set that do not appear in the second
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnionPts()

std::vector< vec3d > vsp::UnionPts ( const std::vector< vec3d > & pt_vec_a,
const std::vector< vec3d > & pt_vec_b,
double tol )
extern

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

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > fwd = KeepPtsBelow( pts, X_DIR, 3.0 );
array < vec3d > aft = KeepPtsAbove( pts, X_DIR, 3.0 );
array < vec3d > all = UnionPts( fwd, aft, 1e-8 );
if ( all.size() != 4 ) { Print( "ERROR: UnionPts" ); __failure++; }
std::vector< vec3d > UnionPts(const std::vector< vec3d > &pt_vec_a, const std::vector< vec3d > &pt_vec_b, double tol)
See also
SubtractPts, IntersectPts, UniquePts
Parameters
[in]pt_vec_avector<vec3d> First set of points
[in]pt_vec_bvector<vec3d> Second set of points
[in]toldouble Distance within which two points count as the same point
Returns
vector<vec3d> Points of either set
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UniquePts()

std::vector< vec3d > vsp::UniquePts ( const std::vector< vec3d > & pt_vec,
double tol )
extern

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.

array < vec3d > pts;
pts.push_back( vec3d( 0.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 2.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 4.0, 0.0, 0.0 ) );
pts.push_back( vec3d( 6.0, 0.0, 0.0 ) );
array < vec3d > twice;
for ( int i = 0 ; i < int( pts.size() ) ; i++ )
{
twice.push_back( pts[i] );
twice.push_back( pts[i] );
}
array < vec3d > once = UniquePts( twice, 1e-8 );
if ( once.size() != 4 ) { Print( "ERROR: UniquePts" ); __failure++; }
std::vector< vec3d > UniquePts(const std::vector< vec3d > &pt_vec, double tol)
See also
UnionPts
Parameters
[in]pt_vecvector<vec3d> Points to filter
[in]toldouble Distance within which two points count as the same point
Returns
vector<vec3d> Points with the repeats removed
Here is the call graph for this function:
Here is the caller graph for this function: