3DSSpatialSort.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /** Small helper classes to optimise finding vertizes close to a given location */
  2. #ifndef AI_D3DSSPATIALSORT_H_INC
  3. #define AI_D3DSSPATIALSORT_H_INC
  4. #include <vector>
  5. #include "../include/aiVector3D.h"
  6. #include "3DSHelper.h"
  7. namespace Assimp
  8. {
  9. using namespace Dot3DS;
  10. // ------------------------------------------------------------------------------------------------
  11. /** Specialized version of SpatialSort to support smoothing groups
  12. * This is used in the .3ds loader
  13. */
  14. class D3DSSpatialSorter
  15. {
  16. public:
  17. D3DSSpatialSorter() {/* This is unintialized. This is evil. This is OK. */}
  18. /** Constructs a spatially sorted representation from the given position array.
  19. * Supply the positions in its layout in memory, the class will only refer to them
  20. * by index.
  21. * @param pPositions Pointer to the first position vector of the array.
  22. * @param pNumPositions Number of vectors to expect in that array.
  23. * @param pElementOffset Offset in bytes from the beginning of one vector in memory to the beginning of the next vector.
  24. * @note Smoothing groups are ignored
  25. */
  26. D3DSSpatialSorter( const aiVector3D* pPositions,
  27. unsigned int pNumPositions, unsigned int pElementOffset);
  28. /** Construction from a given face array, handling smoothing groups properly
  29. * @param p_pcMesh Input mesh.
  30. */
  31. D3DSSpatialSorter( const Dot3DS::Mesh* p_pcMesh);
  32. /** Destructor */
  33. ~D3DSSpatialSorter();
  34. /** Returns an iterator for all positions close to the given position.
  35. * @param pPosition The position to look for vertices.
  36. * @param pSG Only included vertices with at least one shared smooth group
  37. * @param pRadius Maximal distance from the position a vertex may have to be counted in.
  38. * @param poResults The container to store the indices of the found positions. Will be emptied
  39. * by the call so it may contain anything.
  40. * @return An iterator to iterate over all vertices in the given area.
  41. */
  42. void FindPositions( const aiVector3D& pPosition, uint32_t pSG,
  43. float pRadius, std::vector<unsigned int>& poResults) const;
  44. protected:
  45. /** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */
  46. aiVector3D mPlaneNormal;
  47. /** An entry in a spatially sorted position array. Consists of a vertex index,
  48. * its position and its precalculated distance from the reference plane */
  49. struct Entry
  50. {
  51. unsigned int mIndex; ///< The vertex referred by this entry
  52. aiVector3D mPosition; ///< Position
  53. uint32_t mSmoothGroups;
  54. float mDistance; ///< Distance of this vertex to the sorting plane
  55. Entry() { /** intentionally not initialized.*/ }
  56. Entry( unsigned int pIndex, const aiVector3D& pPosition, float pDistance,uint32_t pSG)
  57. :
  58. mPosition( pPosition), mIndex( pIndex), mDistance( pDistance),mSmoothGroups (pSG)
  59. { }
  60. bool operator < (const Entry& e) const { return mDistance < e.mDistance; }
  61. };
  62. // all positions, sorted by distance to the sorting plane
  63. std::vector<Entry> mPositions;
  64. };
  65. } // end of namespace Assimp
  66. #endif // AI_SPATIALSORT_H_INC