HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_GBMacros.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_GBMacros.h ( GA Library, C++)
7  *
8  * COMMENTS: Macros which emulate the old GB macros
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_GBMacros__
14 #define __GA_GBMacros__
15 
16 /// @file GA_GBMacros.h
17 /// @brief Create macros which emulate the macros in the obsolete GB library
18 
19 /// TODO: The GA_ prefix is necessary while GA needs to coexist with GB. Once
20 /// GB has been entirely replaced, we'll remove the GA_ prefix for source
21 /// compatibility.
22 
23 
24 #include "GA_AttributeDict.h"
25 #include "GA_BreakpointGroup.h"
26 #include "GA_Detail.h"
27 #include "GA_GroupTable.h"
28 #include "GA_ElementGroupTable.h"
29 #include "GA_Iterator.h"
30 #include "GA_GBIterators.h"
31 #include "GA_EdgeGroup.h"
32 #include "GA_Types.h"
33 
34 /// @def GA_FOR_ALL_PRIMITIVES(gdp, prim)
35 /// Iterates over primitives, assigning prim to the current primitive
36 #define GA_FOR_ALL_PRIMITIVES(gdp, prim) \
37  for (GA_Iterator it((gdp)->getPrimitiveRange()); (!it.atEnd() || (prim = nullptr)) && \
38  ((prim) = GA_Detail::GB_MACRO_CAST((gdp), (gdp)->getPrimitive(*it))); ++it)
39 
40 /// @def GA_FOR_SAFE_PRIMITIVES(gdp, prim, next)
41 /// Iterates over primitives, but primitives may be deleted during the
42 /// iteration.
43 #define GA_FOR_SAFE_PRIMITIVES(gdp, prim, next) \
44  for (GA_GBPrimitiveIterator it(*(gdp), GA_Range::safedeletions()); \
45  (prim=GA_Detail::GB_MACRO_CAST(gdp, it.getPrimitive())) && \
46  ((next=GA_Detail::GB_MACRO_CAST(gdp, it.getNextPrimitive())) \
47  || true); \
48  ++it)
49 
50 /// @def GA_FOR_MASK_PRIMITIVES(gdp, prim, mask)
51 /// Iterates over primitives, filtering only primitives which match the type
52 /// mask specified. mask can be either GA_PrimCompat::TypeMask or a family
53 /// mask.
54 /// @see GA_Primitive::getTypeId(), GA_Primitive::getFamilyMask(),
55 /// GA_Primitive::getPrimitiveId()
56 #define GA_FOR_MASK_PRIMITIVES(gdp, prim, mask) \
57  for (GA_GBPrimitiveIterator it(*(gdp), mask); \
58  (prim=GA_Detail::GB_MACRO_CAST(gdp, it.getPrimitive())); \
59  ++it)
60 
61 /// @def GA_FOR_ALL_GROUP_PRIMITIVES(gdp, grp, prim)
62 /// Iterate over all primitives in group. @see GA_RTIElementGroup
63 #define GA_FOR_ALL_GROUP_PRIMITIVES(gdp, grp, prim) \
64  for (GA_Iterator it((gdp)->getPrimitiveRange(grp)); (!it.atEnd() || (prim = nullptr)) && \
65  ((prim)=GA_Detail::GB_MACRO_CAST((gdp), (gdp)->getPrimitive(*it))); \
66  ++it)
67 
68 /// @def GA_FOR_SAFE_GROUP_PRIMITIVES(gdp, grp, prim, next)
69 /// Iterates over primitives in group, but primitives may be deleted during the
70 /// iteration. @see GA_RTIElementGroup
71 #define GA_FOR_SAFE_GROUP_PRIMITIVES(gdp, grp, prim, next) \
72  for (GA_GBPrimitiveIterator it(*(gdp),grp,GA_Range::safedeletions()); \
73  (prim=GA_Detail::GB_MACRO_CAST(gdp, it.getPrimitive())) && \
74  ((next=GA_Detail::GB_MACRO_CAST(gdp, it.getNextPrimitive())) \
75  || true); \
76  ++it)
77 
78 /// @def GA_FOR_ALL_OPT_GROUP_PRIMITIVES(gdp, grp, prim)
79 /// Iterate over all primitives in group, but the group can be NULL.
80 /// @see GA_RTIElementGroup
81 #define GA_FOR_ALL_OPT_GROUP_PRIMITIVES(gdp,grp,prim) \
82  GA_FOR_ALL_GROUP_PRIMITIVES(gdp,grp,prim)
83 
84 
85 /// @def GA_FOR_ALL_PTOFF(gdp, ptoff)
86 /// Iterate over all points via offsets.
87 /// WARNING: Because this uses nested loops, "break;" won't work!
88 #define GA_FOR_ALL_PTOFF(gdp, ptoff) \
89  GA_Offset lcl_start, lcl_end; \
90  for (GA_Iterator lcl_it((gdp)->getPointRange()); lcl_it.blockAdvance(lcl_start, lcl_end); ) \
91  for (ptoff = lcl_start; ptoff < lcl_end; ++ptoff)
92 
93 /// @def GA_FOR_ALL_GROUP_PTOFF(gdp, grp, ptoff)
94 /// Iterate over all points in a group via point offsets.
95 /// WARNING: Because this uses nested loops, "break;" won't work!
96 #define GA_FOR_ALL_GROUP_PTOFF(gdp, grp, ptoff) \
97  GA_Offset lcl_start, lcl_end; \
98  for (GA_Iterator lcl_it((gdp)->getPointRange(grp)); lcl_it.blockAdvance(lcl_start, lcl_end); ) \
99  for (ptoff = lcl_start; ptoff < lcl_end; ++ptoff)
100 
101 /// @def GA_FOR_PAIRS_OF_PRIMITIVES(gdp1, prim1, gdp2, prim2)
102 /// Iterate over primitives in both GA_Details in a pairwise fashion.
103 #define GA_FOR_PAIRS_OF_PRIMITIVES(gdp1, prim1, gdp2, prim2) \
104  for (GA_GBPrimitiveIterator it(*(gdp1), NULL, *(gdp2), NULL); \
105  (prim1=GA_Detail::GB_MACRO_CAST(gdp1, it.getPrimitive())) && \
106  (prim2=GA_Detail::GB_MACRO_CAST(gdp2, it.getPrimitive2())); \
107  ++it)
108 
109 /// @def GA_FOR_PAIRS_OF_GROUP_PRIMITIVES(gdp1, group1, prim1, gdp2, group2, prim2)
110 /// Iterate over points in the specified groups across both GA_Details in a
111 /// pairwise fashion.
112 #define GA_FOR_PAIRS_OF_GROUP_PRIMITIVES(gdp1, grp1, prim1, gdp2, grp2, prim2) \
113  for (GA_GBPrimitiveIterator it(*(gdp1), grp1, *(gdp2), grp2); \
114  (prim1=GA_Detail::GB_MACRO_CAST(gdp1, it.getPrimitive())) && \
115  (prim2=GA_Detail::GB_MACRO_CAST(gdp2, it.getPrimitive2())); \
116  ++it)
117 
118 /// @def GA_FOR_ALL_GROUP_EDGES(group, edge)
119 /// Iterate over edges in the specified group.
120 #define GA_FOR_ALL_GROUP_EDGES(group, edge) \
121  for (auto it=(group)->begin(); \
122  !it.atEnd() && (edge = &it.getEdge()); \
123  ++it)
124 
125 /// @def GA_FOR_ALL_GROUP_EDGES_INCL_PRIMS(group, edge, primoff)
126 /// Iterate over edges in the specified group.
127 #define GA_FOR_ALL_GROUP_EDGES_INCL_PRIMS(group, edge, primoff) \
128  for (auto it=(group)->begin(); \
129  !it.atEnd() && (edge = &it.getEdge()) && \
130  (GAisValid(primoff = it.getPrimitive()) || true); \
131  ++it)
132 
133 /// @def GA_FOR_SAFE_GROUP_EDGES(group, edge)
134 /// Iterate over edges in the specified group. Edges may be deleted during
135 /// traversal.
136 #define GA_FOR_SAFE_GROUP_EDGES(group, edge) \
137  GA_FOR_ALL_GROUP_EDGES(group, edge)
138 
139 /// @def GA_FOR_SAFE_GROUP_EDGES_INCL_PRIMS(group, edge)
140 /// Iterate over edges in the specified group. Edges may be deleted during
141 /// traversal.
142 #define GA_FOR_SAFE_GROUP_EDGES_INCL_PRIMS(group, edge, prim) \
143  GA_FOR_ALL_GROUP_EDGES_INCL_PRIMS(group, edge, prim)
144 
145 /// @def GA_FOR_ALL_GROUP_BREAKPOINTS(group, bkp)
146 /// Iterate over breakpoints in the specified group.
147 #define GA_FOR_ALL_GROUP_BREAKPOINTS(group, bkp) \
148  for (GA_BreakpointGroup::iterator it=(group)->begin(); \
149  !it.atEnd() && (bkp = &it.getBreakpoint()); \
150  it.advance())
151 
152 /// @def GA_FOR_ALL_POINTGROUPS(gdp, group)
153 /// Iterate over all point GA_ElementGroups in an arbitrary order
154 /// @warning It is NOT safe to add or remove point groups during this loop.
155 #define GA_FOR_ALL_POINTGROUPS(gdp, grp) \
156  for (GA_GroupTable::iterator<GA_PointGroup> \
157  __iter = (gdp)->pointGroups().beginTraverse(); \
158  !__iter.atEnd() && \
159  ((grp) = __iter.group()); \
160  ++__iter)
161 
162 /// @def GA_FOR_ALL_POINTGROUPS_SORTED(gdp, group)
163 /// Iterate over all point GA_ElementGroups in alphabetical order
164 /// @warning It is NOT safe to add or remove point groups during this loop.
165 #define GA_FOR_ALL_POINTGROUPS_SORTED(gdp, grp) \
166  for (GA_PointGroupTable::ordered_iterator \
167  __iter = (gdp)->pointGroups().obegin(); \
168  !__iter.atEnd() && \
169  ((grp) = *__iter); \
170  ++__iter)
171 
172 /// @def GA_FOR_ALL_PRIMGROUPS(gdp, group)
173 /// Iterate over all primitive GA_ElementGroups in an arbitrary order
174 /// @warning It is NOT safe to add or remove point groups during this loop.
175 #define GA_FOR_ALL_PRIMGROUPS(gdp, grp) \
176  for (GA_GroupTable::iterator<GA_PrimitiveGroup> \
177  __iter = (gdp)->primitiveGroups().beginTraverse(); \
178  !__iter.atEnd() && \
179  ((grp) = __iter.group()); \
180  ++__iter)
181 
182 /// @def GA_FOR_ALL_PRIMGROUPS_SORTED(gdp, group)
183 /// Iterate over all primitive GA_ElementGroups in alphabetical order
184 /// @warning It is NOT safe to add or remove point groups during this loop.
185 #define GA_FOR_ALL_PRIMGROUPS_SORTED(gdp, grp) \
186  for (GA_PrimitiveGroupTable::ordered_iterator \
187  __iter = (gdp)->primitiveGroups().obegin(); \
188  !__iter.atEnd() && \
189  ((grp) = *__iter); \
190  ++__iter)
191 
192 /// @def GA_FOR_ALL_VERTEXGROUPS(gdp, group)
193 /// Iterate over all vertex GA_ElementGroups in an arbitrary order
194 /// @warning It is NOT safe to add or remove point groups during this loop.
195 #define GA_FOR_ALL_VERTEXGROUPS(gdp, grp) \
196  for (GA_GroupTable::iterator<GA_VertexGroup> \
197  __iter = (gdp)->vertexGroups().beginTraverse(); \
198  !__iter.atEnd() && \
199  ((grp) = __iter.group()); \
200  ++__iter)
201 
202 /// @def GA_FOR_ALL_VERTEXGROUPS_SORTED(gdp, group)
203 /// Iterate over all vertex GA_ElementGroups in alphabetical order
204 /// @warning It is NOT safe to add or remove point groups during this loop.
205 #define GA_FOR_ALL_VERTEXGROUPS_SORTED(gdp, grp) \
206  for (GA_VertexGroupTable::ordered_iterator \
207  __iter = (gdp)->vertexGroups().obegin(); \
208  !__iter.atEnd() && \
209  ((grp) = *__iter); \
210  ++__iter)
211 
212 /// @def GA_FOR_ALL_EDGEGROUPS(gdp, group)
213 /// Iterate over all GA_EdgeGroups in an arbitrary order
214 /// @warning It is NOT safe to add or remove edge groups during this loop.
215 #define GA_FOR_ALL_EDGEGROUPS(gdp, grp) \
216  for (GA_GroupTable::iterator<GA_EdgeGroup> \
217  __iter = (gdp)->edgeGroups().beginTraverse(); \
218  !__iter.atEnd() && \
219  ((grp) = __iter.group()); \
220  ++__iter)
221 
222 /// @def GA_FOR_ALL_EDGEGROUPS_SORTED(gdp, group)
223 /// Iterate over all GA_EdgeGroups in alphabetical order
224 /// @warning It is NOT safe to add or remove edge groups during this loop.
225 #define GA_FOR_ALL_EDGEGROUPS_SORTED(gdp, grp) \
226  for (GA_EdgeGroupTable::ordered_iterator \
227  __iter = (gdp)->edgeGroups().obegin(); \
228  !__iter.atEnd() && \
229  ((grp) = *__iter); \
230  ++__iter)
231 
232 /// @def GA_FOR_ALL_ATTRIBUTES(dict, attribute)
233 /// Iterate over all attributes in a GA_AttributeDict
234 #define GA_FOR_ALL_ATTRIBUTES(dict, A) \
235  for (GA_AttributeDict::iterator it=dict.begin(); \
236  !it.atEnd() && (A = it.attrib()); ++it)
237 
238 /// @def GA_FOR_ALL_DETAIL_ATTRIBUTES(gdp, attribute)
239 /// Iterate over all global/detail attributes in the geometry
240 #define GA_FOR_ALL_DETAIL_ATTRIBUTES(gdp, A) \
241  GA_FOR_ALL_ATTRIBUTES((gdp)->getAttributeDict(GA_ATTRIB_GLOBAL), A)
242 
243 /// @def GA_FOR_ALL_PRIMITIVE_ATTRIBUTES(gdp, attribute)
244 /// Iterate over all primitive attributes in the geometry
245 #define GA_FOR_ALL_PRIMITIVE_ATTRIBUTES(gdp, A) \
246  GA_FOR_ALL_ATTRIBUTES((gdp)->getAttributeDict(GA_ATTRIB_PRIMITIVE), A)
247 
248 /// @def GA_FOR_ALL_POINT_ATTRIBUTES(gdp, attribute)
249 /// Iterate over all point attributes in the geometry
250 #define GA_FOR_ALL_POINT_ATTRIBUTES(gdp, A) \
251  GA_FOR_ALL_ATTRIBUTES((gdp)->getAttributeDict(GA_ATTRIB_POINT), A)
252 
253 /// @def GA_FOR_ALL_VERTEX_ATTRIBUTES(gdp, attribute)
254 /// Iterate over all vertex attributes in the geometry
255 #define GA_FOR_ALL_VERTEX_ATTRIBUTES(gdp, A) \
256  GA_FOR_ALL_ATTRIBUTES((gdp)->getAttributeDict(GA_ATTRIB_VERTEX), A)
257 
258 #define GA_FOR_ALL_GROUPS(grptable, grp) \
259  for (GA_GroupTable::iterator<GA_ElementGroup> lcl_it = (grptable).beginTraverse(); !lcl_it.atEnd() && ((grp) = lcl_it.group()); ++lcl_it)
260 
261 #define GA_FOR_ALL_GROUPS_SORTED(grptable, grp) \
262  for (GA_ElementGroupTable::ordered_iterator lcl_it = (grptable).obegin(); !lcl_it.atEnd() && ((grp) = *lcl_it); ++lcl_it)
263 
264 #endif
Contains iterators to help backward compatibility with GB library. The constructors will initialize t...