HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_PrimitiveFactory.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_PrimitiveFactory.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  * A GA_PrimitiveFactory manages a collection of GA_PrimitiveDefinition
10  * objects and an associated set of intrinsic attributes.
11  */
12 
13 #pragma once
14 
15 #ifndef __GA_PrimitiveFactory__
16 #define __GA_PrimitiveFactory__
17 
18 #include "GA_API.h"
19 #include "GA_IOTable.h"
20 #include "GA_IntrinsicManager.h"
21 #include "GA_PrimitiveDefinition.h"
22 #include "GA_PrimitiveFamilyMask.h"
23 #include "GA_PrimitiveTypeMask.h"
24 #include "GA_PrimitiveTypeId.h"
25 #include "GA_PrimitiveTypes.h"
26 #include "GA_Types.h"
27 
28 #include <UT/UT_Array.h>
29 #include <UT/UT_ArrayStringMap.h>
30 #include <UT/UT_FSATable.h>
31 #include <UT/UT_Functor.h>
32 #include <UT/UT_Lock.h>
33 
34 #include <stddef.h>
35 
36 class GA_Detail;
37 class GA_IO;
38 class GA_Primitive;
39 
40 class UT_StringArray;
41 class UT_ArrayStringSet;
42 
44 {
45 public:
46  // Define a map where the key is the primitive name and the value is the
47  // DSO file defining the primitive. Primitives not defined by DSOs are not
48  // stored in this map.
50 
52  const UT_FSATable *factory_ids,
53  unsigned non_factory_id_start, int nentries_hint = 0,
54  bool isforprimarydetail = true);
56 
57  /// Register a new primitive definition.
58  /// In the event of a name collision with an existing definition, we return
59  /// NULL.
60  GA_PrimitiveDefinition *registerDefinition(
61  const UT_StringHolder &name,
65  const UT_StringHolder &icon=UT_StringHolder());
66 
67  /// Return the number of possible primitive types in this factory.
68  /// Primitive type id's may not always be contiguous (i.e. there may be
69  /// invalid primitive id's in the range).
70  int getPrimTypeCount() const { return myNextId; }
71 
72  /// Lookup an existing primitive definition, by either token or primitive
73  /// identifier.
74  const GA_PrimitiveDefinition *lookupDefinition(
75  const UT_StringRef &name) const;
76  const GA_PrimitiveDefinition *lookupDefinition(
77  const GA_PrimitiveTypeId &id) const;
78  const GA_PrimitiveDefinition *lookupDefinition(int id) const;
79 
80  /// Given a factory type id, return the corresponding GA_PrimitiveTypeId
82  {
83  if (id >= 0 && id < myList.size() && myList(id))
84  return GA_PrimitiveTypeId(id);
85  return GA_PrimitiveTypeId();
86  }
87 
88  /// Return a list of all primitives defined by DSOs
89  static const ga_DSODefinitions &dsoDefinitions();
90 
91 
92  /// Get a primitive type mask representing all known types registered by
93  /// this primitive factory.
94  GA_PrimitiveTypeMask getTypeMaskAll() const;
95 
96  /// Query the first and last primitive type id in this factory
97  void getDefinitionIdRange(unsigned &first,
98  unsigned &last) const;
99 
100  /// @{
101  /// Fill out the list of intrinsic names for the given primitive type. The
102  /// intrinsic names are added to the set.
103  void addPrimitiveIntrinsicNames(const GA_PrimitiveTypeId &id,
104  UT_ArrayStringSet &names) const;
105  /// @}
106 
107  /// Get the names of all detail intrinsics. You can avoid creating a
108  /// detail to do this by calling GUgetFactory().getDetailIntrinsics(names);
110  {
111  myDetailIntrinsics.extractNames(names);
112  }
113 
114  /// Returns true if this factory is for use by GEO_Detail and false
115  /// if this type is for use by GD_Detail.
116  bool isForPrimaryDetail() const { return myForPrimaryDetail; }
117 
118  /// Class to traverse all primitive definitions in the factory
119  class iterator
120  {
121  public:
123  : myFactory(NULL)
124  , myCurr(0)
125  , myEnd(0)
126  {}
128  {
129  *this = src;
130  }
133  {
134  myFactory = src.myFactory;
135  myCurr = src.myCurr;
136  myEnd = src.myEnd;
137  return *this;
138  }
139  bool operator==(const iterator &src) const
140  {
141  if (atEnd() && src.atEnd())
142  return true;
143  return myFactory == src.myFactory &&
144  myCurr == src.myCurr &&
145  myEnd == src.myEnd;
146  }
147  bool operator!=(const iterator &cmp) const
148  { return !(*this == cmp); }
149  bool atEnd() const
150  { return myCurr >= myEnd; }
151  iterator &operator++() { advance(); return *this; }
152  // No post increment as it is harmful.
153  void rewind()
154  {
155  if (myFactory)
156  {
157  myFactory->getDefinitionIdRange(
158  myCurr, myEnd
159  );
160  // Go one beyond last definition
161  myEnd++;
162  }
163  }
164 
165  void advance()
166  {
167  for (myCurr++; myCurr < myEnd; ++myCurr)
168  {
169  // Skip empty entries in the table
170  if (myFactory->lookupDefinition(myCurr))
171  break;
172  }
173  }
175  { return myFactory->lookupDefinition(myCurr); }
176  private:
178  : myFactory(f)
179  {
180  rewind();
181  }
182  const GA_PrimitiveFactory *myFactory;
183  unsigned int myCurr, myEnd;
184  friend class GA_PrimitiveFactory;
185  };
186  iterator begin() const { return iterator(this); }
187 
188  /// @{
189  /// Interface to the IO table -- this may not exist in future versions
190  bool registerIO(GA_IO *io)
191  { return myIOTable.add(io); }
192  const GA_IO *findIO(const char *name) const
193  { return myIOTable.find(name); }
194  void getIONames(UT_StringArray &names) const
195  { myIOTable.getNames(names); }
196  /// @}
197 
198  /// add a callback to call when a new primitive type is added
200 
201 private:
202  /// Access detail/global intrinsic attributes defined for this factory
203  const GA_IntrinsicManager &getDetailIntrinsics() const
204  { return myDetailIntrinsics; }
205  GA_IntrinsicManager &getDetailIntrinsics()
206  { return myDetailIntrinsics; }
207 
208  const UT_StringArray &getPrimitiveIntrinsics();
209 
212  const UT_FSATable *myFactoryIds;
213  unsigned int myNextId;
214  GA_PrimitiveTypeMask myTypeMask;
215 
216  GA_IntrinsicManager myDetailIntrinsics;
217  UT_StringArray *myPrimitiveIntrinsics;
218  UT_Lock myPrimitiveIntrinsicsMutex;
219 
220  /// Currently, we use the primitive factory as a place to store the IO
221  /// table. It's really a per-detail specialization variable, and this is
222  /// the best place to put it. We rely on the detail friendliness to allow
223  /// access to it.
224  GA_IOTable myIOTable;
225 
226  /// true iff this primitive factory is for use in GEO_Detail,
227  /// and not GD_Detail.
228  const bool myForPrimaryDetail;
229 
230  UT_Array< UT_Functor<void> > myPrimTypeAddedCallbacks;
231 
232  friend class GA_Detail;
234 };
235 
236 #endif
GLint first
Definition: glcorearb.h:405
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
GA_PrimitiveTypeId getFactoryTypeId(int id) const
Given a factory type id, return the corresponding GA_PrimitiveTypeId.
Manager to keep track of global handle to name mappings.
#define GA_API
Definition: GA_API.h:14
GA_PrimitiveFamilyMask
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
Definition: ImathFun.h:84
void getDetailIntrinsicNames(UT_StringArray &names) const
GLfloat f
Definition: glcorearb.h:1926
Container class to store GA_IO objects for a detail specialization.
Definition: GA_IOTable.h:29
bool operator!=(const iterator &cmp) const
GLint GLuint mask
Definition: glcorearb.h:124
iterator & operator=(const iterator &src)
bool isForPrimaryDetail() const
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_ArrayStringMap< UT_StringHolder > ga_DSODefinitions
void getIONames(UT_StringArray &names) const
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
const GA_PrimitiveDefinition * def() const
void(* GA_PrimitiveBlockConstructor)(GA_Primitive **new_prims, GA_Size nprimitives, GA_Detail &detail, GA_Offset start_offset, const GA_PrimitiveDefinition &def, bool allowed_to_parallelize)
int getPrimTypeCount() const
iterator begin() const
Container class for all geometry.
Definition: GA_Detail.h:96
bool registerIO(GA_IO *io)
Definition of a geometric primitive.
const GA_IO * findIO(const char *name) const
bool operator==(const iterator &src) const
void addPrimTypeAddedCallback(const UT_Functor< void > &cb)
add a callback to call when a new primitive type is added
Class to traverse all primitive definitions in the factory.
GLenum src
Definition: glcorearb.h:1793