HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_ATITopology.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_ATITopology.h ( GA Library, C++)
7  *
8  * COMMENTS: Topology ATI (Attribute Type Implementation)
9  *
10  * Topology attributes are used to store information about how
11  * elements are connected together.
12  */
13 
14 #pragma once
15 
16 #ifndef __GA_ATITopology__
17 #define __GA_ATITopology__
18 
19 #define USE_PAGEARRAY_TOPOLOGY 1
20 #if USE_PAGEARRAY_TOPOLOGY
21 #include "GA_PageArray.h"
22 #else
23 #include "GA_DataArray.h"
25 #endif
26 
27 #include "GA_API.h"
28 #include "GA_Attribute.h"
29 #include "GA_AttributeType.h"
30 #include "GA_IndexMap.h"
31 #include "GA_Types.h"
32 
33 #include <UT/UT_Assert.h>
34 #include <UT/UT_StringHolder.h>
35 #include <SYS/SYS_Types.h>
36 
37 
38 class GA_AIFCopyData;
39 class GA_AIFMerge;
40 class GA_Defragment;
41 class GA_LoadMap;
42 class GA_MergeMap;
43 class GA_SaveMap;
44 class UT_JSONParser;
45 class UT_JSONWriter;
46 
48 {
49 public:
50  static void registerType();
51  static GA_ATITopology *create(
52  const GA_IndexMap &index_map,
53  GA_AttributeScope scope,
54  const UT_StringHolder &name,
55  GA_AttributeOwner linkowner);
57  static const GA_AttributeType &getType() { return *theAttributeType; }
59  static const UT_StringHolder &getTypeName()
60  { return theAttributeType->getTypeName(); }
61 
63  static bool isType(const GA_Attribute *attrib)
64  {
65  return attrib && &attrib->getType() == theAttributeType;
66  }
68  static GA_ATITopology *cast(GA_Attribute *attrib)
69  {
70  if (attrib && &attrib->getType() == theAttributeType)
71  return static_cast<GA_ATITopology *>(attrib);
72  return NULL;
73  }
75  static const GA_ATITopology *cast(const GA_Attribute *attrib)
76  {
77  if (attrib && &attrib->getType() == theAttributeType)
78  return static_cast<const GA_ATITopology *>(attrib);
79  return NULL;
80  }
81 
83  const GA_AttributeType &type,
84  const GA_IndexMap &index_map,
85  GA_AttributeScope scope,
86  const UT_StringHolder &name,
87  GA_AttributeOwner linkowner);
88  virtual ~GA_ATITopology();
89 
90  /// Report memory used
91  int64 getMemoryUsage(bool inclusive) const;
92 
93  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
94 
95  /// We do not need to implement the reconstructElement() method as the
96  /// GA_Topology owner explicitly initializes each value as the element
97  /// is added.
98  /// TODO: Ideally we'd do so in reconstructElement() to avoid useless
99  /// work when elements are first constructed.
100 
101  /// Data is paged, so concurrent writes to separate pages supported.
103  { return WRITE_CONCURRENCE_PAGE; }
104 
105  /// Merge interface
106  virtual const GA_AIFMerge *getAIFMerge() const { return theAIFMerge; }
107 
108  bool mergeAppendData(const GA_MergeMap &map,
109  const GA_ATITopology &sattrib);
110 
111  virtual const GA_AIFCopyData *getAIFCopyData() const { return theAIFCopyData; }
112 
113  /// @{
114  /// Vertex references are managed via multiple coupled attributes, so
115  /// AIF_Merge cannot resolve non-trivial vertex merges. Instead, the
116  /// AIF will set this flag and let GA_Topology::mergeRebuild() handle
117  /// updating the vertex reference attributes.
118  bool getUnresolvedMergeFlag() const { return myUnresolvedMerge; }
119  void setUnresolvedMergeFlag(bool f) { myUnresolvedMerge = f; }
120  /// @}
121 
124  {
125  UT_ASSERT_P(getIndexMap().isOffsetInRange(ai));
126 
127 #if USE_PAGEARRAY_TOPOLOGY
128  return GA_Offset(myData.getGuaranteedInt(ai));
129 #else
130  if (myDataPageTableI16)
131  return GA_Offset(myDataPageTableI16->get(ai));
132  if (myDataPageTableI32)
133  return GA_Offset(myDataPageTableI32->get(ai));
134  return GA_Offset(myDataPageTableI64->get(ai));
135 #endif
136  }
137 
140  {
141  UT_ASSERT_P(getIndexMap().isOffsetInRange(ai));
142 
143 #if USE_PAGEARRAY_TOPOLOGY
144  UT_ASSERT_P(ai < myData.size());
145  myData.set(ai, int64(v));
146  UT_ASSERT_P(myData.getGuaranteedInt(ai) == int64(v));
147 #else
148  UT_ASSERT_P(ai < myData->getArraySize());
149  if (myDataPageTableI16)
150  {
151  myDataPageTableI16->set(ai, v);
152  }
153  else if (myDataPageTableI32)
154  {
155  myDataPageTableI32->set(ai, v);
156  }
157  else
158  {
159  myDataPageTableI64->set(ai, v);
160  }
161 #endif
162  }
163 
165  bool isPageConstant(GA_PageNum pageno) const
166  {
167  return myData.isPageConstant(pageno);
168  }
169 
170  /// Sets all links for offsets >= start and < end to value.
171  void setLinksConstant(GA_Offset start, GA_Offset end, GA_Offset value);
172 
173  /// Set all values to the default
174  void clear();
175 
177  {
178 #if USE_PAGEARRAY_TOPOLOGY
179  return myData.getStorage();
180 #else
181  return myData->getStorage();
182 #endif
183  }
184  bool setStorage(GA_Storage storage);
185 
186  /// Returns true iff that is an attribute whose content can be copied
187  /// from this without any type conversions. This is important to
188  /// avoid reallocation of an attribute if its storage type,
189  /// including tuple size, matches the source attribute exactly.
190  virtual bool matchesStorage(const GA_Attribute *that) const
191  {
192  if (!GA_Attribute::matchesStorage(that))
193  return false;
194  const GA_ATITopology *thatn = UTverify_cast<const GA_ATITopology *>(that);
195  if (getStorage() != thatn->getStorage())
196  return false;
197  return true;
198  }
199 
200  /// This replaces the entirety of this attribute's content and non-
201  /// storage metadata (except the name) with that of the src attribute.
202  /// matchesStorage(src) should already return true.
203  /// This is primarily for use by GA_AttributeSet::replace().
204  /// NOTE: The internal content sizes may not match exactly if the
205  /// attribute type may overallocate, but the sizes should be such
206  /// that any real data will fit in the destination, so be careful
207  /// and deal with the myTailInitialize flag appropriately if
208  /// any extra elements aren't equal to the default.
209  virtual void replace(const GA_Attribute &src);
210 
211  /// Query the owner type of the link stored in this attribute. For
212  /// example, the vertex PointRef attribute would have:
213  /// getOwner() == GA_ATTRIB_VERTEX
214  /// getLinkOwner() == GA_ATTRIB_POINT
215  GA_AttributeOwner getLinkOwner() const { return myLinkOwner; }
216 
217  /// Save to a JSON stream.
218  /// @section JSON-GA_ATITopology JSON Schema: GA_ATITopology
219  /// @code
220  /// {
221  /// "name" : "GA_ATITopology",
222  /// "description" : "An tuple array of indexed strings",
223  /// "type" : "orderedmap",
224  /// "properties": {
225  /// "data": {
226  /// "type" : "indices",
227  /// "items" : "integer",
228  /// "description" : "Integer reference indices.",
229  /// },
230  /// },
231  /// }
232  /// @endcode
233  /// @see @ref JSON_FileFormat
234  /// @note There is no GA_AIFJSON interface for topology.
235  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &map) const;
236 
237  /// Load from a JSON stream.
238  /// @note There is no GA_AIFJSON interface for topology.
239  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &map);
240 
241 #if USE_PAGEARRAY_TOPOLOGY
243 
244  /// @{
245  /// Provide access to data
246  const DataType &getData() const { return myData; }
247  DataType &getData() { return myData; }
248  /// @}
249 #else
250  /// @{
251  /// Provide access to data
252  const GA_DataArray &getData() const { return *myData; }
253  GA_DataArray &getData() { return *myData; }
254  /// @}
255 #endif
256 
257  /// Grow or shrink the array size
258  virtual bool setArraySize(GA_Offset new_size);
259 
260  /// Try to compress data pages
261  virtual void tryCompressAllPages(
262  GA_Offset start_offset = GA_Offset(0),
263  GA_Offset end_offset = GA_INVALID_OFFSET);
264  /// Harden data pages
265  virtual void hardenAllPages(
266  GA_Offset start_offset = GA_Offset(0),
267  GA_Offset end_offset = GA_INVALID_OFFSET);
268 
269 private:
270  // Defragmentation functions should only be called internally or from GA_Topology.
271  friend class GA_Topology;
272 
273  /// @{
274  /// Interface for defragmentation
275  /// This implementation does nothing, because defragmentation
276  /// of topology attributes must be handled separately.
277  virtual void defragment(const GA_Defragment &defrag);
278  /// @}
279 
280  /// Swap the elements in the array
281  void swapElements(GA_Offset a, GA_Offset b, GA_Size n);
282  /// Move elements in the array from a to b
283  void moveElements(GA_Offset a, GA_Offset b, GA_Size n);
284 
285  /// Change the values in the array
286  /// This bumps the attribute's data ID iff myData != NULL
287  /// and getLinkOwner() != getOwner().
288  void swapLinks(const GA_Defragment &defrag);
289 
290  /// Set the link data type
291  void setLinkOwner(GA_AttributeOwner t) { myLinkOwner = t; }
292 
293 #if USE_PAGEARRAY_TOPOLOGY
294  DataType myData;
295 #else
296  /// Rebuild our direct page pointers.
297  /// Must be invoked if the page type changes.
298  void updatePagePointers();
299 
300  GA_DataArray *myData;
301 #endif
302  GA_AttributeOwner myLinkOwner;
303  bool myUnresolvedMerge;
304 
305 #if !USE_PAGEARRAY_TOPOLOGY
307  *myDataPageTableI16;
309  *myDataPageTableI32;
311  *myDataPageTableI64;
312 #endif
313 
314  static const GA_AIFMerge *theAIFMerge;
315  static const GA_AIFCopyData *theAIFCopyData;
316  static const GA_AttributeType *theAttributeType;
317 
318  friend class ga_TopologyCopy;
319 };
320 
321 #endif
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
virtual bool matchesStorage(const GA_Attribute *that) const
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
GA_Storage getStorage() const
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
SYS_FORCE_INLINE GA_Offset getLink(GA_Offset ai) const
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
SYS_FORCE_INLINE bool isPageConstant(GA_PageNum pageno) const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
virtual bool setArraySize(GA_Offset size)=0
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
virtual int64 getMemoryUsage(bool inclusive) const =0
virtual bool matchesStorage(const GA_Attribute *that) const
Definition: GA_Attribute.h:680
static SYS_FORCE_INLINE const GA_ATITopology * cast(const GA_Attribute *attrib)
GA_PageArray< void, 1, true, false > DataType
virtual void tryCompressAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)=0
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
GA_AttributeOwner getLinkOwner() const
GA_Size GA_Offset
Definition: GA_Types.h:617
DataType & getData()
long long int64
Definition: SYS_Types.h:100
GA_AttributeScope
Definition: GA_Types.h:121
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
void setUnresolvedMergeFlag(bool f)
virtual void replace(const GA_Attribute &src)=0
Attribute Interface for merging attribute data between details.
Definition: GA_AIFMerge.h:56
virtual const GA_AIFMerge * getAIFMerge() const
Merge interface.
GLuint GLuint end
Definition: glcorearb.h:474
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
static SYS_FORCE_INLINE GA_ATITopology * cast(GA_Attribute *attrib)
virtual const GA_AIFCopyData * getAIFCopyData() const
Return the attribute's copy interface or NULL.
An array of numbers with various storage types.
Definition: GA_DataArray.h:49
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
bool getUnresolvedMergeFlag() const
GLuint const GLchar * name
Definition: glcorearb.h:785
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:175
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:197
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GA_AttributeOwner
Definition: GA_Types.h:33
virtual WriteConcurrence getSupportedWriteConcurrence() const
Data is paged, so concurrent writes to separate pages supported.
const GA_IndexMap & getIndexMap() const
Definition: GA_Attribute.h:198
GA_Size GA_PageNum
Definition: GA_Types.h:620
Concurrent writes to separate pages supported.
Definition: GA_Attribute.h:338
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Attribute Interface class to copy attribute data.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const DataType & getData() const
virtual void hardenAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)=0
virtual void defragment(const GA_Defragment &defrag)=0
GA_Storage
Definition: GA_Types.h:48
static SYS_FORCE_INLINE const GA_AttributeType & getType()
GLenum src
Definition: glcorearb.h:1792
SYS_FORCE_INLINE void setLink(GA_Offset ai, GA_Offset v)