Path Tracer
SpatialSort.h
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2020, assimp team
6 
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
13 
14 * Redistributions of source code must retain the above
15  copyright notice, this list of conditions and the
16  following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the
20  following disclaimer in the documentation and/or other
21  materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24  contributors may be used to endorse or promote products
25  derived from this software without specific prior
26  written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 
40 ----------------------------------------------------------------------
41 */
42 
44 #pragma once
45 #ifndef AI_SPATIALSORT_H_INC
46 #define AI_SPATIALSORT_H_INC
47 
48 #ifdef __GNUC__
49 #pragma GCC system_header
50 #endif
51 
52 #include <assimp/types.h>
53 #include <vector>
54 
55 namespace Assimp {
56 
57 // ------------------------------------------------------------------------------------------------
64 // ------------------------------------------------------------------------------------------------
65 class ASSIMP_API SpatialSort {
66 public:
67  SpatialSort();
68 
69  // ------------------------------------------------------------------------------------
77  SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions,
78  unsigned int pElementOffset);
79 
82 
83  // ------------------------------------------------------------------------------------
96  void Fill(const aiVector3D *pPositions, unsigned int pNumPositions,
97  unsigned int pElementOffset,
98  bool pFinalize = true);
99 
100  // ------------------------------------------------------------------------------------
102  void Append(const aiVector3D *pPositions, unsigned int pNumPositions,
103  unsigned int pElementOffset,
104  bool pFinalize = true);
105 
106  // ------------------------------------------------------------------------------------
111  void Finalize();
112 
113  // ------------------------------------------------------------------------------------
120  void FindPositions(const aiVector3D &pPosition, ai_real pRadius,
121  std::vector<unsigned int> &poResults) const;
122 
123  // ------------------------------------------------------------------------------------
130  void FindIdenticalPositions(const aiVector3D &pPosition,
131  std::vector<unsigned int> &poResults) const;
132 
133  // ------------------------------------------------------------------------------------
141  unsigned int GenerateMappingTable(std::vector<unsigned int> &fill,
142  ai_real pRadius) const;
143 
144 protected:
147 
150  struct Entry {
151  unsigned int mIndex;
153  ai_real mDistance;
154 
155  Entry() AI_NO_EXCEPT
156  : mIndex(999999999),
157  mPosition(),
158  mDistance(99999.) {
159  // empty
160  }
161  Entry(unsigned int pIndex, const aiVector3D &pPosition, ai_real pDistance) :
162  mIndex(pIndex), mPosition(pPosition), mDistance(pDistance) {
163  // empty
164  }
165 
166  bool operator<(const Entry &e) const { return mDistance < e.mDistance; }
167  };
168 
169  // all positions, sorted by distance to the sorting plane
170  std::vector<Entry> mPositions;
171 };
172 
173 } // end of namespace Assimp
174 
175 #endif // AI_SPATIALSORT_H_INC
Assimp::SpatialSort::FindPositions
void FindPositions(const aiVector3D &pPosition, ai_real pRadius, std::vector< unsigned int > &poResults) const
aiVector3D
Definition: vector3.h:136
Assimp::SpatialSort::Fill
void Fill(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset, bool pFinalize=true)
types.h
Assimp::SpatialSort
Definition: SpatialSort.h:65
Assimp::SpatialSort::Finalize
void Finalize()
Assimp::SpatialSort::~SpatialSort
~SpatialSort()
Assimp::SpatialSort::Append
void Append(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset, bool pFinalize=true)
Assimp::SpatialSort::SpatialSort
SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset)
Assimp::SpatialSort::Entry
Definition: SpatialSort.h:150
Assimp::SpatialSort::mPlaneNormal
aiVector3D mPlaneNormal
Definition: SpatialSort.h:146
Assimp::SpatialSort::Entry::mPosition
aiVector3D mPosition
Position.
Definition: SpatialSort.h:152
Assimp::SpatialSort::FindIdenticalPositions
void FindIdenticalPositions(const aiVector3D &pPosition, std::vector< unsigned int > &poResults) const
Assimp::SpatialSort::Entry::mIndex
unsigned int mIndex
The vertex referred by this entry.
Definition: SpatialSort.h:151
Assimp::SpatialSort::GenerateMappingTable
unsigned int GenerateMappingTable(std::vector< unsigned int > &fill, ai_real pRadius) const
Assimp::SpatialSort::Entry::mDistance
ai_real mDistance
Distance of this vertex to the sorting plane.
Definition: SpatialSort.h:153
Assimp
Definition: ai_assert.h:50