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 <UT/UT_Map.h>
15 #include "GA_API.h"
16 #include "GA_Types.h"
17 #include "GA_Range.h"
18 #include "GA_MergeOptions.h"
19 
20 
21 class GA_MergeMap;
22 class GA_MergeOptions;
23 template <typename T> class GA_TempBuffer;
24 
25 
26 /// @brief Keeps track of offset mapping when merging index lists
27 ///
28 /// When an index map is merged with an existing index map, there are several
29 /// different ways the index lists can be merged.
30 /// # A simple merge. This happens when the destination index map is empty.
31 /// # A full append merge. The source list is appended to the destination
32 /// # A full interleaved merge. Source elements use up holes in the dest.
33 /// # A selected merge. Only selected elements from the source are merged
34 ///
35 /// @see GA_MergeMap, GA_MergeOptions
36 ///
38 {
39 public:
41  const GA_Range *sit,
42  GA_AttributeOwner owner);
44 
46  { return myStrategy; }
47 
48  /// Create a merge-iterator. The merge iterator will iterate over the
49  /// source elements which are to be merged into the destination
50  const GA_Range &getSourceRange() const { return mySourceRange; }
51 
52  /// Create a merge-iterator. The merge iterator will iterate over the
53  /// elements which were created in the destination detail.
54  ///
55  /// @note It is more efficient to use mapDestFromSource() with the source
56  /// range, especially when iterating over both.
57  const GA_Range &getDestRange() const { return myDestRange; }
58 
59  /// The array capacity is the original capacity of attribute arrays.
60  /// This is set for MERGE_COPY, MERGE_APPEND and MERGE_INTERLEAVE.
62  { return myDestInitCapacity; }
63 
64  /// The array capacity is the required capacity of attribute arrays to
65  /// perform the merge. This is set for MERGE_COPY, MERGE_APPEND and
66  /// MERGE_INTERLEAVE, though in the MERGE_INTERLEAVE scenario, the
67  /// additional capacity will already have been allocated.
68  GA_Offset getDestCapacity() const { return myDestCapacity; }
69 
70  /// @{
71  /// Set for MERGE_COPY and MERGE_APPEND. Specify where in the attribute
72  /// arrays to place the merged source data.
73  GA_Offset getDestStart() const { return myDestStart; }
74  GA_Offset getDestEnd() const { return myDestEnd; }
75  /// @}
76 
77  /// Sets map to be a detail map (GA_Offset(0)-->GA_Offset(0))
78  void setDetail();
79 
80  /// Set destination offsets for source range
81  void setDestForSourceRange(GA_Offset d);
82 
83  /// Given the source offset, find the corresponding destination offset.
84  GA_Offset mapDestFromSource(GA_Offset source_offset) const;
85 
86  /// An identity map means mapDestFromSource(i) == i for all elements.
87  /// @note A false return value doesn't necessarily mean this map is not
88  /// an identity map, but only that our simple detection failed.
89  bool isIdentityMap() const;
90 
91  /// @private Used by the index map to set the destination initial capacity
92  /// for merging. Valid for MERGE_COPY, MERGE_APPEND, MERGE_INTERLEAVE.
93  void setDestInitCapacity(GA_Offset s)
94  { myDestInitCapacity = s; }
95 
96  /// @private Used by the index map to set the destination capacity for
97  /// merging. Valid for MERGE_COPY, MERGE_APPEND, MERGE_INTERLEAVE.
98  void setDestCapacity(GA_Offset s) { myDestCapacity = s; }
99 
100  /// @{
101  /// @private Used by the index map to set the destination range where
102  /// the merged data is to be placed (MERGE_COPY, MERGE_APPEND). This
103  /// range is inclusive [start..end].
104  void setDestStart(GA_Offset s) { myDestStart = s; }
105  void setDestEnd(GA_Offset e) { myDestEnd = e; }
106  /// @}
107 
108  /// @private Used by the GA_MergeMap to finish constructing iterators
109  void makeRanges(GA_MergeMap &map);
110 
111  /// @private Used by the GA_MergeMap to finish constructing trivial map
112  void makeTrivialRanges(GA_MergeMap &map);
113 
114  /// @private Used to fill out GA_MergeOptions point maps
115  void buildOptionPointMaps(GA_MergeOptions &options);
116 
117  /// Returns true if the map is trivial
118  bool isTrivial() const { return myIsTrivial; }
119 
120  /// Returns the value that should be added to source indices to
121  /// map onto destination indices
122  GA_Size getTrivialDiff() const { return myTrivialSrcToDest; }
123 
124 protected:
125  /// Builds the myOffsetArray or myOffsetTable
126  /// Assumes already guaranteed not trivial.
127  void buildSourceToDestMap(GA_Offset d);
128 
129 private:
130  GA_MergeMap &myMap;
131  GA_Range mySourceRange, myDestRange;
132  GA_TempBuffer<GA_Offset> *myOffsetArray;
133  UT_Map<GA_Offset, GA_Offset> *myOffsetTable;
134  GA_Offset myDestStart, myDestEnd;
135  GA_Offset myDestInitCapacity, myDestCapacity;
136  GA_AttributeOwner myOwner;
138  bool myIsTrivial;
139  GA_Size myTrivialSrcToDest;
140  /// NOTE: myTrivialDestEnd is the end of the trivial range (NOT minus 1);
141  /// myDestEnd is sometimes instead the offset *capacity* (minus 1).
142  GA_Offset myTrivialDestEnd;
143  /// Mapping not yet built, but delayed.
144  bool myDelayedMap;
145  mutable int myDelayedMapBuilt;
146 };
147 
148 #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
const GA_Range & getSourceRange() const
#define GA_API
Definition: GA_API.h:12
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_Offset getDestCapacity() const
Keeps track of offset mapping when merging index lists.
GA_Offset getDestEnd() const
const GA_Range & getDestRange() const
GA_AttributeOwner
Definition: GA_Types.h:33
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