2008-05-09 17:24:28 +00:00
|
|
|
/*
|
2008-05-22 10:20:31 +00:00
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-09 17:24:28 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2010-04-10 15:30:22 +00:00
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
2008-05-09 17:24:28 +00:00
|
|
|
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 Development 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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Small helper classes to optimise finding vertizes close to a given location
|
|
|
|
*/
|
2008-05-05 12:36:31 +00:00
|
|
|
#ifndef AI_D3DSSPATIALSORT_H_INC
|
|
|
|
#define AI_D3DSSPATIALSORT_H_INC
|
|
|
|
|
|
|
|
#include <vector>
|
2008-08-28 17:35:36 +00:00
|
|
|
#include "../include/aiTypes.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-09-20 15:55:51 +00:00
|
|
|
namespace Assimp {
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-09-20 15:55:51 +00:00
|
|
|
// ----------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
/** Specialized version of SpatialSort to support smoothing groups
|
2008-09-20 15:55:51 +00:00
|
|
|
* This is used in by the 3DS, ASE and LWO loaders. 3DS and ASE share their
|
|
|
|
* normal computation code in SmoothingGroups.inl, the LWO loader has its own
|
|
|
|
* implementation to handle all details of its file format correctly.
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-09-20 15:55:51 +00:00
|
|
|
// ----------------------------------------------------------------------------------
|
2008-08-28 17:35:36 +00:00
|
|
|
class SGSpatialSort
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
SGSpatialSort();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-09-20 15:55:51 +00:00
|
|
|
/** Construction from a given face array, handling smoothing groups
|
|
|
|
* properly
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-08-28 17:35:36 +00:00
|
|
|
SGSpatialSort(const std::vector<aiVector3D>& vPositions);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-08-28 17:35:36 +00:00
|
|
|
/** Add a vertex to the spatial sort
|
|
|
|
* @param vPosition Vertex position to be added
|
|
|
|
* @param index Index of the vrtex
|
|
|
|
* @param smoothingGroup SmoothingGroup for this vertex
|
2008-05-05 12:36:31 +00:00
|
|
|
*/
|
2008-08-28 17:35:36 +00:00
|
|
|
void Add(const aiVector3D& vPosition, unsigned int index,
|
|
|
|
unsigned int smoothingGroup);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-09-20 15:55:51 +00:00
|
|
|
/** Prepare the spatial sorter for use. This step runs in O(logn)
|
2008-05-09 17:24:28 +00:00
|
|
|
*/
|
|
|
|
void Prepare();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
/** Destructor */
|
2008-08-28 17:35:36 +00:00
|
|
|
~SGSpatialSort();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
/** Returns an iterator for all positions close to the given position.
|
|
|
|
* @param pPosition The position to look for vertices.
|
|
|
|
* @param pSG Only included vertices with at least one shared smooth group
|
2008-09-20 15:55:51 +00:00
|
|
|
* @param pRadius Maximal distance from the position a vertex may have
|
|
|
|
* to be counted in.
|
|
|
|
* @param poResults The container to store the indices of the found
|
|
|
|
* positions. Will be emptied by the call so it may contain anything.
|
|
|
|
* @param exactMatch Specifies whether smoothing groups are bit masks
|
|
|
|
* (false) or integral values (true). In the latter case, a vertex
|
|
|
|
* cannot belong to more than one smoothing group.
|
2008-05-05 12:36:31 +00:00
|
|
|
* @return An iterator to iterate over all vertices in the given area.
|
|
|
|
*/
|
2008-09-20 15:55:51 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
void FindPositions( const aiVector3D& pPosition, uint32_t pSG,
|
2008-09-20 15:55:51 +00:00
|
|
|
float pRadius, std::vector<unsigned int>& poResults,
|
|
|
|
bool exactMatch = false) const;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */
|
|
|
|
aiVector3D mPlaneNormal;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// -------------------------------------------------------------------
|
2008-09-20 15:55:51 +00:00
|
|
|
/** An entry in a spatially sorted position array. Consists of a
|
|
|
|
* vertex index, its position and its precalculated distance from
|
|
|
|
* the reference plane */
|
|
|
|
// -------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
struct Entry
|
|
|
|
{
|
2008-09-20 15:55:51 +00:00
|
|
|
unsigned int mIndex; ///< The vertex referred by this entry
|
|
|
|
aiVector3D mPosition; ///< Position
|
2008-05-05 12:36:31 +00:00
|
|
|
uint32_t mSmoothGroups;
|
2008-09-20 15:55:51 +00:00
|
|
|
float mDistance; ///< Distance of this vertex to the sorting plane
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
Entry() { /** intentionally not initialized.*/ }
|
|
|
|
Entry( unsigned int pIndex, const aiVector3D& pPosition, float pDistance,uint32_t pSG)
|
|
|
|
:
|
2008-09-11 20:50:15 +00:00
|
|
|
mIndex( pIndex),
|
|
|
|
mPosition( pPosition),
|
|
|
|
mSmoothGroups (pSG),
|
|
|
|
mDistance( pDistance)
|
2008-05-05 12:36:31 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
bool operator < (const Entry& e) const { return mDistance < e.mDistance; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// all positions, sorted by distance to the sorting plane
|
|
|
|
std::vector<Entry> mPositions;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace Assimp
|
|
|
|
|
2008-09-11 20:50:15 +00:00
|
|
|
#endif // AI_SPATIALSORT_H_INC
|