HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_MergeMap.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_MergeMap.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_MergeMap__
12 #define __GA_MergeMap__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include "GA_MergeOptions.h"
17 #include "GA_MergeOffsetMap.h"
18 #include "GA_TempBuffer.h"
19 
20 #include <SYS/SYS_Types.h>
21 
22 #include <stddef.h>
23 
24 
25 class GA_Attribute;
26 class GA_Detail;
27 class GA_Range;
28 
29 
30 /// @brief The merge map keeps track of information when merging details
31 ///
32 /// Merging details involves merging
33 /// - Attributes
34 /// - Elements
35 /// This class keeps track of information between the different stages of
36 /// merging.
37 ///
38 /// When merging attribute data there are two different modes. The mode is per
39 /// attribute type (i.e. point data might be a full merge while primitives
40 /// might be a compact merge).
41 /// - <b>full merging</b> will copy the source arrays verbatim. Certain
42 /// optimizations may be possible using full merging in that it may be possible
43 /// to share data during the merge.
44 /// - <b>compact merging</b> will compact data data and produce a more compact
45 /// representation of the data. However, since the data is re-ordered, it may
46 /// not be possible to share data.
47 ///
48 /// When merging subsets of the source geometry, compact merging is
49 /// automatically turned on.
50 ///
51 /// @see GA_AIFMerge, GA_MergeOptions
52 ///
54 {
55 public:
56  GA_MergeMap(GA_Detail &dest, const GA_Detail &src, GA_MergeOptions &opts);
57  ~GA_MergeMap();
58 
59  /// Clear for multiple iterations
60  void clear();
61 
62  /// @{
63  /// When performing multiple merges of a single source geometry, this is
64  /// set to the iteration count.
65  GA_Size iterationCount() const { return myIteration; }
66  void setIterationCount(GA_Size i) { myIteration = i; }
67  /// @}
68 
69  /// Before the merge map can be used, the source & destination iterators
70  /// need to be created. This may also adjust index maps if they need to be
71  /// interleaved.
72  void createOffsetMaps();
73 
74  /// Creates a trivial merge map, and doesn't change the destination detail,
75  /// because the index maps are assumed to have already been updated.
76  void createTrivialMaps();
77 
78  /// Create offset maps for merging of global attributes
79  void createGlobalOffsetMap();
80 
81  /// Get the destination geometry
82  GA_Detail &getDestination() const { return myDest; }
83 
84  /// Get the source geometry
85  const GA_Detail &getSource() const { return mySource; }
86 
87  /// Get the merging options
88  GA_MergeOptions &getOptions() const { return myOptions; }
89 
90  /// Store a mapping between a source attribute and a destination attribute.
91  /// This is built automatically for during attribute processing during
92  /// merging. The GA_AIFMerge::getDestination() is used to define the map.
93  /// @see GA_AIFMerge
94  void setAttributeMap(const GA_Attribute &src,
95  GA_Attribute &dest);
96 
97  /// Retrieve the source attribute mapped to the destination attribute.
98  const GA_Attribute *getSourceAttribute(const GA_Attribute &dest) const;
99 
100  /// @{
101  /// Get the offset map for a class of elements.
102  /// @see GA_MergeOffsetMap
104  { return *myOffsetMaps[owner]; }
105  /// Convenience method to get iterator over the source elements
107  { return myOffsetMaps[owner]->getSourceRange(); }
108 
109  /// Convenience method to get iterator over the destination elements.
110  ///
111  /// @note It is more efficient to use mapDestFromSource() with the source
112  /// range, especially when iterating over both.
114  { return myOffsetMaps[owner]->getDestRange(); }
115 
116  /// Convenience method to get old destination size
118  { return myOffsetMaps[owner]->getDestInitCapacity(); }
119 
120  /// Convenience method to get new destination size
122  { return myOffsetMaps[owner]->getDestCapacity(); }
123 
124  /// @{
125  /// Convenience methods to get the destination range where the merged
126  /// data is to be placed (MERGE_COPY, MERGE_APPEND). This range is
127  /// inclusive [start..end].
129  { return myOffsetMaps[owner]->getDestStart(); }
131  { return myOffsetMaps[owner]->getDestEnd(); }
132  /// @}
133 
134  /// Convenience method to get the destination offset from the source offset
136  GA_Offset off) const
137  { return myOffsetMaps[own]->mapDestFromSource(off);}
138 
139  /// Convenience method to check for an identity offset map.
141  { return myOffsetMaps[own]->isIdentityMap(); }
142 
143  /// Convenience method to check for a trivial offset map.
145  { return myOffsetMaps[own]->isTrivial(); }
146 
147  /// Convenience method to check for the dest-source of a trivial offset map.
149  { return myOffsetMaps[own]->getTrivialDiff(); }
150 
151  /// Convenience method to get the merge strategy
152  /// @see GA_MergeOptions
155  { return myOffsetMaps[own]->getMergeStrategy(); }
156 
157  /// @}
158 
159  /// Used to fill out the GA_MergeOptions primitive maps, after the
160  /// primitives have been merged.
161  void buildMergeOptionPrimitiveMaps() const;
162 
164  {
165  public:
168 
169  void append(GA_Attribute &dest, const GA_Attribute &src)
170  {
171  myDest.append(&dest);
172  mySrc.append(&src);
173  }
175  {
176  myDest.reserve(entries);
177  mySrc.reserve(entries);
178  }
179  bool empty() const { return myDest.entries() == 0; }
180  exint entries() const { return myDest.entries(); }
181  GA_Attribute *getDest(exint i) const { return myDest(i); }
182  const GA_Attribute *getSrc(exint i) const { return mySrc(i); }
183  void clear()
184  {
185  myDest.clear();
186  mySrc.clear();
187  }
188 
190  {
191  public:
193  : myI(0)
194  , myEnd(0)
195  , myMap(NULL)
196  {
197  }
199  : myI(src.myI)
200  , myEnd(src.myEnd)
201  , myMap(src.myMap)
202  {
203  }
205  {
206  myI = src.myI;
207  myEnd = src.myEnd;
208  myMap = src.myMap;
209  return *this;
210  }
211  bool operator==(const const_iterator &src) const
212  {
213  return myI == src.myI &&
214  myEnd == src.myEnd &&
215  myMap == src.myMap;
216  }
217  bool operator!=(const const_iterator &src) const
218  { return !(*this == src); }
219  exint operator*() const { return myI; }
220  bool atEnd() const { return myI == myEnd; }
221  void advance() { ++myI; }
222  void rewind() { myI = 0; }
223  const_iterator &operator++() { advance(); return *this; }
224 
225  GA_Attribute *getDest() const { return myMap->getDest(myI); }
226  const GA_Attribute *getSrc() const { return myMap->getSrc(myI); }
227 
228  private:
229  const_iterator(const AttributeMap *map, exint where)
230  : myI(where)
231  , myEnd(map->entries())
232  , myMap(map)
233  {
234  }
235  const AttributeMap *myMap;
236  exint myI, myEnd;
237  friend class AttributeMap;
238  };
239 
240  const_iterator begin() const { return const_iterator(this, 0); }
241  const_iterator end() const { return const_iterator(this, entries()); }
242 
243  private:
246  };
247 
248  /// Access the attribute map that maps between the destination and source
249  /// attributes.
250  /// The key is the destination attribute, the value is the source
251  /// attribute. All values are stored as pointers.
253  {
254  return myAttributeMap;
255  }
256 private:
257  /// Used to fill out the GA_MergeOptions point maps
258  void buildMergeOptionPointMaps() const;
259 
260  GA_MergeOptions &myOptions;
261  GA_Detail &myDest;
262  const GA_Detail &mySource;
263  GA_Size myIteration;
264  AttributeMap myAttributeMap;
265  GA_MergeOffsetMap *myOffsetMaps[4];
266 };
267 
268 #endif
bool operator==(const const_iterator &src) const
Definition: GA_MergeMap.h:211
bool isTrivialMap(GA_AttributeOwner own) const
Convenience method to check for a trivial offset map.
Definition: GA_MergeMap.h:144
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
GA_Size getTrivialDiff(GA_AttributeOwner own) const
Convenience method to check for the dest-source of a trivial offset map.
Definition: GA_MergeMap.h:148
GA_MergeOptions & getOptions() const
Get the merging options.
Definition: GA_MergeMap.h:88
bool isIdentityMap(GA_AttributeOwner own) const
Convenience method to check for an identity offset map.
Definition: GA_MergeMap.h:140
const_iterator end() const
Definition: GA_MergeMap.h:241
const_iterator begin() const
Definition: GA_MergeMap.h:240
const_iterator & operator=(const const_iterator &src)
Definition: GA_MergeMap.h:204
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
#define GA_API
Definition: GA_API.h:12
const GA_Attribute * getSrc(exint i) const
Definition: GA_MergeMap.h:182
GA_Offset getDestEnd(GA_AttributeOwner owner) const
Definition: GA_MergeMap.h:130
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
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Offset mapDestFromSource(GA_AttributeOwner own, GA_Offset off) const
Convenience method to get the destination offset from the source offset.
Definition: GA_MergeMap.h:135
const GA_Attribute * getSrc() const
Definition: GA_MergeMap.h:226
void reserve(exint entries)
Definition: GA_MergeMap.h:174
GA_Size GA_Offset
Definition: GA_Types.h:617
const GA_Detail & getSource() const
Get the source geometry.
Definition: GA_MergeMap.h:85
void append(GA_Attribute &dest, const GA_Attribute &src)
Definition: GA_MergeMap.h:169
const GA_Range & getSourceRange(GA_AttributeOwner owner) const
Convenience method to get iterator over the source elements.
Definition: GA_MergeMap.h:106
int64 exint
Definition: SYS_Types.h:109
const_iterator(const const_iterator &src)
Definition: GA_MergeMap.h:198
GA_Attribute * getDest(exint i) const
Definition: GA_MergeMap.h:181
void setIterationCount(GA_Size i)
Definition: GA_MergeMap.h:66
exint entries() const
Definition: GA_MergeMap.h:180
Keeps track of offset mapping when merging index lists.
GA_Size iterationCount() const
Definition: GA_MergeMap.h:65
GA_AttributeOwner
Definition: GA_Types.h:33
png_infop png_sPLT_tpp entries
Definition: png.h:2481
bool operator!=(const const_iterator &src) const
Definition: GA_MergeMap.h:217
GA_MergeOptions::MergeStrategy getMergeStrategy(GA_AttributeOwner own) const
Definition: GA_MergeMap.h:154
GA_Detail & getDestination() const
Get the destination geometry.
Definition: GA_MergeMap.h:82
const AttributeMap & getAttributeMap() const
Definition: GA_MergeMap.h:252
Provide options when performing a merge operation.
Container class for all geometry.
Definition: GA_Detail.h:96
GA_Offset getDestCapacity(GA_AttributeOwner owner) const
Convenience method to get new destination size.
Definition: GA_MergeMap.h:121
const GA_Range & getDestRange(GA_AttributeOwner owner) const
Definition: GA_MergeMap.h:113
GA_MergeOffsetMap & getOffsetMap(GA_AttributeOwner owner) const
Definition: GA_MergeMap.h:103
GA_Offset getDestStart(GA_AttributeOwner owner) const
Definition: GA_MergeMap.h:128
GLenum src
Definition: glcorearb.h:1792
GA_Offset getDestInitCapacity(GA_AttributeOwner owner) const
Convenience method to get old destination size.
Definition: GA_MergeMap.h:117