HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_MergeOffsetMap.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: GA_MergeOffsetMap.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_MergeOffsetMap__
12 #define __GA_MergeOffsetMap__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include "GA_Range.h"
17 #include "GA_MergeOptions.h"
18 
19 #include <UT/UT_ArrayMap.h>
20 
21 class GA_MergeMap;
22 class GA_MergeOptions;
23 
24 
25 /// @brief Keeps track of offset mapping when merging index lists
26 ///
27 /// When an index map is merged with an existing index map, there are several
28 /// different ways the index lists can be merged.
29 /// # A simple merge. This happens when the destination index map is empty.
30 /// # A full append merge. The source list is appended to the destination
31 /// # A full interleaved merge. Source elements use up holes in the dest.
32 /// # A selected merge. Only selected elements from the source are merged
33 ///
34 /// @see GA_MergeMap, GA_MergeOptions
35 ///
37 {
38 public:
40  const GA_Range *sit,
41  GA_AttributeOwner owner);
43 
45  { return myStrategy; }
46 
47  /// Create a merge-iterator. The merge iterator will iterate over the
48  /// source elements which are to be merged into the destination
49  const GA_Range &getSourceRange() const { return mySourceRange; }
50 
51  /// Create a merge-iterator. The merge iterator will iterate over the
52  /// elements which were created in the destination detail.
53  ///
54  /// @note It is more efficient to use mapDestFromSource() with the source
55  /// range, especially when iterating over both.
56  const GA_Range &getDestRange() const { return myDestRange; }
57 
58  /// The array capacity is the original capacity of attribute arrays.
59  /// This is set for MERGE_COPY, MERGE_APPEND and MERGE_INTERLEAVE.
61  { return myDestInitCapacity; }
62 
63  /// The array capacity is the required capacity of attribute arrays to
64  /// perform the merge. This is set for MERGE_COPY, MERGE_APPEND and
65  /// MERGE_INTERLEAVE, though in the MERGE_INTERLEAVE scenario, the
66  /// additional capacity will already have been allocated.
67  GA_Offset getDestCapacity() const { return myDestCapacity; }
68 
69  /// @{
70  /// Set for MERGE_COPY and MERGE_APPEND. Specify where in the attribute
71  /// arrays to place the merged source data.
72  GA_Offset getDestStart() const { return myDestStart; }
73  GA_Offset getDestEnd() const { return myDestEnd; }
74  /// @}
75 
76  /// Sets map to be a detail map (GA_Offset(0)-->GA_Offset(0))
77  void setDetail();
78 
79  /// Set destination offsets for source range
80  void setDestForSourceRange(GA_Offset d);
81 
82  /// Given the source offset, find the corresponding destination offset.
83  GA_Offset mapDestFromSource(GA_Offset source_offset) const;
84 
85  /// An identity map means mapDestFromSource(i) == i for all elements.
86  /// @note A false return value doesn't necessarily mean this map is not
87  /// an identity map, but only that our simple detection failed.
88  bool isIdentityMap() const;
89 
90  /// @private Used by the index map to set the destination initial capacity
91  /// for merging. Valid for MERGE_COPY, MERGE_APPEND, MERGE_INTERLEAVE.
92  void setDestInitCapacity(GA_Offset s)
93  { myDestInitCapacity = s; }
94 
95  /// @private Used by the index map to set the destination capacity for
96  /// merging. Valid for MERGE_COPY, MERGE_APPEND, MERGE_INTERLEAVE.
97  void setDestCapacity(GA_Offset s) { myDestCapacity = s; }
98 
99  /// @{
100  /// @private Used by the index map to set the destination range where
101  /// the merged data is to be placed (MERGE_COPY, MERGE_APPEND). This
102  /// range is inclusive [start..end].
103  void setDestStart(GA_Offset s) { myDestStart = s; }
104  void setDestEnd(GA_Offset e) { myDestEnd = e; }
105  /// @}
106 
107  /// @private Used by the GA_MergeMap to finish constructing iterators
108  void makeRanges(GA_MergeMap &map);
109 
110  /// @private Used by the GA_MergeMap to finish constructing trivial map
111  void makeTrivialRanges(GA_MergeMap &map);
112 
113  /// @private Used to fill out GA_MergeOptions point maps
114  void buildOptionPointMaps(GA_MergeOptions &options);
115 
116  /// Returns true if the map is trivial
117  bool isTrivial() const { return myIsTrivial; }
118 
119  /// Returns the value that should be added to source indices to
120  /// map onto destination indices
121  GA_Size getTrivialDiff() const { return myTrivialSrcToDest; }
122 
123 protected:
124  /// Builds the myOffsetArray or myOffsetTable
125  /// Assumes already guaranteed not trivial.
126  void buildSourceToDestMap(GA_Offset d);
127 
128 private:
129  // Since hboost::hash is an identity function for integers, the offset
130  // table has a good chance of having multiple sequential ranges that hash
131  // to the same range of values modulo the number of buckets. A custom hash
132  // function is used to avoid this worst-case behavior in UT_ArraySet.
133  struct OffsetHash
134  {
135  SYS_FORCE_INLINE size_t operator()(GA_Offset val) const
136  {
137  return SYSmultiplicative_inthash64(size_t(val));
138  }
139  };
140 
141  using OffsetTable = UT_ArrayMap<
142  GA_Offset,
143  GA_Offset,
144  false,
145  128,
147  OffsetHash>;
148 
149  GA_MergeMap &myMap;
150  GA_Range mySourceRange, myDestRange;
151  UT_Array<GA_Offset> *myOffsetArray;
152  OffsetTable *myOffsetTable;
153  GA_Offset myDestStart, myDestEnd;
154  GA_Offset myDestInitCapacity, myDestCapacity;
155  GA_AttributeOwner myOwner;
157  bool myIsTrivial;
158  GA_Size myTrivialSrcToDest;
159  /// NOTE: myTrivialDestEnd is the end of the trivial range (NOT minus 1);
160  /// myDestEnd is sometimes instead the offset *capacity* (minus 1).
161  GA_Offset myTrivialDestEnd;
162  /// Mapping not yet built, but delayed.
163  bool myDelayedMap;
164  mutable int myDelayedMapBuilt;
165 };
166 
167 #endif
void setDestEnd(GA_Offset e)
GA_MergeOptions::MergeStrategy getMergeStrategy() const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
GA_Offset getDestInitCapacity() const
GLdouble s
Definition: glad.h:3009
const GA_Range & getSourceRange() const
#define GA_API
Definition: GA_API.h:14
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
GA_Size GA_Offset
Definition: GA_Types.h:646
GA_Offset getDestCapacity() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Keeps track of offset mapping when merging index lists.
GA_Offset getDestEnd() const
const GA_Range & getDestRange() const
GA_AttributeOwner
Definition: GA_Types.h:35
GLuint GLfloat * val
Definition: glcorearb.h:1608
bool isTrivial() const
Returns true if the map is trivial.
Provide options when performing a merge operation.
GA_Size getTrivialDiff() const
GA_Offset getDestStart() const