Assimp v5.2.2 (January 2022)
The Asset-Importer-Lib API documentation.
Assimp::SpatialSort Class Reference

A little helper class to quickly find all vertices in the epsilon environment of a given position. More...

#include <SpatialSort.h>

Classes

struct  Entry
 An entry in a spatially sorted position array. More...
 

Public Member Functions

void Append (const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset, bool pFinalize=true)
 Same as Fill(), except the method appends to existing data in the SpatialSort. More...
 
void Fill (const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset, bool pFinalize=true)
 Sets the input data for the SpatialSort. More...
 
void Finalize ()
 Finalize the spatial hash data structure. More...
 
void FindIdenticalPositions (const aiVector3D &pPosition, std::vector< unsigned int > &poResults) const
 Fills an array with indices of all positions identical to the given position. More...
 
void FindPositions (const aiVector3D &pPosition, ai_real pRadius, std::vector< unsigned int > &poResults) const
 Returns an iterator for all positions close to the given position. More...
 
unsigned int GenerateMappingTable (std::vector< unsigned int > &fill, ai_real pRadius) const
 Compute a table that maps each vertex ID referring to a spatially close enough position to the same output ID. More...
 
 SpatialSort ()
 
 SpatialSort (const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset)
 Constructs a spatially sorted representation from the given position array. More...
 
 ~SpatialSort ()
 Destructor. More...
 

Protected Member Functions

ai_real CalculateDistance (const aiVector3D &pPosition) const
 Return the distance to the sorting plane. More...
 

Protected Attributes

aiVector3D mCentroid
 The centroid of the positions, which is used as a point on the sorting plane when calculating distance. More...
 
bool mFinalized
 false until the Finalize method is called. More...
 
aiVector3D mPlaneNormal
 Normal of the sorting plane, normalized. More...
 
std::vector< EntrymPositions
 

Detailed Description

A little helper class to quickly find all vertices in the epsilon environment of a given position.

Construct an instance with an array of positions. The class stores the given positions by their indices and sorts them by their distance to an arbitrary chosen plane. You can then query the instance for all vertices close to a given position in an average O(log n) time, with O(n) worst case complexity when all vertices lay on the plane. The plane is chosen so that it avoids common planes in usual data sets.

Constructor & Destructor Documentation

◆ SpatialSort() [1/2]

Assimp::SpatialSort::SpatialSort ( )

◆ SpatialSort() [2/2]

Assimp::SpatialSort::SpatialSort ( const aiVector3D pPositions,
unsigned int  pNumPositions,
unsigned int  pElementOffset 
)

Constructs a spatially sorted representation from the given position array.

Supply the positions in its layout in memory, the class will only refer to them by index.

Parameters
pPositionsPointer to the first position vector of the array.
pNumPositionsNumber of vectors to expect in that array.
pElementOffsetOffset in bytes from the beginning of one vector in memory to the beginning of the next vector.

◆ ~SpatialSort()

Assimp::SpatialSort::~SpatialSort ( )

Destructor.

Member Function Documentation

◆ Append()

void Assimp::SpatialSort::Append ( const aiVector3D pPositions,
unsigned int  pNumPositions,
unsigned int  pElementOffset,
bool  pFinalize = true 
)

Same as Fill(), except the method appends to existing data in the SpatialSort.

◆ CalculateDistance()

ai_real Assimp::SpatialSort::CalculateDistance ( const aiVector3D pPosition) const
protected

Return the distance to the sorting plane.

◆ Fill()

void Assimp::SpatialSort::Fill ( const aiVector3D pPositions,
unsigned int  pNumPositions,
unsigned int  pElementOffset,
bool  pFinalize = true 
)

Sets the input data for the SpatialSort.

This replaces existing data, if any. The new data receives new indices in ascending order.

Parameters
pPositionsPointer to the first position vector of the array.
pNumPositionsNumber of vectors to expect in that array.
pElementOffsetOffset in bytes from the beginning of one vector in memory to the beginning of the next vector.
pFinalizeSpecifies whether the SpatialSort's internal representation is finalized after the new data has been added. Finalization is required in order to use #FindPosition() or GenerateMappingTable(). If you don't finalize yet, you can use Append() to add data from other sources.

◆ Finalize()

void Assimp::SpatialSort::Finalize ( )

Finalize the spatial hash data structure.

This can be useful after multiple calls to Append() with the pFinalize parameter set to false. This is finally required before one of FindPositions() and GenerateMappingTable() can be called to query the spatial sort.

◆ FindIdenticalPositions()

void Assimp::SpatialSort::FindIdenticalPositions ( const aiVector3D pPosition,
std::vector< unsigned int > &  poResults 
) const

Fills an array with indices of all positions identical to the given position.

In opposite to FindPositions(), not an epsilon is used but a (very low) tolerance of four floating-point units.

Parameters
pPositionThe position to look for vertices.
poResultsThe container to store the indices of the found positions. Will be emptied by the call so it may contain anything.

◆ FindPositions()

void Assimp::SpatialSort::FindPositions ( const aiVector3D pPosition,
ai_real  pRadius,
std::vector< unsigned int > &  poResults 
) const

Returns an iterator for all positions close to the given position.

Parameters
pPositionThe position to look for vertices.
pRadiusMaximal distance from the position a vertex may have to be counted in.
poResultsThe container to store the indices of the found positions. Will be emptied by the call so it may contain anything.
Returns
An iterator to iterate over all vertices in the given area.

◆ GenerateMappingTable()

unsigned int Assimp::SpatialSort::GenerateMappingTable ( std::vector< unsigned int > &  fill,
ai_real  pRadius 
) const

Compute a table that maps each vertex ID referring to a spatially close enough position to the same output ID.

Output IDs are assigned in ascending order from 0...n.

Parameters
fillWill be filled with numPositions entries.
pRadiusMaximal distance from the position a vertex may have to be counted in.
Returns
Number of unique vertices (n).

Member Data Documentation

◆ mCentroid

aiVector3D Assimp::SpatialSort::mCentroid
protected

The centroid of the positions, which is used as a point on the sorting plane when calculating distance.

This value is calculated in Finalize.

◆ mFinalized

bool Assimp::SpatialSort::mFinalized
protected

false until the Finalize method is called.

◆ mPlaneNormal

aiVector3D Assimp::SpatialSort::mPlaneNormal
protected

Normal of the sorting plane, normalized.

◆ mPositions

std::vector<Entry> Assimp::SpatialSort::mPositions
protected

The documentation for this class was generated from the following file: