HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Sort.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU_Sort.h (GU Library, C++)
7  *
8  * COMMENTS: Geometry sorting implementations
9  */
10 
11 #include <UT/UT_KDTree.h>
12 #include <UT/UT_Vector3.h>
13 #include <UT/UT_VectorTypes.h>
14 #include <GA/GA_Handle.h>
15 #include <GA/GA_Range.h>
16 #include <GA/GA_Types.h>
17 
18 class GA_Attribute;
19 class GA_ElementGroup;
20 class GA_PointGroup;
21 
22 /// Set the indexattrib value of each element in the range to its GA_Index.
24  const GA_RWHandleID &indexattrib,
25  const GA_Range &range);
26 
27 /// Set the indexattrib value of each element in the group to its GA_Index.
29  const GA_RWHandleID &indexattrib,
30  const GA_ElementGroup *group = nullptr);
31 
32 ///
33 /// Argsort implementations of GU_Detail's sorting routines.
34 /// Each fills the provided indexattrib with the sorted indices.
35 /// Elements excluded from the group are set to their current GA_Index.
36 ///
37 /// If combine_argsort is set to true, the existing indexattrib indices
38 /// are used for argsorting.
39 ///
40 
41 /// Attribute argsort
42 /// @see GU_Detail::sortElements()
44  const GA_RWHandleID &indexattrib,
45  const GA_Attribute *order,
46  int component = 0,
47  const GA_ElementGroup *group = nullptr,
48  bool combine_argsort = false);
49 
50 /// Axis argsort
51 /// @see GU_Detail::sortPoints()
53  const GA_RWHandleID &indexattib,
54  GU_AxisType axis,
55  const GA_ElementGroup *group = nullptr,
56  bool combine_argsort = false);
57 
58 /// Random argsort
59 /// @see GU_Detail::sortPoints()
61  const GA_RWHandleID &indexattrib,
62  int seed,
63  bool combine_argsort = false);
64 
65 /// Shift argsort
66 /// @see GU_Detail::shiftPoints()
68  const GA_RWHandleID &indexattrib,
69  GA_Size shift,
70  const GA_ElementGroup *group = nullptr,
71  bool combine_argsort = false);
72 
73 /// Reverse argsort
74 /// @see GU_Detail::reversePoints()
76  const GA_RWHandleID &indexattrib,
77  const GA_ElementGroup *group = nullptr,
78  bool combine_argsort = false);
79 
80 /// Spatial argsort
81 /// @see GU_Detail::sortPointsSpatial()
83  const GA_RWHandleID &indexattrib,
84  const GA_ElementGroup *group = nullptr,
85  bool combine_argsort = false);
86 
87 /// Proximity argsort
88 /// @see GU_Detail::proximityPoints()
90  const GA_RWHandleID &indexattrib,
91  UT_Vector3F &point,
92  const GA_ElementGroup *group = nullptr,
93  bool combine_argsort = false);
94 
95 /// Vector argsort
96 /// @see GU_Detail::sortPoints()
98  const GA_RWHandleID &indexattrib,
99  const UT_Vector3F &origin,
100  const UT_Vector3F &direction,
101  const GA_ElementGroup *group = nullptr,
102  bool combine_argsort = false);
103 
104 /// Vertex argsort
105 /// @see GU_Detail::vertexOrder()
107  const GA_RWHandleID &indexattrib,
108  const GA_PointGroup *group = nullptr,
109  bool combine_argsort = false);
110 
111 /// Sort a component of an attribute as an array
113  GA_Attribute *attrib,
114  int component = 0,
115  bool descending = false);
116 
117 
118 // A KD-Tree to sort the model's point or primitive positions
119 class GU_SortKDTree : public UT_KDTree {
120 public:
122  : UT_KDTree(3, size)
123  , myPos(size)
124  {
125  myPos.entries(size);
126  setMaxLeafNodes(4);
128  }
129 
130  void setPos(int idx, const UT_Vector3 &pos) { myPos(idx) = pos; }
131 
132  const int *getIndices() const { return myList; }
133 
134  int comparePosition(int idx0, int idx1, int dim) const override
135  {
136  return myPos(idx0)[dim] < myPos(idx1)[dim] ? -1 : 1;
137  }
138  const float *getP(int idx) const override { return myPos(idx).vec; }
139 
140 private:
141  UT_Vector3Array myPos;
142 };
143 
void setBalancer(ut_KDBalancer balance)
Definition: UT_KDTree.h:542
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GU_API void GUargsortReverse(const GA_RWHandleID &indexattrib, const GA_ElementGroup *group=nullptr, bool combine_argsort=false)
GLenum GLint * range
Definition: glcorearb.h:1925
GU_SortKDTree(size_t size)
Definition: GU_Sort.h:121
GU_API void GUenumerateElements(const GA_RWHandleID &indexattrib, const GA_Range &range)
Set the indexattrib value of each element in the range to its GA_Index.
GU_API void GUargsortRandom(const GA_RWHandleID &indexattrib, int seed, bool combine_argsort=false)
void setMaxLeafNodes(int max_leaf_nodes)
Definition: UT_KDTree.h:548
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GU_API void GUargsortShift(const GA_RWHandleID &indexattrib, GA_Size shift, const GA_ElementGroup *group=nullptr, bool combine_argsort=false)
void setPos(int idx, const UT_Vector3 &pos)
Definition: GU_Sort.h:130
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
A range of elements in an index-map.
Definition: GA_Range.h:42
GU_AxisType
Definition: GU_Types.h:24
GU_API void GUargsortPointsByVertexOrder(const GA_RWHandleID &indexattrib, const GA_PointGroup *group=nullptr, bool combine_argsort=false)
const int * getIndices() const
Definition: GU_Sort.h:132
GU_API void GUargsortVector(const GA_RWHandleID &indexattrib, const UT_Vector3F &origin, const UT_Vector3F &direction, const GA_ElementGroup *group=nullptr, bool combine_argsort=false)
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
#define GU_API
Definition: GU_API.h:14
GU_API void GUargsortProximity(const GA_RWHandleID &indexattrib, UT_Vector3F &point, const GA_ElementGroup *group=nullptr, bool combine_argsort=false)
GU_API void GUargsortElements(const GA_RWHandleID &indexattrib, const GA_Attribute *order, int component=0, const GA_ElementGroup *group=nullptr, bool combine_argsort=false)
GU_API void GUsortAttribute(GA_Attribute *attrib, int component=0, bool descending=false)
Sort a component of an attribute as an array.
int comparePosition(int idx0, int idx1, int dim) const override
Definition: GU_Sort.h:134
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:655
GLsizeiptr size
Definition: glcorearb.h:664
const float * getP(int idx) const override
Return the position associated with the given point.
Definition: GU_Sort.h:138
int * myList
Definition: UT_KDTree.h:874
GU_API void GUargsortSpatial(const GA_RWHandleID &indexattrib, const GA_ElementGroup *group=nullptr, bool combine_argsort=false)