closes https://github.com/assimp/assimp/issues/3165: remove deprecated code whch causes compiler warning.

pull/3167/head
Kim Kulling 2020-04-26 08:59:52 +02:00
parent 02ef435d55
commit bafb8e3189
5 changed files with 220 additions and 157 deletions

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -50,71 +48,64 @@ using namespace Assimp;
// CHAR_BIT seems to be defined under MVSC, but not under GCC. Pray that the correct value is 8. // CHAR_BIT seems to be defined under MVSC, but not under GCC. Pray that the correct value is 8.
#ifndef CHAR_BIT #ifndef CHAR_BIT
# define CHAR_BIT 8 #define CHAR_BIT 8
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
# pragma warning(disable : 4127) //# pragma warning(disable : 4127)
#endif // _WIN32 #endif // _WIN32
// ------------------------------------------------------------------------------------------------ const aiVector3D PlaneInit( 0.8523f, 0.34321f, 0.5736f );
// Constructs a spatially sorted representation from the given position array.
SpatialSort::SpatialSort( const aiVector3D* pPositions, unsigned int pNumPositions,
unsigned int pElementOffset)
// define the reference plane. We choose some arbitrary vector away from all basic axises // ------------------------------------------------------------------------------------------------
// in the hope that no model spreads all its vertices along this plane. // Constructs a spatially sorted representation from the given position array.
: mPlaneNormal(0.8523f, 0.34321f, 0.5736f) // define the reference plane. We choose some arbitrary vector away from all basic axises
{ // in the hope that no model spreads all its vertices along this plane.
SpatialSort::SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset) :
mPlaneNormal(PlaneInit) {
mPlaneNormal.Normalize(); mPlaneNormal.Normalize();
Fill(pPositions,pNumPositions,pElementOffset); Fill(pPositions, pNumPositions, pElementOffset);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SpatialSort :: SpatialSort() SpatialSort::SpatialSort() :
: mPlaneNormal(0.8523f, 0.34321f, 0.5736f) mPlaneNormal(PlaneInit) {
{
mPlaneNormal.Normalize(); mPlaneNormal.Normalize();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor // Destructor
SpatialSort::~SpatialSort() SpatialSort::~SpatialSort() {
{ // empty
// nothing to do here, everything destructs automatically
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SpatialSort::Fill( const aiVector3D* pPositions, unsigned int pNumPositions, void SpatialSort::Fill(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset, unsigned int pElementOffset,
bool pFinalize /*= true */) bool pFinalize /*= true */) {
{
mPositions.clear(); mPositions.clear();
Append(pPositions,pNumPositions,pElementOffset,pFinalize); Append(pPositions, pNumPositions, pElementOffset, pFinalize);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SpatialSort :: Finalize() void SpatialSort::Finalize() {
{ std::sort(mPositions.begin(), mPositions.end());
std::sort( mPositions.begin(), mPositions.end());
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SpatialSort::Append( const aiVector3D* pPositions, unsigned int pNumPositions, void SpatialSort::Append(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset, unsigned int pElementOffset,
bool pFinalize /*= true */) bool pFinalize /*= true */) {
{
// store references to all given positions along with their distance to the reference plane // store references to all given positions along with their distance to the reference plane
const size_t initial = mPositions.size(); const size_t initial = mPositions.size();
mPositions.reserve(initial + (pFinalize?pNumPositions:pNumPositions*2)); mPositions.reserve(initial + (pFinalize ? pNumPositions : pNumPositions * 2));
for( unsigned int a = 0; a < pNumPositions; a++) for (unsigned int a = 0; a < pNumPositions; a++) {
{ const char *tempPointer = reinterpret_cast<const char *>(pPositions);
const char* tempPointer = reinterpret_cast<const char*> (pPositions); const aiVector3D *vec = reinterpret_cast<const aiVector3D *>(tempPointer + a * pElementOffset);
const aiVector3D* vec = reinterpret_cast<const aiVector3D*> (tempPointer + a * pElementOffset);
// store position by index and distance // store position by index and distance
ai_real distance = *vec * mPlaneNormal; ai_real distance = *vec * mPlaneNormal;
mPositions.push_back( Entry( static_cast<unsigned int>(a+initial), *vec, distance)); mPositions.push_back(Entry(static_cast<unsigned int>(a + initial), *vec, distance));
} }
if (pFinalize) { if (pFinalize) {
@ -125,9 +116,8 @@ void SpatialSort::Append( const aiVector3D* pPositions, unsigned int pNumPositio
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns an iterator for all positions close to the given position. // Returns an iterator for all positions close to the given position.
void SpatialSort::FindPositions( const aiVector3D& pPosition, void SpatialSort::FindPositions(const aiVector3D &pPosition,
ai_real pRadius, std::vector<unsigned int>& poResults) const ai_real pRadius, std::vector<unsigned int> &poResults) const {
{
const ai_real dist = pPosition * mPlaneNormal; const ai_real dist = pPosition * mPlaneNormal;
const ai_real minDist = dist - pRadius, maxDist = dist + pRadius; const ai_real minDist = dist - pRadius, maxDist = dist + pRadius;
@ -135,19 +125,18 @@ void SpatialSort::FindPositions( const aiVector3D& pPosition,
poResults.clear(); poResults.clear();
// quick check for positions outside the range // quick check for positions outside the range
if( mPositions.size() == 0) if (mPositions.size() == 0)
return; return;
if( maxDist < mPositions.front().mDistance) if (maxDist < mPositions.front().mDistance)
return; return;
if( minDist > mPositions.back().mDistance) if (minDist > mPositions.back().mDistance)
return; return;
// do a binary search for the minimal distance to start the iteration there // do a binary search for the minimal distance to start the iteration there
unsigned int index = (unsigned int)mPositions.size() / 2; unsigned int index = (unsigned int)mPositions.size() / 2;
unsigned int binaryStepSize = (unsigned int)mPositions.size() / 4; unsigned int binaryStepSize = (unsigned int)mPositions.size() / 4;
while( binaryStepSize > 1) while (binaryStepSize > 1) {
{ if (mPositions[index].mDistance < minDist)
if( mPositions[index].mDistance < minDist)
index += binaryStepSize; index += binaryStepSize;
else else
index -= binaryStepSize; index -= binaryStepSize;
@ -157,21 +146,20 @@ void SpatialSort::FindPositions( const aiVector3D& pPosition,
// depending on the direction of the last step we need to single step a bit back or forth // depending on the direction of the last step we need to single step a bit back or forth
// to find the actual beginning element of the range // to find the actual beginning element of the range
while( index > 0 && mPositions[index].mDistance > minDist) while (index > 0 && mPositions[index].mDistance > minDist)
index--; index--;
while( index < (mPositions.size() - 1) && mPositions[index].mDistance < minDist) while (index < (mPositions.size() - 1) && mPositions[index].mDistance < minDist)
index++; index++;
// Mow start iterating from there until the first position lays outside of the distance range. // Mow start iterating from there until the first position lays outside of the distance range.
// Add all positions inside the distance range within the given radius to the result aray // Add all positions inside the distance range within the given radius to the result aray
std::vector<Entry>::const_iterator it = mPositions.begin() + index; std::vector<Entry>::const_iterator it = mPositions.begin() + index;
const ai_real pSquared = pRadius*pRadius; const ai_real pSquared = pRadius * pRadius;
while( it->mDistance < maxDist) while (it->mDistance < maxDist) {
{ if ((it->mPosition - pPosition).SquareLength() < pSquared)
if( (it->mPosition - pPosition).SquareLength() < pSquared) poResults.push_back(it->mIndex);
poResults.push_back( it->mIndex);
++it; ++it;
if( it == mPositions.end()) if (it == mPositions.end())
break; break;
} }
@ -180,70 +168,71 @@ void SpatialSort::FindPositions( const aiVector3D& pPosition,
namespace { namespace {
// Binary, signed-integer representation of a single-precision floating-point value. // Binary, signed-integer representation of a single-precision floating-point value.
// IEEE 754 says: "If two floating-point numbers in the same format are ordered then they are // IEEE 754 says: "If two floating-point numbers in the same format are ordered then they are
// ordered the same way when their bits are reinterpreted as sign-magnitude integers." // ordered the same way when their bits are reinterpreted as sign-magnitude integers."
// This allows us to convert all floating-point numbers to signed integers of arbitrary size // This allows us to convert all floating-point numbers to signed integers of arbitrary size
// and then use them to work with ULPs (Units in the Last Place, for high-precision // and then use them to work with ULPs (Units in the Last Place, for high-precision
// computations) or to compare them (integer comparisons are faster than floating-point // computations) or to compare them (integer comparisons are faster than floating-point
// comparisons on many platforms). // comparisons on many platforms).
typedef ai_int BinFloat; typedef ai_int BinFloat;
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
// Converts the bit pattern of a floating-point number to its signed integer representation. // Converts the bit pattern of a floating-point number to its signed integer representation.
BinFloat ToBinary( const ai_real & pValue) { BinFloat ToBinary(const ai_real &pValue) {
// If this assertion fails, signed int is not big enough to store a float on your platform. // If this assertion fails, signed int is not big enough to store a float on your platform.
// Please correct the declaration of BinFloat a few lines above - but do it in a portable, // Please correct the declaration of BinFloat a few lines above - but do it in a portable,
// #ifdef'd manner! // #ifdef'd manner!
static_assert( sizeof(BinFloat) >= sizeof(ai_real), "sizeof(BinFloat) >= sizeof(ai_real)"); static_assert(sizeof(BinFloat) >= sizeof(ai_real), "sizeof(BinFloat) >= sizeof(ai_real)");
#if defined( _MSC_VER) #if defined(_MSC_VER)
// If this assertion fails, Visual C++ has finally moved to ILP64. This means that this // If this assertion fails, Visual C++ has finally moved to ILP64. This means that this
// code has just become legacy code! Find out the current value of _MSC_VER and modify // code has just become legacy code! Find out the current value of _MSC_VER and modify
// the #if above so it evaluates false on the current and all upcoming VC versions (or // the #if above so it evaluates false on the current and all upcoming VC versions (or
// on the current platform, if LP64 or LLP64 are still used on other platforms). // on the current platform, if LP64 or LLP64 are still used on other platforms).
static_assert( sizeof(BinFloat) == sizeof(ai_real), "sizeof(BinFloat) == sizeof(ai_real)"); static_assert(sizeof(BinFloat) == sizeof(ai_real), "sizeof(BinFloat) == sizeof(ai_real)");
// This works best on Visual C++, but other compilers have their problems with it. // This works best on Visual C++, but other compilers have their problems with it.
const BinFloat binValue = reinterpret_cast<BinFloat const &>(pValue); const BinFloat binValue = reinterpret_cast<BinFloat const &>(pValue);
#else //::memcpy(&binValue, &pValue, sizeof(pValue));
// On many compilers, reinterpreting a float address as an integer causes aliasing //return binValue;
// problems. This is an ugly but more or less safe way of doing it. #else
union { // On many compilers, reinterpreting a float address as an integer causes aliasing
ai_real asFloat; // problems. This is an ugly but more or less safe way of doing it.
BinFloat asBin; union {
} conversion; ai_real asFloat;
conversion.asBin = 0; // zero empty space in case sizeof(BinFloat) > sizeof(float) BinFloat asBin;
conversion.asFloat = pValue; } conversion;
const BinFloat binValue = conversion.asBin; conversion.asBin = 0; // zero empty space in case sizeof(BinFloat) > sizeof(float)
#endif conversion.asFloat = pValue;
const BinFloat binValue = conversion.asBin;
#endif
// floating-point numbers are of sign-magnitude format, so find out what signed number // floating-point numbers are of sign-magnitude format, so find out what signed number
// representation we must convert negative values to. // representation we must convert negative values to.
// See http://en.wikipedia.org/wiki/Signed_number_representations. // See http://en.wikipedia.org/wiki/Signed_number_representations.
// Two's complement? // Two's complement?
if( (-42 == (~42 + 1)) && (binValue & 0x80000000)) /*if ((-42 == (~42 + 1)) && (binValue & 0x80000000))
return BinFloat(1 << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue; return BinFloat(1 << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue;
// One's complement? // One's complement?
else if ( (-42 == ~42) && (binValue & 0x80000000)) else if ((-42 == ~42) && (binValue & 0x80000000))
return BinFloat(-0) - binValue; return BinFloat(-0) - binValue;
// Sign-magnitude? // Sign-magnitude?
else if( (-42 == (42 | (-0))) && (binValue & 0x80000000)) // -0 = 1000... binary else if ((-42 == (42 | (-0))) && (binValue & 0x80000000)) // -0 = 1000... binary
return binValue; return binValue;
else else*/
return binValue;
} return binValue;
}
} // namespace } // namespace
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Fills an array with indices of all positions identical to the given position. In opposite to // 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. // FindPositions(), not an epsilon is used but a (very low) tolerance of four floating-point units.
void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition, void SpatialSort::FindIdenticalPositions(const aiVector3D &pPosition, std::vector<unsigned int> &poResults) const {
std::vector<unsigned int>& poResults) const
{
// Epsilons have a huge disadvantage: they are of constant precision, while floating-point // Epsilons have a huge disadvantage: they are of constant precision, while floating-point
// values are of log2 precision. If you apply e=0.01 to 100, the epsilon is rather small, but // values are of log2 precision. If you apply e=0.01 to 100, the epsilon is rather small, but
// if you apply it to 0.001, it is enormous. // if you apply it to 0.001, it is enormous.
@ -269,20 +258,19 @@ void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition,
// Convert the plane distance to its signed integer representation so the ULPs tolerance can be // Convert the plane distance to its signed integer representation so the ULPs tolerance can be
// applied. For some reason, VC won't optimize two calls of the bit pattern conversion. // applied. For some reason, VC won't optimize two calls of the bit pattern conversion.
const BinFloat minDistBinary = ToBinary( pPosition * mPlaneNormal) - distanceToleranceInULPs; const BinFloat minDistBinary = ToBinary(pPosition * mPlaneNormal) - distanceToleranceInULPs;
const BinFloat maxDistBinary = minDistBinary + 2 * distanceToleranceInULPs; const BinFloat maxDistBinary = minDistBinary + 2 * distanceToleranceInULPs;
// clear the array in this strange fashion because a simple clear() would also deallocate // clear the array in this strange fashion because a simple clear() would also deallocate
// the array which we want to avoid // the array which we want to avoid
poResults.resize( 0 ); poResults.resize(0);
// do a binary search for the minimal distance to start the iteration there // do a binary search for the minimal distance to start the iteration there
unsigned int index = (unsigned int)mPositions.size() / 2; unsigned int index = (unsigned int)mPositions.size() / 2;
unsigned int binaryStepSize = (unsigned int)mPositions.size() / 4; unsigned int binaryStepSize = (unsigned int)mPositions.size() / 4;
while( binaryStepSize > 1) while (binaryStepSize > 1) {
{
// Ugly, but conditional jumps are faster with integers than with floats // Ugly, but conditional jumps are faster with integers than with floats
if( minDistBinary > ToBinary(mPositions[index].mDistance)) if (minDistBinary > ToBinary(mPositions[index].mDistance))
index += binaryStepSize; index += binaryStepSize;
else else
index -= binaryStepSize; index -= binaryStepSize;
@ -292,20 +280,19 @@ void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition,
// depending on the direction of the last step we need to single step a bit back or forth // depending on the direction of the last step we need to single step a bit back or forth
// to find the actual beginning element of the range // to find the actual beginning element of the range
while( index > 0 && minDistBinary < ToBinary(mPositions[index].mDistance) ) while (index > 0 && minDistBinary < ToBinary(mPositions[index].mDistance))
index--; index--;
while( index < (mPositions.size() - 1) && minDistBinary > ToBinary(mPositions[index].mDistance)) while (index < (mPositions.size() - 1) && minDistBinary > ToBinary(mPositions[index].mDistance))
index++; index++;
// Now start iterating from there until the first position lays outside of the distance range. // Now start iterating from there until the first position lays outside of the distance range.
// Add all positions inside the distance range within the tolerance to the result array // Add all positions inside the distance range within the tolerance to the result array
std::vector<Entry>::const_iterator it = mPositions.begin() + index; std::vector<Entry>::const_iterator it = mPositions.begin() + index;
while( ToBinary(it->mDistance) < maxDistBinary) while (ToBinary(it->mDistance) < maxDistBinary) {
{ if (distance3DToleranceInULPs >= ToBinary((it->mPosition - pPosition).SquareLength()))
if( distance3DToleranceInULPs >= ToBinary((it->mPosition - pPosition).SquareLength()))
poResults.push_back(it->mIndex); poResults.push_back(it->mIndex);
++it; ++it;
if( it == mPositions.end()) if (it == mPositions.end())
break; break;
} }
@ -313,22 +300,19 @@ void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition,
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int>& fill, ai_real pRadius) const unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int> &fill, ai_real pRadius) const {
{ fill.resize(mPositions.size(), UINT_MAX);
fill.resize(mPositions.size(),UINT_MAX);
ai_real dist, maxDist; ai_real dist, maxDist;
unsigned int t=0; unsigned int t = 0;
const ai_real pSquared = pRadius*pRadius; const ai_real pSquared = pRadius * pRadius;
for (size_t i = 0; i < mPositions.size();) { for (size_t i = 0; i < mPositions.size();) {
dist = mPositions[i].mPosition * mPlaneNormal; dist = mPositions[i].mPosition * mPlaneNormal;
maxDist = dist + pRadius; maxDist = dist + pRadius;
fill[mPositions[i].mIndex] = t; fill[mPositions[i].mIndex] = t;
const aiVector3D& oldpos = mPositions[i].mPosition; const aiVector3D &oldpos = mPositions[i].mPosition;
for (++i; i < fill.size() && mPositions[i].mDistance < maxDist for (++i; i < fill.size() && mPositions[i].mDistance < maxDist && (mPositions[i].mPosition - oldpos).SquareLength() < pSquared; ++i) {
&& (mPositions[i].mPosition - oldpos).SquareLength() < pSquared; ++i)
{
fill[mPositions[i].mIndex] = t; fill[mPositions[i].mIndex] = t;
} }
++t; ++t;
@ -338,7 +322,7 @@ unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int>& fill,
// debug invariant: mPositions[i].mIndex values must range from 0 to mPositions.size()-1 // debug invariant: mPositions[i].mIndex values must range from 0 to mPositions.size()-1
for (size_t i = 0; i < fill.size(); ++i) { for (size_t i = 0; i < fill.size(); ++i) {
ai_assert(fill[i]<mPositions.size()); ai_assert(fill[i] < mPositions.size());
} }
#endif #endif

View File

@ -46,11 +46,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_SPATIALSORT_H_INC #define AI_SPATIALSORT_H_INC
#ifdef __GNUC__ #ifdef __GNUC__
# pragma GCC system_header #pragma GCC system_header
#endif #endif
#include <vector>
#include <assimp/types.h> #include <assimp/types.h>
#include <vector>
namespace Assimp { namespace Assimp {
@ -62,10 +62,8 @@ namespace Assimp {
* time, with O(n) worst case complexity when all vertices lay on the plane. The plane is chosen * 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. */ * so that it avoids common planes in usual data sets. */
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
class ASSIMP_API SpatialSort class ASSIMP_API SpatialSort {
{
public: public:
SpatialSort(); SpatialSort();
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
@ -76,14 +74,12 @@ public:
* @param pNumPositions Number of vectors to expect in that array. * @param pNumPositions Number of vectors to expect in that array.
* @param pElementOffset Offset in bytes from the beginning of one vector in memory * @param pElementOffset Offset in bytes from the beginning of one vector in memory
* to the beginning of the next vector. */ * to the beginning of the next vector. */
SpatialSort( const aiVector3D* pPositions, unsigned int pNumPositions, SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset); unsigned int pElementOffset);
/** Destructor */ /** Destructor */
~SpatialSort(); ~SpatialSort();
public:
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
/** Sets the input data for the SpatialSort. This replaces existing data, if any. /** Sets the input data for the SpatialSort. This replaces existing data, if any.
* The new data receives new indices in ascending order. * The new data receives new indices in ascending order.
@ -97,17 +93,15 @@ public:
* required in order to use #FindPosition() or #GenerateMappingTable(). * required in order to use #FindPosition() or #GenerateMappingTable().
* If you don't finalize yet, you can use #Append() to add data from * If you don't finalize yet, you can use #Append() to add data from
* other sources.*/ * other sources.*/
void Fill( const aiVector3D* pPositions, unsigned int pNumPositions, void Fill(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset, unsigned int pElementOffset,
bool pFinalize = true); bool pFinalize = true);
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
/** Same as #Fill(), except the method appends to existing data in the #SpatialSort. */ /** Same as #Fill(), except the method appends to existing data in the #SpatialSort. */
void Append( const aiVector3D* pPositions, unsigned int pNumPositions, void Append(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset, unsigned int pElementOffset,
bool pFinalize = true); bool pFinalize = true);
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
/** Finalize the spatial hash data structure. This can be useful after /** Finalize the spatial hash data structure. This can be useful after
@ -123,8 +117,8 @@ public:
* @param poResults The container to store the indices of the found positions. * @param poResults The container to store the indices of the found positions.
* Will be emptied by the call so it may contain anything. * Will be emptied by the call so it may contain anything.
* @return An iterator to iterate over all vertices in the given area.*/ * @return An iterator to iterate over all vertices in the given area.*/
void FindPositions( const aiVector3D& pPosition, ai_real pRadius, void FindPositions(const aiVector3D &pPosition, ai_real pRadius,
std::vector<unsigned int>& poResults) const; std::vector<unsigned int> &poResults) const;
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
/** Fills an array with indices of all positions identical to the given position. In /** Fills an array with indices of all positions identical to the given position. In
@ -133,8 +127,8 @@ public:
* @param pPosition The position to look for vertices. * @param pPosition The position to look for vertices.
* @param poResults The container to store the indices of the found positions. * @param poResults The container to store the indices of the found positions.
* Will be emptied by the call so it may contain anything.*/ * Will be emptied by the call so it may contain anything.*/
void FindIdenticalPositions( const aiVector3D& pPosition, void FindIdenticalPositions(const aiVector3D &pPosition,
std::vector<unsigned int>& poResults) const; std::vector<unsigned int> &poResults) const;
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
/** Compute a table that maps each vertex ID referring to a spatially close /** Compute a table that maps each vertex ID referring to a spatially close
@ -144,8 +138,8 @@ public:
* @param pRadius Maximal distance from the position a vertex may have to * @param pRadius Maximal distance from the position a vertex may have to
* be counted in. * be counted in.
* @return Number of unique vertices (n). */ * @return Number of unique vertices (n). */
unsigned int GenerateMappingTable(std::vector<unsigned int>& fill, unsigned int GenerateMappingTable(std::vector<unsigned int> &fill,
ai_real pRadius) const; ai_real pRadius) const;
protected: protected:
/** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */ /** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */
@ -159,15 +153,17 @@ protected:
ai_real mDistance; ///< Distance of this vertex to the sorting plane ai_real mDistance; ///< Distance of this vertex to the sorting plane
Entry() AI_NO_EXCEPT Entry() AI_NO_EXCEPT
: mIndex( 999999999 ), mPosition(), mDistance( 99999. ) { : mIndex(999999999),
// empty mPosition(),
mDistance(99999.) {
// empty
} }
Entry( unsigned int pIndex, const aiVector3D& pPosition, ai_real pDistance) Entry(unsigned int pIndex, const aiVector3D &pPosition, ai_real pDistance) :
: mIndex( pIndex), mPosition( pPosition), mDistance( pDistance) { mIndex(pIndex), mPosition(pPosition), mDistance(pDistance) {
// empty // empty
} }
bool operator < (const Entry& e) const { return mDistance < e.mDistance; } bool operator<(const Entry &e) const { return mDistance < e.mDistance; }
}; };
// all positions, sorted by distance to the sorting plane // all positions, sorted by distance to the sorting plane

View File

@ -86,6 +86,7 @@ SET( COMMON
unit/utStringUtils.cpp unit/utStringUtils.cpp
unit/Common/uiScene.cpp unit/Common/uiScene.cpp
unit/Common/utLineSplitter.cpp unit/Common/utLineSplitter.cpp
unit/Common/utSpatialSort.cpp
) )
SET( IMPORTERS SET( IMPORTERS

View File

@ -0,0 +1,84 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "UnitTestPCH.h"
#include <assimp/SpatialSort.h>
using namespace Assimp;
class utSpatialSort : public ::testing::Test {
public
:
aiVector3D *vecs;
protected:
void SetUp() override {
::srand(static_cast<unsigned>(time(0)));
vecs = new aiVector3D[100];
for (size_t i = 0; i < 100; ++i) {
vecs[i].x = static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / 100));
vecs[i].y = static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / 100));
vecs[i].z = static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / 100));
}
}
void TearDown() override {
delete[] vecs;
}
};
TEST_F( utSpatialSort, findIdenticalsTest ) {
SpatialSort sSort;
sSort.Fill(vecs, 100, sizeof(aiVector3D));
std::vector<unsigned int> indices;
sSort.FindIdenticalPositions(vecs[0], indices);
EXPECT_EQ(1u, indices.size());
}
TEST_F(utSpatialSort, findPositionsTest) {
SpatialSort sSort;
sSort.Fill(vecs, 100, sizeof(aiVector3D));
std::vector<unsigned int> indices;
sSort.FindPositions(vecs[0], 0.01f, indices);
EXPECT_EQ(1u, indices.size());
}

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,