HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_ElementGroupTable.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_ElementGroupTable.h (GA Library, C++)
7  *
8  * COMMENTS: A table for managing GA_ElementGroup objects.
9  *
10  */
11 
12 #pragma once
13 
14 #ifndef __GA_ElementGroupTable_h__
15 #define __GA_ElementGroupTable_h__
16 
17 #include "GA_API.h"
18 #include "GA_ElementGroup.h"
19 #include "GA_GroupTable.h"
20 #include "GA_Types.h"
21 
22 #include <UT/UT_OrderedIterator.h>
23 
24 #include <iosfwd>
25 
26 
27 class GA_Detail;
28 class GA_ElementGroup;
29 class GA_MergeMap;
30 class GA_LoadMap;
31 class GA_Group;
32 class GA_PointGroup;
33 class GA_PrimitiveGroup;
34 class GA_Range;
36 class GA_VertexGroup;
37 
38 class UT_IStream;
39 class UT_JSONParser;
40 template <typename T> class UT_Array;
41 
42 
44 {
45 protected:
47  GA_AttributeOwner owner);
48 public:
49  ~GA_ElementGroupTable() override;
50 
51  void getList(UT_Array<const GA_ElementGroup *> &list) const;
52  void getList(UT_Array<GA_ElementGroup *> &list) const;
53 
55 
56  /// @{
57  /// Traverse the group table in creation order.
58  ///
59  /// @warning It is NOT safe to add or remove groups during traversal.
61  { return begin<GA_ElementGroup>(); }
63  { return end<GA_ElementGroup>(); }
64  /// @}
65 
66  /// @{
67  /// Traverse the group table in alpabetic order.
70  static int compareAlpha(GA_ElementGroup *const*a, GA_ElementGroup *const*b)
71  { return GA_GroupTable::compareGroupName(**a, **b); }
73  { return ordered_iterator(beginTraverse(), compareAlpha); }
75  { return ordered_iterator(); }
76  /// @}
77 
78  bool loadGroupsH9(UT_IStream &is,
79  GA_AttributeOwner owner, int count);
80  bool saveGroupsH9(std::ostream &os, int binary) const;
81 
82  /// @{
83  /// Apply an operation to all element groups
84  void addElementToAllGroups(GA_Offset dest) const;
85  void toggleElementInAllGroups(GA_Offset dest) const;
86  void removeElementFromAllGroups(GA_Offset dest) const;
87  /// @}
88 
89  /// Add @c dest to the same groups that @c src belongs to.
90  void unionElementForAllGroups(GA_Offset dest,
91  GA_Offset src) const;
92  /// Remove @c dest from the groups that @c src does not belong to.
93  void intersectElementForAllGroups(GA_Offset dest,
94  GA_Offset src) const;
95 
96  /// @{
97  /// @private
98  /// Remove elements from each group's ordered list, if any, in preparation
99  /// for deleting those elements. This must occur in advance of the actual
100  /// deletion and consequent removal from the group as a GA_RangeMemberQuery
101  /// object may be using an element group internally. The GA_Range version
102  /// may allocate a GA_RangeMemberQuery object if not provided one, in which
103  /// case the caller is responsible for deleting it.
104  ///
105  /// @note This will temporarily leave ordered groups in an invalid state
106  /// until the element removal is processed.
107  void removeElementFromGroupOrders(GA_Offset element) const;
108  void removeElementsFromGroupOrders(const GA_Range &range) const;
109  void removeElementsFromGroupOrders(
110  const GA_Range &range,
111  const GA_RangeMemberQuery *&range_query) const;
112  /// @}
113 
114  /// @{
115  /// @private
116  /// Remove secondary elements from mixed groups, if any, in preparation
117  /// for deleting those elements. The GA_Range version may allocate a
118  /// GA_RangeMemberQuery object if not provided one, in which case the
119  /// caller is responsible for deleting it. The final offset in the
120  /// GA_SecondaryLookupInfo argument in the GA_Range versions is a place
121  /// holder for the offsets in the provided GA_Range and is ignored.
122  void removeMixElementFromGroups(GA_Offset element,
123  const GA_SecondaryLookupInfo *sec) const;
124  void removeMixElementsFromGroups(
125  GA_Offset element,
126  const GA_SecondaryLookupInfo *sec_prefix,
127  const GA_Range &sec_range) const;
128  void removeMixElementsFromGroups(
129  GA_Offset element,
130  const GA_SecondaryLookupInfo *sec_prefix,
131  const GA_Range &sec_range,
132  const GA_RangeMemberQuery *&sec_range_query) const;
133  /// @}
134 
135  GA_Size destroyEmptyGroups();
136 
137  /// If you have changed group membership in a multithreaded algorithm,
138  /// call this method to invalidate cached group entries for all groups
139  /// in this table.
140  void invalidateGroupEntries();
141 
144  {
146  }
147 
148 protected:
149  void baseMergeTable(const GA_ElementGroupTable &src,
150  GA_MergeMap &map,
151  GA_AttributeOwner owner);
152 
153  GA_Group *jsonCreateGroup(UT_JSONParser &p, const char *type,
154  const char *name,
155  bool internal,
156  GA_AttributeOwner owner) override;
157 
158  virtual GA_AttributeOwner getOwner() const = 0;
159 
160 private:
161  bool loadGroup(UT_JSONParser &p, const GA_LoadMap &map,
162  const char *name, const char *type, bool ordered);
163 
164 protected:
165  /// A template class, the specializations of which wrap a typedef to the
166  /// the corresponding subclass of GA_ElementGroup. Effectively mapping
167  /// GA_AttributeOwner to a GA_ElementGroup subclass. The template class
168  /// is protected so that external specializations cannot be added.
169  ///
170  /// The DUMMY parameter is necessary because explicit specialization is
171  /// allowed at this scope, while, strangely, the same does not hold for
172  /// partial specialization.
173  template <GA_AttributeOwner OWNER, bool DUMMY>
174  class ElementType {};
175 
176  template <bool DUMMY> // GA_ATTRIB_POINT -> GA_PointGroup
178  {
179  public:
181  };
182 
183  template <bool DUMMY> // GA_ATTRIB_PRIMITIVE -> GA_PrimitiveGroup
185  {
186  public:
188  };
189 
190  template <bool DUMMY> // GA_ATTRIB_VERTEX -> GA_VertexGroup
192  {
193  public:
195  };
196 };
197 
198 
199 /// OWNER must be one of GA_ATTRIB_POINT, GA_ATTRIB_PRIMITIVE, GA_ATTRIB_VERTEX
200 template <GA_AttributeOwner OWNER>
202 {
203 public:
206 
208  : GA_ElementGroupTable(detail, OWNER) {}
209 
211 
213  { getListT<const GROUP_TYPE>(list); }
214  void getList(UT_Array<GROUP_TYPE *> &list) const
215  { getListT<GROUP_TYPE>(list); }
216 
217  /// A table merge matches our groups with source, adding any missing, and
218  /// updating map. This method acts as GA_AIFMerge::destroyDestination()
219  /// and GA_AIFMerge::addDestination() for element groups. The merging of
220  /// individual element groups is handled by the attributes (GA_AIFMerge).
222  GA_MergeMap &map)
223  { baseMergeTable(src, map, OWNER); }
224 
226  { return begin<GROUP_TYPE>(); }
228  { return end<GROUP_TYPE>(); }
229 
230  static int compareAlpha(GROUP_TYPE *const*a, GROUP_TYPE *const*b)
231  { return GA_GroupTable::compareGroupName(**a, **b); }
232 
233  typedef UT_OrderedIterator<GROUP_TYPE *,
238  { return ordered_iterator(); }
239 
240  static const GROUP_TYPE *castGroup(const GA_ElementGroup *group)
241  { return (const GROUP_TYPE *)group; }
243  { return (GROUP_TYPE *)group; }
244 protected:
245  GA_AttributeOwner getOwner() const override { return OWNER; }
246 
248  GA_Detail &detail,
249  const UT_StringHolder &name,
250  bool internal) const override
251  {
252  return new GROUP_TYPE(detail, name, internal, false);
253  }
254 
256  const GA_Detail &detail) const override
257  {
258  return new GROUP_TYPE(detail);
259  }
260 };
261 
265 
266 #endif
ordered_iterator oend() const
void getList(UT_Array< const GROUP_TYPE * > &list) const
GA_GroupTable::iterator< GA_Group > beginTraverse() const
GLenum GLint * range
Definition: glcorearb.h:1925
GA_ElementGroupTableT< GA_ATTRIB_PRIMITIVE > GA_PrimitiveGroupTable
GA_GroupTable::iterator< GROUP_TYPE > endTraverse() const
static GROUP_TYPE * castGroup(GA_ElementGroup *group)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
void baseMergeTable(const GA_ElementGroupTable &src, GA_MergeMap &map, GA_AttributeOwner owner)
#define GA_API
Definition: GA_API.h:14
Abstract base class for a range membership query object.
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
GA_ElementGroupTableT< GA_ATTRIB_VERTEX > GA_VertexGroupTable
Information necessary to lookup a secondary primitive.
ordered_iterator oend() const
GA_AttributeOwner getOwner() const override
virtual GA_Group * jsonCreateGroup(UT_JSONParser &p, const char *type, const char *name, bool internal, GA_AttributeOwner owner)=0
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
static int compareAlpha(GA_ElementGroup *const *a, GA_ElementGroup *const *b)
GA_GroupTable::iterator< GA_ElementGroup > iterator
A range of elements in an index-map.
Definition: GA_Range.h:42
SYS_FORCE_INLINE GA_ElementGroup * find(const UT_StringRef &name) const
GA_Size GA_Offset
Definition: GA_Types.h:646
ordered_iterator obegin() const
ElementType< OWNER, true >::Class GROUP_TYPE
GLuint GLuint end
Definition: glcorearb.h:475
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Options during loading.
Definition: GA_LoadMap.h:42
GA_GroupTable::iterator< GA_ElementGroup > beginTraverse() const
GA_Group * virtualCreateDetachedGroup(const GA_Detail &detail) const override
GLuint const GLchar * name
Definition: glcorearb.h:786
OWNER must be one of GA_ATTRIB_POINT, GA_ATTRIB_PRIMITIVE, GA_ATTRIB_VERTEX.
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_Group * find(const UT_StringRef &name) const
void mergeTable(const GA_ElementGroupTableT< OWNER > &src, GA_MergeMap &map)
ordered_iterator obegin() const
GA_ElementGroupTableT(GA_Detail &detail)
GA_GroupTable::iterator< GA_ElementGroup > endTraverse() const
static const GROUP_TYPE * castGroup(const GA_ElementGroup *group)
GA_AttributeOwner
Definition: GA_Types.h:35
static int compareGroupName(const GA_Group &a, const GA_Group &b)
UT_OrderedIterator< GROUP_TYPE *, GA_GroupTable::iterator< GROUP_TYPE > > ordered_iterator
static int compareAlpha(GROUP_TYPE *const *a, GROUP_TYPE *const *b)
GA_GroupTable::iterator< GROUP_TYPE > beginTraverse() const
GA_GroupTable::iterator< GROUP_TYPE > iterator
UT_OrderedIterator< GA_ElementGroup *, GA_GroupTable::iterator< GA_ElementGroup > > ordered_iterator
Container class for all geometry.
Definition: GA_Detail.h:96
GA_ElementGroupTableT< GA_ATTRIB_POINT > GA_PointGroupTable
type
Definition: core.h:1059
UT_OrderedIterator< GA_Group *, GA_GroupTable::iterator< GA_Group > > ordered_iterator
void getList(UT_Array< GROUP_TYPE * > &list) const
GA_Group * virtualCreateGroup(GA_Detail &detail, const UT_StringHolder &name, bool internal) const override
GLint GLsizei count
Definition: glcorearb.h:405
GLenum src
Definition: glcorearb.h:1793