vrshoot
view libs/assimp/SGSpatialSort.h @ 3:c179c72369be
rename candy->vr
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 03 Feb 2014 08:52:13 +0200 |
parents | |
children |
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** Small helper classes to optimise finding vertizes close to a given location
42 */
43 #ifndef AI_D3DSSPATIALSORT_H_INC
44 #define AI_D3DSSPATIALSORT_H_INC
46 #include <vector>
47 #include "assimp/types.h"
49 namespace Assimp {
51 // ----------------------------------------------------------------------------------
52 /** Specialized version of SpatialSort to support smoothing groups
53 * This is used in by the 3DS, ASE and LWO loaders. 3DS and ASE share their
54 * normal computation code in SmoothingGroups.inl, the LWO loader has its own
55 * implementation to handle all details of its file format correctly.
56 */
57 // ----------------------------------------------------------------------------------
58 class SGSpatialSort
59 {
60 public:
62 SGSpatialSort();
64 // -------------------------------------------------------------------
65 /** Construction from a given face array, handling smoothing groups
66 * properly
67 */
68 SGSpatialSort(const std::vector<aiVector3D>& vPositions);
70 // -------------------------------------------------------------------
71 /** Add a vertex to the spatial sort
72 * @param vPosition Vertex position to be added
73 * @param index Index of the vrtex
74 * @param smoothingGroup SmoothingGroup for this vertex
75 */
76 void Add(const aiVector3D& vPosition, unsigned int index,
77 unsigned int smoothingGroup);
79 // -------------------------------------------------------------------
80 /** Prepare the spatial sorter for use. This step runs in O(logn)
81 */
82 void Prepare();
84 /** Destructor */
85 ~SGSpatialSort();
87 // -------------------------------------------------------------------
88 /** Returns an iterator for all positions close to the given position.
89 * @param pPosition The position to look for vertices.
90 * @param pSG Only included vertices with at least one shared smooth group
91 * @param pRadius Maximal distance from the position a vertex may have
92 * to be counted in.
93 * @param poResults The container to store the indices of the found
94 * positions. Will be emptied by the call so it may contain anything.
95 * @param exactMatch Specifies whether smoothing groups are bit masks
96 * (false) or integral values (true). In the latter case, a vertex
97 * cannot belong to more than one smoothing group.
98 * @return An iterator to iterate over all vertices in the given area.
99 */
100 // -------------------------------------------------------------------
101 void FindPositions( const aiVector3D& pPosition, uint32_t pSG,
102 float pRadius, std::vector<unsigned int>& poResults,
103 bool exactMatch = false) const;
105 protected:
106 /** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */
107 aiVector3D mPlaneNormal;
109 // -------------------------------------------------------------------
110 /** An entry in a spatially sorted position array. Consists of a
111 * vertex index, its position and its precalculated distance from
112 * the reference plane */
113 // -------------------------------------------------------------------
114 struct Entry
115 {
116 unsigned int mIndex; ///< The vertex referred by this entry
117 aiVector3D mPosition; ///< Position
118 uint32_t mSmoothGroups;
119 float mDistance; ///< Distance of this vertex to the sorting plane
121 Entry() { /** intentionally not initialized.*/ }
122 Entry( unsigned int pIndex, const aiVector3D& pPosition, float pDistance,uint32_t pSG)
123 :
124 mIndex( pIndex),
125 mPosition( pPosition),
126 mSmoothGroups (pSG),
127 mDistance( pDistance)
128 { }
130 bool operator < (const Entry& e) const { return mDistance < e.mDistance; }
131 };
133 // all positions, sorted by distance to the sorting plane
134 std::vector<Entry> mPositions;
135 };
137 } // end of namespace Assimp
139 #endif // AI_SPATIALSORT_H_INC