HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_PointGrid.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_PointGrid (GEO Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __GEO_PointGrid_h__
13 #define __GEO_PointGrid_h__
14 
15 #include <UT/UT_PointGrid.h>
16 #include <UT/UT_Assert.h>
17 
18 #include <GA/GA_Types.h>
19 #include <GA/GA_OffsetList.h>
20 
21 #include <GEO/GEO_Detail.h>
22 
23 template <typename INDEX, typename KEY>
25 {
26 public:
28  const GA_PointGroup *ptgrp = NULL):
29  myGdp(gdp), myPtgrp(ptgrp),
30  myOffsets(NULL), myBuilt(false)
31  {
33  }
34 
36  {
37  delete myOffsets;
38  }
39 
40  // indextype must be signed.
41  typedef INDEX indextype;
42  typedef KEY keytype;
43 
44  /// Invalid key value.
45  static const keytype INVALIDKEY;
46 
47  // Return GA_Size instead of indextype so UT_PointGrid::canBuild can
48  // test if points will fit in 32-bit index.
49  GA_Size entries() const
50  {
52  return myOffsets ? myOffsets->entries() : myGdp->getNumPoints();
53  }
54 
56  {
58  return myOffsets ? myGdp->getPos3(myOffsets->get(idx)) :
60  }
61 
63  {
65  // If no offset list exists, then the index represents the GA_Index
66  // within the entire GEO_Detail. If the point is not in a specified
67  // point group, just return invalid, which tells the calling PointGrid
68  // to skip adding this point to the grid.
69  if (myOffsets)
70  return keytype(myOffsets->get(idx));
71  if (!myPtgrp)
72  return keytype(myGdp->pointOffset(idx));
73  GA_Offset ptoff = myGdp->pointOffset(idx);
74  return myPtgrp->containsOffset(ptoff) ? keytype(ptoff) : INVALIDKEY;
75  }
76 
77  // Return GA_Size instead of keytype so UT_PointGrid::canBuild can
78  // test if key will fit in 32-bit.
80  {
81  return myGdp->getPointMap().offsetSize();
82  }
83 
85  {
88  (myOffsets ? myOffsets->getMemoryUsage(true) : 0);
89  }
90 
91  // If a small enough point group is specified, build a contiguous list
92  // of GA_Offsets. The above functions then use the index into
93  // this list to reference each point in sequence.
94  void build()
95  {
96  if (myPtgrp)
97  {
98  GA_Size numGroupPts = myPtgrp->entries();
99  GA_Size numPts = myGdp->getNumPoints();
100  // Only create offsets list if group comprises < 90% of all points.
101  if (fpreal(numGroupPts) / numPts < 0.9)
102  {
103  myOffsets = new GA_OffsetList();
104  myOffsets->setEntries(numGroupPts);
105  GA_Size i = 0;
107  !it.atEnd();
108  ++it)
109  myOffsets->set(i++, *it);
110  }
111  }
112  myBuilt = true;
113  }
114 
115 protected:
119  bool myBuilt;
120 };
121 
122 
123 // Default invalid key value.
124 template <typename INDEX, typename KEY>
125 const KEY
127 
128 
133 
134 #endif
GA_OffsetList * myOffsets
Iteration over a range of elements This class implements a point-in-grid acceleration structure that ...
Definition: UT_PointGrid.h:21
Iteration over a range of elements.
Definition: GA_Iterator.h:28
GA_OffsetListType< GA_Size > GA_OffsetList
GA_OffsetList is a map from index to offset.
virtual GA_Size entries() const final
Will return the number of primary elements.
UT_PointGrid< GEO_PointGridGDPAccessor< GA_Size, GA_Offset > > GEO_PointGrid
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:170
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GA_Size maxKeyValue() const
Definition: GEO_PointGrid.h:79
GEO_PointGrid::queuetype GEO_PointGridQueue
SYS_FORCE_INLINE int64 getMemoryUsage(bool inclusive) const
Report memory usage (includes all shared memory)
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
void set(FromType index, ToType value)
Set the index to the value.
GA_Size GA_Offset
Definition: GA_Types.h:617
bool atEnd() const
Definition: GA_Iterator.h:100
long long int64
Definition: SYS_Types.h:106
UT_PointGrid< GEO_PointGridGDPAccessor< int32, uint32 > > GEO_PointGrid32
const GEO_Detail * myGdp
GA_Range getPointRange(const GA_PointGroup *group=0) const
Get a range of all points in the detail.
Definition: GA_Detail.h:1616
const GA_IndexMap & getPointMap() const
Definition: GA_Detail.h:664
UT_Vector3 getPos(indextype idx) const
Definition: GEO_PointGrid.h:55
GA_Iterator begin() const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
int64 getMemoryUsage() const
Definition: GEO_PointGrid.h:84
keytype getKey(indextype idx) const
Definition: GEO_PointGrid.h:62
GEO_PointGrid32::queuetype GEO_PointGrid32Queue
GEO_PointGridGDPAccessor(const GEO_Detail *gdp, const GA_PointGroup *ptgrp=NULL)
Definition: GEO_PointGrid.h:27
SYS_FORCE_INLINE bool containsOffset(GA_Offset offset) const
double fpreal
Definition: SYS_Types.h:269
const GA_PointGroup * myPtgrp
static const keytype INVALIDKEY
Invalid key value.
Definition: GEO_PointGrid.h:45
GA_Size entries() const
Definition: GEO_PointGrid.h:49
void setEntries(FromType sz, bool doresize=true)
SYS_FORCE_INLINE ToType get(FromType index) const
Get the the value at the index.
SYS_FORCE_INLINE GA_Offset pointOffset(GA_Index index) const
Given a point's index (in append order), return its data offset.
Definition: GA_Detail.h:292
SYS_FORCE_INLINE GA_Offset offsetSize() const
Definition: GA_IndexMap.h:97
SYS_FORCE_INLINE GA_Size getNumPoints() const
Return the number of points.
Definition: GA_Detail.h:281
SYS_FORCE_INLINE FromType entries() const
Returns the number of used elements in the list (always <= capacity())