HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_BVH.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_BVH.h (GEO Library, C++)
7  *
8  * COMMENTS: Bounding Volume Hierarchy (BVH) implementation for GEO_Detail.
9  */
10 
11 #pragma once
12 
13 #include "GEO_API.h"
14 #include <GA/GA_Handle.h>
15 #include <GA/GA_Types.h>
16 #include <UT/UT_BVH.h>
17 #include <UT/UT_UniquePtr.h>
18 #include <UT/UT_Vector3.h>
19 #include <limits>
20 
21 #define GEO_BVH_INTERLEAVED 1
22 #if GEO_BVH_INTERLEAVED
23 #include <VM/VM_SIMD.h>
24 #endif
25 
26 class GEO_Detail;
27 
28 namespace GEO {
29 
30 template<uint NAXES,typename SUBCLASS>
32 {
33 public:
34  BVHBase() noexcept
35  : myHasCurvesOrPoints(false)
36  {}
37  ~BVHBase() noexcept {}
38 
42 #if !GEO_BVH_INTERLEAVED
44 #else
46 #endif
47 
48 protected:
49  void clear() noexcept;
50 public:
51 
52  SYS_FORCE_INLINE bool isEmpty() const noexcept
53  {
54  return myTree.getNumNodes() == 0;
55  }
56 
57  struct ItemHitInfo
58  {
59  exint myItemIndex = -1;
61  };
62  struct CommonHitInfo : public ItemHitInfo
63  {
64  using ItemHitInfo::myItemIndex;
65  using ItemHitInfo::myUVW;
66 
67  /// This can be used for packed primitive hits.
68  UT_Array<exint> *myNestedItemIndices = nullptr;
69 
70  SYS_FORCE_INLINE bool isHit() const noexcept
71  {
72  return (myItemIndex >= 0);
73  }
74  };
75  struct HitInfo : public CommonHitInfo
76  {
77  float myT = -1;
78  };
79  struct HitInfoAndNormal : public HitInfo
80  {
82  };
83 
84  /// Sends a ray from the specified origin in the specified direction and
85  /// finds the closest (or farthest) intersection.
86  /// Potential hits less than tmin or greater than tmax from the origin are
87  /// treated as not having been hit, regardless of whether farthest is true.
88  /// If rm_backface is true, backface hits will be treated as no hit,
89  /// and if reverse is also true, frontface hits will be treated as no hit.
90  /// NOTE: If the hit_info.myNestedItemIndices is non-null,
91  /// it will be filled with the hit path,
92  /// ignoring the outermost index, which is in hit_info.myItemIndex.
93  template<bool farthest=false,bool rm_backface=false,bool reverse=false,typename HitInfoType>
94  void sendRay(const VectorType &origin, const VectorType &direction, HitInfoType &hit_info,
95  float tmin = 0, float tmax = std::numeric_limits<float>::max()) const noexcept;
96 
97  /// Like sendRay, except with a radius (tolerance) for curve and point hits,
98  /// in case myRadii is empty.
99  template<bool farthest=false,bool rm_backface=false,bool reverse=false,typename HitInfoType>
100  void sendRayRad(const VectorType &origin, const VectorType &direction, HitInfoType &hit_info,
101  float default_radius,
102  float tmin = 0, float tmax = std::numeric_limits<float>::max()) const noexcept;
103 
104  /// Sends a ray from the specified origin in the specified direction and
105  /// finds all intersections, removing all but one that are within
106  /// duplicate_tolerance of another hit.
107  /// Potential hits less than tmin or greater than tmax from the origin are
108  /// treated as not having been hit, regardless of whether farthest is true.
109  /// If rm_backface is true, backface hits will be treated as no hit,
110  /// and if reverse is also true, frontface hits will be treated as no hit.
111  /// NOTE: If nesting_temp_array is non-null, this function will allocate
112  /// nesting arrays for any applicable entries in hit_info, so the
113  /// caller is responsible for deleting myNestedItemIndices arrays in
114  /// hit_info. nesting_temp_array itself is just used for temporary
115  /// storage to reduce the number of allocations.
116  template<bool rm_backface=false,bool reverse=false,bool sort=true,typename HitInfoType>
117  void sendRayAll(const VectorType &origin, const VectorType &direction, UT_Array<HitInfoType> &hit_info,
118  UT_Array<exint> *nesting_temp_array=nullptr,
119  float duplicate_tolerance = 0,float tmin = 0, float tmax = std::numeric_limits<float>::max()) const noexcept;
120 
121  /// Like sendRayAll, except with a radius (tolerance) for curve and point hits,
122  /// in case myRadii is empty.
123  template<bool rm_backface=false,bool reverse=false,bool sort=true,typename HitInfoType>
124  void sendRayAllRad(const VectorType &origin, const VectorType &direction, UT_Array<HitInfoType> &hit_info,
125  float default_radius, UT_Array<exint> *nesting_temp_array=nullptr,
126  float duplicate_tolerance = 0,float tmin = 0, float tmax = std::numeric_limits<float>::max()) const noexcept;
127 
128 protected:
129  template<bool USE_TOLERANCE>
131  template<bool USE_TOLERANCE>
133  template<bool USE_TOLERANCE>
135  template<bool USE_TOLERANCE>
137 public:
138 
139  template<bool farthest,bool rm_backface,bool reverse,typename FUNCTOR>
140  void sendRayGeneric(VectorType origin, VectorType direction, FUNCTOR &hit_info,
141  float tmin = 0, float tmax = std::numeric_limits<float>::max()) const noexcept;
142 
143  struct MinInfo : public CommonHitInfo
144  {
145  float myDistSquared = -1;
147  };
148 
149  /// Finds the closest points to the infinite line containing `origin` with direction `direction`.
150  void findClosestToLine(VectorType origin, VectorType direction, const exint max_points, const float max_dist_squared,
151  UT::BVHOrderedStack& output_queue) const noexcept;
152 
153  /// Finds the closest points to the line segment with endpoints `p0` and `p1`.
154  void findClosestToSegment(VectorType p0, VectorType p1, const exint max_points, const float max_dist_squared,
155  UT::BVHOrderedStack& output_queue) const noexcept;
156 
157  /// Finds the closest points from the origin to any surface within max_dist_squared, within the cone containing
158  /// all points at most `angle` away from `direction`.
159  void findClosestInCone(VectorType origin, VectorType direction, const float angle, const exint max_points,
160  const float max_dist_squared, UT::BVHOrderedStack& output_queue) const noexcept;
161 
162  /// Finds the closest (or farthest) position to origin on any surface, as long as it's within max_dist_squared.
163  /// NOTE: If farthest is true, max_dist_squared is actually the *minimum* distance squared from the origin,
164  /// so you will need to specify a value.
165  template<bool farthest>
166  void findClosest(VectorType origin, MinInfo &min_info, float max_dist_squared = std::numeric_limits<float>::max()) const noexcept;
167 
168  /// Finds the closest (or farthest) position(s) to origin on any surface, as long as it's within
169  /// max_dist_squared.
170  /// NOTE: If farthest is true, max_dist_squared is actually the *minimum* distance squared from
171  /// the origin, so you will need to specify a value.
172  template<bool farthest>
173  void findProximity(UT_Array< MinInfo > &min_info, const VectorType &origin,
174  float max_dist_squared = std::numeric_limits<float>::max()) const noexcept;
175 
176  /// Fills box_indices array with the indices of all boxes intersecting query_box.
177  /// NOTE: This does not clear out previous contents of indices, so that you
178  /// can easily query intersection with multiple boxes.
179  /// WARNING: DO NOT depend on the order of box_indices. If you need a consistent order, sort it.
180  void getIntersectingBoxes(const SingleBoxType &query_box, UT_Array<exint> &box_indices) const noexcept;
181 
182  SYS_FORCE_INLINE exint numPoints() const noexcept
183  {
184  return myPoints.size();
185  }
186  SYS_FORCE_INLINE GA_Offset pointOffset(exint item_index) const noexcept
187  {
188  UT_ASSERT_P(item_index < numPoints());
189  return myPoints(item_index);
190  }
191 
192  /// Returns the geometric normal (not based on the N attribute) for the hit surface,
193  /// optionally normalized, since apparently Mantra doesn't need it normalized.
194  template<bool normalize=true>
195  VectorType getGeometricNormal(const CommonHitInfo &hit_info) const noexcept;
196 
197  /// Fills in the values of dP/du and dP/dv for the hit surface.
198  void getDerivs(const CommonHitInfo &hit_info, VectorType &dP_du, VectorType &dP_dv) const noexcept;
199 
200  /// For points, this converts the uvw from ItemHitInfo to polar form.
201  /// The original is effectively a normal.
202  static void pointUVWToPolar(VectorType &uvw) noexcept;
203 
204  /// Returns true on success, false on failure. The function can fail if the hit is on a point
205  /// and the attribute is a vertex or primitive attribute.
206  template<GA_AttributeOwner owner,typename T,typename DEST_T>
207  bool getAttribute(const CommonHitInfo &hit_info, const GA_ROHandleT<T> &attrib, const GEO_Detail &detail, DEST_T &value) const noexcept;
208 
209  SingleBoxType getBBox() const noexcept
210  {
211  SingleBoxType bbox;
212  if (isEmpty())
213  {
214  bbox.initBounds();
215  return bbox;
216  }
217 
218  BoxType &root_boxes = myNodeBoxes[0];
219  for (uint axis = 0; axis < NAXES; ++axis) {
220  SYS_STATIC_ASSERT(sizeof(root_boxes[axis][0]) == 4*sizeof(float));
221  float *vmin = (float*)&root_boxes[axis][0];
222  bbox[axis][0] = SYSmin(vmin[0],vmin[1],vmin[2],vmin[3]);
223  float *vmax = (float*)&root_boxes[axis][1];
224  bbox[axis][1] = SYSmax(vmax[0],vmax[1],vmax[2],vmax[3]);
225  }
226  return bbox;
227  }
228 
229 #ifdef GA_STRICT_TYPES
230  class PosAttribType : public GA_ROHandleT<VectorType>
231  {
232  using Parent = GA_ROHandleT<VectorType>;
233  public:
234  using Parent::Parent;
235  using Parent::operator[];
236  using Parent::operator=;
237 
238  SYS_FORCE_INLINE VectorType operator[](exint offset) const
239  {
240  return Parent::get(GA_Offset(offset));
241  }
242  };
243  class RadAttribType : public GA_ROHandleF
244  {
245  using Parent = GA_ROHandleF;
246  public:
247  using Parent::Parent;
248  using Parent::operator[];
249  using Parent::operator=;
250 
251  SYS_FORCE_INLINE float operator[](exint offset) const
252  {
253  return Parent::get(GA_Offset(offset));
254  }
255  };
256 #else
259 #endif
260 
261 protected:
262  SYS_FORCE_INLINE SUBCLASS *subclass() noexcept { return static_cast<SUBCLASS*>(this); }
263  SYS_FORCE_INLINE const SUBCLASS *subclass() const noexcept { return static_cast<const SUBCLASS*>(this); }
264 
265  // Iterates through the box hierachy and calls the given function
266  // when a distance criteria is satisfied.
267  template<bool farthest, typename FUNC>
268  int traverseBVH(const UT_FixedVector<v4uf,NAXES> &vorigin,
269  float &max_dist_squared, FUNC &op) const noexcept;
270 
271  template<bool farthest,typename QUERY_POINT>
272  void findMaximalPointsCommon(
273  const QUERY_POINT &query_point,
274  UT::BVHOrderedStack &stack,
275  UT::BVHOrderedStack &output_queue,
276  exint max_points,
277  float max_dist_squared) const noexcept;
278 
279  using NodeData = BoxType;
280 
281 #if !GEO_BVH_INTERLEAVED
282  static constexpr uint BVH_N = 2;
283 #else
284  static constexpr uint BVH_N = 4;
285 #endif
288  //UT_UniquePtr<uint[]> myIndices;
290 
291  /// Positions for points
293 
294  /// Radii for disconnected points
296 
297  /// Attribute for positions, to avoid having to copy all positions into
298  /// myPositions if only a small subset of points are needed.
300 
301  /// Attribute for radii, to avoid having to copy all radii into
302  /// myRadii if only a small subset of points are needed.
304 
305  /// Disconnected points
307 
308  /// Data IDs for myPositions and myRadii
309  /// @{
312  /// @}
313 
315 };
316 
317 #if 0
318 template<uint NAXES>
319 struct QueryPtWrapper {
320  SYS_FORCE_INLINE QueryPtWrapper(const UT_FixedVector<float,NAXES> &p)
321  : q(p), vq(p)
322  {}
323 
324  /// This is used for findClosest.
325  /// It can optionally return an underestimate, but NOT an overestimate.
326  /// @{
327  SYS_FORCE_INLINE float boxMinDist2(const UT::Box<float,NAXES> &box) const
328  { return box.minDistance2(q); }
329  SYS_FORCE_INLINE v4uf boxMinDist2(const UT::Box<v4uf,NAXES> &box) const
330  { return box.minDistance2(vq); }
331  /// @}
332 
333  /// This is used for findFarthest.
334  /// It can optionally return an overestimate, but NOT an underestimate.
335  /// @{
336  SYS_FORCE_INLINE float boxMaxDist2(const UT::Box<float,NAXES> &box) const
337  { return box.maxDistance2(q); }
338  SYS_FORCE_INLINE v4uf boxMaxDist2(const UT::Box<v4uf,NAXES> &box) const
339  { return box.maxDistance2(vq); }
340  /// @}
341 
342  /// This should be exact
344  { return q.distance2(p); }
345 
346  /// These are for culling the query space
347  /// @{
348  SYS_FORCE_INLINE constexpr bool isValid(const UT::Box<float,NAXES> &box) const
349  { return true; }
350  static constexpr bool theHasBoxValidCheck = false;
351  SYS_FORCE_INLINE constexpr v4uu isValid(const UT::Box<v4uf,NAXES> &box) const
352  { return v4uu(1); }
353  template<typename INT_TYPE>
354  SYS_FORCE_INLINE constexpr bool isValid(INT_TYPE index) const
355  { return true; }
356  SYS_FORCE_INLINE constexpr bool isValid(const UT_FixedVector<float,NAXES> &p) const
357  { return true; }
358  /// @}
359 
360 private:
363 };
364 
365 template<uint NAXES>
366 SYS_FORCE_INLINE QueryPtWrapper<NAXES> QueryPoint(const UT_FixedVector<float,NAXES> &p)
367 { return QueryPtWrapper<NAXES>(p); }
368 #endif
369 
370 template<uint NAXES>
371 class PointBVHT : public BVHBase<NAXES,PointBVHT<NAXES>>
372 {
373 public:
375  using typename Parent::VectorType;
376  using typename Parent::UintVectorType;
377  using typename Parent::SingleBoxType;
378  using typename Parent::BoxType;
379 
382 
383  /// NOTE: With this signature, radius is the point radius.
385  void init(const GA_Detail &detail,
386  const GA_ROHandleT<VectorType> &P,
387  const float radius = 0.0f,
388  const GA_Range *point_range=nullptr,
389  const bool force_rebalance=false) noexcept
390  {
391  init(detail, P, GA_ROHandleF(), radius, point_range, force_rebalance);
392  }
393 
394  /// NOTE: With this signature, P can have a tuple size other than 3,
395  /// though if tuple size is more than 3, only the first 3 components
396  /// will be used, and if tuple size is less than 3, the remaining
397  /// components will be treated as having value 0.0.
398  /// NOTE: With this signature, radius is the point radius.
400  void init(const GA_Detail &detail,
401  const GA_ROHandleF &P,
402  const float radius = 0.0f,
403  const GA_Range *point_range=nullptr,
404  const bool force_rebalance=false) noexcept
405  {
406  init(detail, P, GA_ROHandleF(), radius, point_range, force_rebalance);
407  }
408 
409  /// NOTE: With this signature, radscale scales the pscale attribute
410  /// if it's a valid attribute, else it's the point radius.
412  void init(const GA_Detail &detail,
413  const GA_ROHandleT<VectorType> &P,
414  const GA_ROHandleF &pscale,
415  const float radscale = 1.0f,
416  const GA_Range *point_range=nullptr,
417  const bool force_rebalance=false) noexcept
418  {
419  initAttribCommon(detail, P, pscale, radscale, point_range, force_rebalance);
420  }
421 
422  /// NOTE: With this signature, P can have a tuple size other than 3,
423  /// though if tuple size is more than 3, only the first 3 components
424  /// will be used, and if tuple size is less than 3, the remaining
425  /// components will be treated as having value 0.0.
426  /// NOTE: With this signature, radscale scales the pscale attribute
427  /// if it's a valid attribute, else it's the point radius.
429  void init(const GA_Detail &detail,
430  const GA_ROHandleF &P,
431  const GA_ROHandleF &pscale,
432  const float radscale = 1.0f,
433  const GA_Range *point_range=nullptr,
434  const bool force_rebalance=false) noexcept
435  {
436  // Check for tuple size match.
437  if (P.isValid() && P->getTupleSize() == NAXES)
438  initAttribCommon(detail, GA_ROHandleT<VectorType>(P.getAttribute()), pscale, radscale, point_range, force_rebalance);
439  else
440  initAttribCommon(detail, P, pscale, radscale, point_range, force_rebalance);
441  }
442 
443  /// NOTE: With this signature, radius is the point radius.
445  void init(const exint n,
446  const VectorType *P,
447  const float radius = 0.0f,
448  const bool rebalance=true) noexcept
449  {
450  init(n, P, nullptr, radius, rebalance);
451  }
452 
453  /// NOTE: With this signature, radscale scales the pscale values
454  /// if it's non-null, else it's the point radius.
455  GEO_API void init(const exint n,
456  const VectorType *P,
457  const float *pscale,
458  const float radscale = 1.0f,
459  const bool rebalance=true) noexcept;
460 
461 #if 0
462  /// Find the closest point to the position specified. This method
463  /// returns -1 if no point is found.
464  /// NOTE THAT max_distance_squared IS SQUARED DISTANCE.
465  template<bool farthest,typename QueryPointType>
467  const QueryPointType &pt,
468  QueueType &queue,
469  exint max_points = std::numeric_limits<exint>::max(),
470  IntArrayType *list = nullptr,
471  float max_distance_squared = std::numeric_limits<float>::max()) const noexcept;
472 #endif
473 
474  using typename Parent::ItemHitInfo;
475  using typename Parent::CommonHitInfo;
476  using typename Parent::HitInfo;
477  using typename Parent::MinInfo;
478  using Parent::numPoints;
479  using Parent::isEmpty;
480  using Parent::clear;
481 
482  /// Finds the closest points (up to max_points of them)
483  /// within sqrt(max_distance_squared) of query_pt
486  const VectorType &query_pt,
487  UT::BVHOrderedStack &stack,
488  UT::BVHOrderedStack &output_queue,
489  exint max_points = std::numeric_limits<uint>::max(),
490  float max_distance_squared = std::numeric_limits<float>::max()) const noexcept
491  {
492  findMaximalPoints<false>(query_pt, stack,
493  output_queue, max_points, max_distance_squared);
494  }
495 
496  /// Finds the farthest points (up to max_points of them)
497  /// at least sqrt(min_distance_squared) away from query_pt
500  const VectorType &query_pt,
501  UT::BVHOrderedStack &stack,
502  UT::BVHOrderedStack &output_queue,
503  exint max_points = std::numeric_limits<uint>::max(),
504  float min_distance_squared = 0.0f) const noexcept
505  {
506  findMaximalPoints<true>(query_pt, stack,
507  output_queue, max_points, min_distance_squared);
508  }
509 
510  /// Sorts results from findClosestPoints or findFarthestPoints by distance
511  /// squared, and, in the case of ties, by the point offsets.
512  /// If farthest is true, it puts farther distances first, and breaks
513  /// ties with larger offsets first.
514  template<bool farthest>
515  GEO_API void sortResults(UT::BVHOrderedStack &closepts) const noexcept;
516 
517  template<bool farthest>
519  const VectorType &query_pt,
520  UT::BVHOrderedStack &stack,
521  UT::BVHOrderedStack &output_queue,
522  exint max_points,
523  float max_distance_squared) const noexcept;
524 
525  /// Don't call this unless you really need to. It might have to change in the future.
526  /// The array is owned by myPoints.
527  GEO_API const exint *getPointsArray() const noexcept;
528 
529 protected:
530  static constexpr bool theHasPrimitives = false;
531  static constexpr bool theReordersPositions = true;
532 
533  using Parent::myTree;
534  using Parent::myNodeBoxes;
535  using Parent::myNodeNItems;
536  using Parent::myPositions;
537  using Parent::myRadii;
538  using Parent::myPosAttrib;
539  using Parent::myRadAttrib;
540  using Parent::myPoints;
541  using Parent::myPositionsDataId;
542  using Parent::myRadiiDataId;
544  using Parent::BVH_N;
545 
547  const GA_ROHandleT<VectorType> &P,
548  const GA_Range *point_range,
549  const bool topology_changed,
550  const GA_Size npoints) noexcept;
552  const GA_ROHandleF &P,
553  const GA_Range *point_range,
554  const bool topology_changed,
555  const GA_Size npoints) noexcept;
556 
557  /// This is instantiated for VectorType and float.
558  template<typename T>
560  const GA_Detail &detail,
561  const GA_ROHandleT<T> &P,
562  const GA_ROHandleF &pscale,
563  const float radscale,
564  const GA_Range *point_range,
565  const bool force_rebalance) noexcept;
566 
567  GEO_API void initCommon(bool topology_changed,
568  const VectorType *orig_order_positions,
569  const float *orig_order_radii) noexcept;
570 
571  template<bool farthest,bool rm_backface,bool reverse,typename FUNCTOR>
573  uint index, const VectorType &origin, const VectorType &direction,
574  const VectorType &inverse_direction,
575  int &max_dir, VectorType &N0, VectorType &N1,
576  float &outer_tmax, float &outer_tmin, FUNCTOR &hit_info) const noexcept
577  {
578  UT_ASSERT_MSG(0, "Base class should deal with intersecting points");
579  return false;
580  }
581  template<bool farthest>
583  uint index, const VectorType &origin, float &max_dist_squared,
584  exint &hit_index, UT_Vector3 &hit_uvw, VectorType &hit_position,
585  const UT_FixedVector<v4uf,NAXES> &vorigin,
586  UT_Array<exint> *nesting_array,
587  exint nesting_array_base) const noexcept
588  {
589  UT_ASSERT_MSG(0, "Base class should deal with findign closest points");
590  }
591  template<bool normalize>
592  SYS_FORCE_INLINE VectorType primGeometricNormal(const CommonHitInfo &hit_info) const noexcept
593  {
594  UT_ASSERT_MSG(0, "Base class should deal with normals for points");
595  return VectorType(float(0));
596  }
597  SYS_FORCE_INLINE void primDerivs(const CommonHitInfo &hit_info, VectorType &dP_du, VectorType &dP_dv) const noexcept
598  {
599  UT_ASSERT_MSG(0, "Base class should deal with derivatives for points");
600  }
601  template<GA_AttributeOwner owner,typename T,typename DEST_T>
602  SYS_FORCE_INLINE bool primAttribute(const CommonHitInfo &hit_info, const GA_ROHandleT<T> &attrib, const GEO_Detail &detail, DEST_T &value) const noexcept
603  {
604  UT_ASSERT_MSG(0, "Base class should deal with attributes for points");
605  return false;
606  }
607 
608 private:
609  friend Parent;
610 };
611 
614 
615 } // GEO namespace
616 
619 
620 #undef GEO_BVH_INTERLEAVED
type
Definition: core.h:556
#define SYSmax(a, b)
Definition: SYS_Math.h:1952
SYS_FORCE_INLINE void primDerivs(const CommonHitInfo &hit_info, VectorType &dP_du, VectorType &dP_dv) const noexcept
Definition: GEO_BVH.h:597
SYS_FORCE_INLINE VectorType primGeometricNormal(const CommonHitInfo &hit_info) const noexcept
Definition: GEO_BVH.h:592
static constexpr bool theReordersPositions
Definition: GEO_BVH.h:531
#define SYS_STATIC_ASSERT(expr)
GA_DataId myRadiiDataId
Definition: GEO_BVH.h:311
SYS_FORCE_INLINE bool primAttribute(const CommonHitInfo &hit_info, const GA_ROHandleT< T > &attrib, const GEO_Detail &detail, DEST_T &value) const noexcept
Definition: GEO_BVH.h:602
SIM_API const UT_StringHolder angle
bool myHasCurvesOrPoints
Definition: GEO_BVH.h:314
RadAttribType myRadAttrib
Definition: GEO_BVH.h:303
__hostdev__ bool isValid(GridType gridType, GridClass gridClass)
return true if the combination of GridType and GridClass is valid.
Definition: NanoVDB.h:860
SYS_FORCE_INLINE void init(const GA_Detail &detail, const GA_ROHandleF &P, const float radius=0.0f, const GA_Range *point_range=nullptr, const bool force_rebalance=false) noexcept
Definition: GEO_BVH.h:400
Definition: UT_BVH.h:37
void findClosest(VectorType origin, MinInfo &min_info, float max_dist_squared=std::numeric_limits< float >::max()) const noexcept
int64 GA_DataId
Definition: GA_Types.h:703
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
UT_Array< float > myRadii
Radii for disconnected points.
Definition: GEO_BVH.h:295
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GEO_API void findMaximalPoints(const VectorType &query_pt, UT::BVHOrderedStack &stack, UT::BVHOrderedStack &output_queue, exint max_points, float max_distance_squared) const noexcept
int getTupleSize() const
UT_UniquePtr< BoxType[]> myNodeBoxes
Definition: GEO_BVH.h:287
UT_Array< VectorType > myPositions
Positions for points.
Definition: GEO_BVH.h:292
fpreal64 distance2(const UT_VectorD &v1, const UT_VectorD &v2)
Distance squared (L2) aka quadrance.
Definition: UT_Vector.h:399
int64 exint
Definition: SYS_Types.h:125
SYS_FORCE_INLINE GA_Offset pointOffset(exint item_index) const noexcept
Definition: GEO_BVH.h:186
PUGI__FN void reverse(I begin, I end)
Definition: pugixml.cpp:7458
static constexpr bool theHasPrimitives
Definition: GEO_BVH.h:530
SYS_FORCE_INLINE void initBounds() noexcept
Definition: UT_BVH.h:87
PUGI__FN void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7550
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
SYS_FORCE_INLINE void init(const GA_Detail &detail, const GA_ROHandleT< VectorType > &P, const float radius=0.0f, const GA_Range *point_range=nullptr, const bool force_rebalance=false) noexcept
NOTE: With this signature, radius is the point radius.
Definition: GEO_BVH.h:385
SYS_FORCE_INLINE exint numPoints() const noexcept
Definition: GEO_BVH.h:182
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:243
SYS_FORCE_INLINE void init(const exint n, const VectorType *P, const float radius=0.0f, const bool rebalance=true) noexcept
NOTE: With this signature, radius is the point radius.
Definition: GEO_BVH.h:445
PointBVHT< 2 > PointBVH_2D
Definition: GEO_BVH.h:613
A range of elements in an index-map.
Definition: GA_Range.h:42
SingleBoxType getBBox() const noexcept
Definition: GEO_BVH.h:209
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
SYS_FORCE_INLINE T minDistance2(const UT_FixedVector< T, NAXES > &p) const noexcept
Definition: UT_BVH.h:313
SYS_FORCE_INLINE void closestPrim(uint index, const VectorType &origin, float &max_dist_squared, exint &hit_index, UT_Vector3 &hit_uvw, VectorType &hit_position, const UT_FixedVector< v4uf, NAXES > &vorigin, UT_Array< exint > *nesting_array, exint nesting_array_base) const noexcept
Definition: GEO_BVH.h:582
#define UT_ASSERT_MSG(ZZ,...)
Definition: UT_Assert.h:168
const GA_ATINumeric * getAttribute() const
Definition: GA_Handle.h:168
GA_Size GA_Offset
Definition: GA_Types.h:653
PointBVHT< 3 > PointBVH
Definition: GEO_BVH.h:612
SYS_FORCE_INLINE void findClosestPoints(const VectorType &query_pt, UT::BVHOrderedStack &stack, UT::BVHOrderedStack &output_queue, exint max_points=std::numeric_limits< uint >::max(), float max_distance_squared=std::numeric_limits< float >::max()) const noexcept
Definition: GEO_BVH.h:485
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
GLintptr offset
Definition: glcorearb.h:665
SYS_FORCE_INLINE PointBVHT() noexcept
Definition: GEO_BVH.h:380
SYS_FORCE_INLINE ~PointBVHT() noexcept
Definition: GEO_BVH.h:381
UT_BVH< BVH_N > myTree
Definition: GEO_BVH.h:286
SYS_FORCE_INLINE T maxDistance2(const UT_FixedVector< T, NAXES > &p) const noexcept
Definition: UT_BVH.h:326
Definition: VM_SIMD.h:48
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:164
UT::Box< v4uf, NAXES > BoxType
Definition: GEO_BVH.h:45
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GA_ROHandleT< fpreal32 > GA_ROHandleF
Definition: GA_Handle.h:1403
Definition: VM_SIMD.h:188
#define GEO_API
Definition: GEO_API.h:14
SYS_FORCE_INLINE void findFarthestPoints(const VectorType &query_pt, UT::BVHOrderedStack &stack, UT::BVHOrderedStack &output_queue, exint max_points=std::numeric_limits< uint >::max(), float min_distance_squared=0.0f) const noexcept
Definition: GEO_BVH.h:499
void clear() noexcept
Definition: GEO_BVHImpl.h:34
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the queue
Definition: thread.h:632
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
Definition: UT_ARTMap.h:1173
typename SYS_SelectType< UT_Vector2, UT_Vector3, NAXES==3 >::type VectorType
Definition: GEO_BVH.h:39
typename SYS_SelectType< UT_FixedVector< uint, 2 >, UT_FixedVector< uint, 3 >, NAXES==3 >::type UintVectorType
Definition: GEO_BVH.h:40
BVHBase< NAXES, PointBVHT< NAXES >> Parent
Definition: GEO_BVH.h:374
BVHBase() noexcept
Definition: GEO_BVH.h:34
GEO_API const exint * getPointsArray() const noexcept
~BVHBase() noexcept
Definition: GEO_BVH.h:37
SYS_FORCE_INLINE bool isEmpty() const noexcept
Definition: GEO_BVH.h:52
SYS_FORCE_INLINE bool isValid() const
Definition: GA_Handle.h:194
GEO_API void fillPositionArray(const GA_ROHandleT< VectorType > &P, const GA_Range *point_range, const bool topology_changed, const GA_Size npoints) noexcept
SYS_FORCE_INLINE const SUBCLASS * subclass() const noexcept
Definition: GEO_BVH.h:263
typename SYS_SelectType< UT_Vector2, UT_Vector3, NAXES==3 >::type VectorType
Definition: GEO_BVH.h:39
GLuint index
Definition: glcorearb.h:786
UT_UniquePtr< UT_FixedVector< int32, BVH_N >[]> myNodeNItems
Definition: GEO_BVH.h:289
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder pscale
GEO_API void initCommon(bool topology_changed, const VectorType *orig_order_positions, const float *orig_order_radii) noexcept
SYS_FORCE_INLINE void init(const GA_Detail &detail, const GA_ROHandleT< VectorType > &P, const GA_ROHandleF &pscale, const float radscale=1.0f, const GA_Range *point_range=nullptr, const bool force_rebalance=false) noexcept
Definition: GEO_BVH.h:412
Container class for all geometry.
Definition: GA_Detail.h:105
GA_OffsetList myPoints
Disconnected points.
Definition: GEO_BVH.h:306
void getIntersectingBoxes(const UT::BVH< 4 > &bvh, const UT::Box< v4uf, NAXES > *node_boxes, const UT::Box< float, NAXES > &query_box, UT_Array< INT_TYPE > &box_indices, BVHUnorderedStack &stack) noexcept
Definition: UT_BVHImpl.h:2449
SYS_FORCE_INLINE SUBCLASS * subclass() noexcept
Definition: GEO_BVH.h:262
SYS_FORCE_INLINE bool isHit() const noexcept
Definition: GEO_BVH.h:70
PosAttribType myPosAttrib
Definition: GEO_BVH.h:299
#define SYSmin(a, b)
Definition: SYS_Math.h:1953
GA_DataId myPositionsDataId
Definition: GEO_BVH.h:310
GEO_API void sortResults(UT::BVHOrderedStack &closepts) const noexcept
unsigned int uint
Definition: SYS_Types.h:45
SYS_FORCE_INLINE bool intersectPrim(uint index, const VectorType &origin, const VectorType &direction, const VectorType &inverse_direction, int &max_dir, VectorType &N0, VectorType &N1, float &outer_tmax, float &outer_tmin, FUNCTOR &hit_info) const noexcept
Definition: GEO_BVH.h:572
#define GEO_API_TMPL
Definition: GEO_API.h:15
GEO_API void initAttribCommon(const GA_Detail &detail, const GA_ROHandleT< T > &P, const GA_ROHandleF &pscale, const float radscale, const GA_Range *point_range, const bool force_rebalance) noexcept
This is instantiated for VectorType and float.
UT::Box< float, NAXES > SingleBoxType
Definition: GEO_BVH.h:41
SYS_FORCE_INLINE void init(const GA_Detail &detail, const GA_ROHandleF &P, const GA_ROHandleF &pscale, const float radscale=1.0f, const GA_Range *point_range=nullptr, const bool force_rebalance=false) noexcept
Definition: GEO_BVH.h:429
VectorType myP
Definition: GEO_BVH.h:146