HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_AttribFind.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: GEO_AttribFind.h (GEO Library, C++)
7  *
8  * COMMENTS: Declarations of functions for finding interpolated
9  * attribute values
10  */
11 
12 #pragma once
13 
14 #ifndef __GEO_AttribFind__
15 #define __GEO_AttribFind__
16 
17 #include "GEO_API.h"
18 #include <GA/GA_Handle.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_KDTree.h>
21 #include <UT/UT_Vector2.h>
22 #include <UT/UT_Vector3.h>
23 #include <UT/UT_VectorTypes.h>
24 
25 class GEO_Detail;
27 template<typename T>
29 
31 {
32 public:
34  : UT_KDTree(2, points.entries())
35  , myPoints(points)
36  {
37  // Override the balancer to be centroid, it should behave nicer
38  // for very large data sets. (Mantra uses centroid for photons already)
39  setBalancer(UT_KD_CENTROID);
40 
41  // Doing this prior to querying in multithreaded code
42  // avoids extra locks.
43  balance();
44  }
45 
46  /// NOTE: Although this is non-const, it's safe to call from multiple threads.
47  int findAllInsideTri(
48  UT_IntArray &list,
50  ut_KDPQueue &q,
51  const UT_Vector2 &a,
52  const UT_Vector2 &b,
53  const UT_Vector2 &c,
54  float tolerance = 1e-7f,
55  bool wrapunitsquare = false);
56 
57  void updatePoints(bool enable_multithreading = true)
58  {
59  flagDirty();
60  balance(enable_multithreading);
61  }
62  virtual void buildIfNeeded(bool enable_multithreading = true)
63  {
64  updatePoints(enable_multithreading);
65  }
66  const UT_Vector2 &getValue(int idx) const
67  {
68  return myPoints(idx);
69  }
70 private:
71  virtual const float *getP(int idx) const
72  {
73  return myPoints(idx).data();
74  }
75  virtual int comparePosition(int idx0, int idx1, int dim) const
76  {
77  float delta = myPoints(idx0)(dim) - myPoints(idx1)(dim);
78  if (delta < 0)
79  return -1;
80  if (delta > 0)
81  return 1;
82  return 0;
83  }
84  const UT_Array<UT_Vector2> &myPoints;
85 };
86 
87 class GEO_API GEO_3DTree : private UT_KDTree
88 {
89 public:
91  : UT_KDTree(3, points.entries())
92  , myPoints(points)
93  {
94  // Override the balancer to be centroid, it should behave nicer
95  // for very large data sets. (Mantra uses centroid for photons already)
96  setBalancer(UT_KD_CENTROID);
97 
98  // Doing this prior to querying in multithreaded code
99  // avoids extra locks.
100  balance();
101  }
102 
103  /// NOTE: Although this is non-const, it's safe to call from multiple threads.
104  int findAllInsideTet(
105  UT_IntArray &list,
106  UT_Array<UT_Vector3> &offs,
107  ut_KDPQueue &q,
108  const UT_Vector3 &a,
109  const UT_Vector3 &b,
110  const UT_Vector3 &c,
111  const UT_Vector3 &d,
112  float tolerance = 1e-7f,
113  bool wrapunitcube = false);
114 
116  {
117  flagDirty();
118  balance();
119  }
120  const UT_Vector3 &getValue(int idx) const
121  {
122  return myPoints(idx);
123  }
124 private:
125  virtual const float *getP(int idx) const
126  {
127  return myPoints(idx).data();
128  }
129  virtual int comparePosition(int idx0, int idx1, int dim) const
130  {
131  float delta = myPoints(idx0)(dim) - myPoints(idx1)(dim);
132  if (delta < 0)
133  return -1;
134  if (delta > 0)
135  return 1;
136  return 0;
137  }
138  const UT_Array<UT_Vector3> &myPoints;
139 };
140 
141 /// NOTE: Although tree is non-const, this is safe to call from multiple
142 /// threads with the same tree.
143 template<typename POLY>
145  const POLY &poly,
146  const UT_Vector2 *attribvalues,// 3 or 4 values, depending on tri or quad
147  GEO_2DTree &tree,
148  ut_KDPQueue *kdqueue, // Just here to avoid reallocating on every query
149  UT_IntArray &temp, // ''
150  UT_Array<UT_Vector2> &temp2, // ''
151  UT_Array<UT_Vector3> &primuvwsarray,
152  UT_Array<exint> &treepointnumsarray,
153  float tolerance = 1e-7f,
154  bool wrapunitsquare = false);
155 
156 /// NOTE: Although tree is non-const, this is safe to call from multiple
157 /// threads with the same tree.
159  const GEO_PrimTetrahedron &tet,
160  const UT_Vector3 *attribvalues,// 4 values
161  GEO_3DTree &tree,
162  ut_KDPQueue *kdqueue, // Just here to avoid reallocating on every query
163  UT_IntArray &temp, // ''
164  UT_Array<UT_Vector3> &temp2, // ''
165  UT_Array<UT_Vector3> &primuvwsarray,
166  UT_Array<exint> &treepointnumsarray,
167  float tolerance = 1e-7f,
168  bool wrapunitcube = false);
169 
170 /// Finds, for each element in queryrange, the primitive number and primitive
171 /// uvw in searchindetail at which searchingattrib matches queryattrib.
172 ///
173 /// If appropriate, it interpolates inside (convexed) polygons and tetrahedra
174 /// to find matching values. Anything that has no match will not be
175 /// written-to, in case you want to do multiple queries, so make sure to
176 /// initialize foundprimnums to -1 (default value -1 suffices).
177 ///
178 /// Returns false if the attributes aren't compatible with this querying.
179 /// searchinattrib must be a numeric, float, point or vertex attribute,
180 /// queryattrib must be a numeric, float or int attribute of any owner,
181 /// and the two must have the same tuple size. searchinrange must be
182 /// a primitive range.
183 template<typename INT>
184 bool GEOfindAttrib(
185  const GA_Attribute *queryattrib,
186  const GA_Range &queryrange,
187  const GEO_Detail &searchindetail,
188  const GA_Range &searchinrange,
189  const GA_Attribute *searchinattrib,
190  const GA_RWHandleT<INT> &foundprimnums,
191  const GA_RWHandleV3 &foundprimuvws,
192  float tolerance = 1e-7f,
193  bool wrapunitcube = false);
194 
195 template<typename INT>
196 bool GEOfindAttrib(
197  const GA_Attribute *queryattrib,
198  const GA_Range &queryrange,
199  const GEO_Detail &searchindetail,
200  const GA_Range &searchinrange,
201  const GA_Attribute *searchinattrib,
202  const GA_RWHandleT<UT_ValArray<INT> > &foundprimnums,
203  const GA_RWHandleT<UT_Fpreal32Array> &foundprimuvws,
204  float tolerance = 1e-7f,
205  bool wrapunitcube = false);
206 
207 template<typename INT>
208 void GEOfindAttrib(
209  const UT_Array<UT_Vector3> &queries,
210  const GEO_Detail &searchindetail,
211  const GA_Range &searchinrange,
212  const GA_Attribute *searchinattrib,
213  UT_Array<INT> &foundprimnums,
214  UT_Array<UT_Vector3> &foundprimuvws,
215  float tolerance = 1e-7f,
216  bool wrapunitcube = false);
217 
218 /// Finds, for each element in queryrange, the vertex or point numbers
219 /// and corresponding weights in searchindetail at which searchingattrib
220 /// matches queryattrib.
221 ///
222 /// If appropriate, it interpolates inside (convexed) polygons and tetrahedra
223 /// to find matching values. Anything that has no match will not be
224 /// written-to, in case you want to do multiple queries, so make sure to
225 /// initialize foundprimnums to -1 (default value -1 suffices).
226 ///
227 /// With this version, for polygons with 5 or more
228 /// sides, only up to 4 indices and weights are produced, because it
229 /// considers the convexed polygons produced by GEOconvexPoly, producing
230 /// results more consistent with Mantra.
232  const GA_Attribute *queryattrib,
233  const GA_Range &queryrange,
234  const GEO_Detail &searchindetail,
235  const GA_Range &searchinrange,
236  const GA_Attribute *searchinattrib,
237  GA_AttributeOwner indexattrib,
238  GA_Attribute *foundindexattrib,
239  GA_Attribute *foundweightsattrib,
240  bool wrapunitcube = false);
241 
243  const UT_Array<UT_Vector3> &queries,
244  const GEO_Detail &searchindetail,
245  const GA_Range &searchinrange,
246  const GA_Attribute *searchinattrib,
247  GA_AttributeOwner indexattrib,
248  UT_Array<GEO_TriOrQuadT<GA_Offset> > &foundindexattrib,
249  UT_Array<GEO_TriOrQuadT<float> > &foundweightsattrib,
250  bool wrapunitcube = false);
251 
252 #endif
void setBalancer(ut_KDBalancer balance)
Definition: UT_KDTree.h:535
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
void updatePoints(bool enable_multithreading=true)
GEO_3DTree(const UT_Array< UT_Vector3 > &points)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GEO_2DTree(const UT_Array< UT_Vector2 > &points)
void flagDirty()
Definition: UT_KDTree.h:549
void updatePoints()
3D Vector class.
A range of elements in an index-map.
Definition: GA_Range.h:42
const UT_Vector3 & getValue(int idx) const
bool GEOfindAttrib(const GA_Attribute *queryattrib, const GA_Range &queryrange, const GEO_Detail &searchindetail, const GA_Range &searchinrange, const GA_Attribute *searchinattrib, const GA_RWHandleT< INT > &foundprimnums, const GA_RWHandleV3 &foundprimuvws, float tolerance=1e-7f, bool wrapunitcube=false)
GLfloat f
Definition: glcorearb.h:1925
#define GEO_API
Definition: GEO_API.h:10
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
virtual const float * getP(int idx) const =0
Return the position associated with the given point.
GA_AttributeOwner
Definition: GA_Types.h:33
virtual int comparePosition(int idx0, int idx1, int dim) const =0
png_infop png_sPLT_tpp entries
Definition: png.h:2481
void balance(bool enable_multithreading=true)
const UT_Vector2 & getValue(int idx) const
void GEOpickUpAttribPoints(const POLY &poly, const UT_Vector2 *attribvalues, GEO_2DTree &tree, ut_KDPQueue *kdqueue, UT_IntArray &temp, UT_Array< UT_Vector2 > &temp2, UT_Array< UT_Vector3 > &primuvwsarray, UT_Array< exint > &treepointnumsarray, float tolerance=1e-7f, bool wrapunitsquare=false)
virtual void buildIfNeeded(bool enable_multithreading=true)
This must be called before querying, to build and balance the tree.