HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_PrimitiveDefinition.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_PrimitiveDefinition.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_PrimitiveDefinition__
14 #define __GA_PrimitiveDefinition__
15 
16 #include "GA_API.h"
17 #include "GA_IntrinsicManager.h"
18 #include "GA_PrimitiveFamilyMask.h"
19 #include "GA_PrimitiveTypeId.h"
20 #include "GA_Types.h"
21 
22 #include <UT/UT_StringHolder.h>
23 #include <SYS/SYS_Inline.h>
24 
25 class UT_Options;
26 class GA_Detail;
27 class GA_MergeMap;
28 class GA_Primitive;
31 class GA_PrimitiveList;
32 class GA_LoadMap;
33 class GA_SharedLoadData;
35 
37  GA_Primitive **new_prims,
38  GA_Size nprimitives,
39  GA_Detail &detail,
40  GA_Offset start_offset,
41  const GA_PrimitiveDefinition &def,
42  bool allowed_to_parallelize);
43 
44 /// @brief Definition of a geometric primitive
45 ///
46 /// Every primitive type is registered with a GA_PrimitiveFactory which creates
47 /// a GA_PrimitiveDefinition. Each GA_PrimitiveDefinition in a given
48 /// GA_PrimitiveFactory is assigned a unique identifier. In addition, an
49 /// optional family mask can be registered with the type to specify from which
50 /// standard primitive types (managed by that factory) the new GA_Primitive
51 /// subclass derives.
52 ///
53 /// The GA_PrimitiveDefinition for the new type registers a constructor
54 /// function that will be used to allocate new instances of that type.
55 ///
56 /// Finally, the definition also contains a list of "intrinsics" that can
57 /// be queried from primitives of that type.
59 {
60 public:
61  /// The name of the primitive
62  const UT_StringHolder &getToken() const { return myToken; }
63  /// The label (user friendly & readable token) of the primitive
64  const UT_StringHolder &getLabel() const { return myLabel; }
65  /// The icon associated with the primitive type (if any).
66  const UT_StringHolder &getIcon() const { return myIcon; }
67 
68  /// The unique ID assigned by the GA_PrimitiveFactory
70  const GA_PrimitiveTypeId &getId() const { return myId; }
71  /// The optional family mask
72  GA_PrimitiveFamilyMask getFamilyMask() const { return myFamilyMask; }
73 
74  /// Primitive intrinsic attributes defined for this primitive
76  { return myIntrinsicManager; }
78  { return myIntrinsicManager; }
79 
80  /// Set the label for the primitive
82  { myLabel = label; }
83 
84  /// Set the icon for the primitive
85  void setIcon(const UT_StringHolder &icon)
86  { myIcon = icon; }
87 
88  /// NOTE: This used to set the merge constructor, but merge constructors are
89  /// no longer a thing. Please make sure that the regular constructor of
90  /// your primitive types don't add any vertices to the detail or anything
91  /// else thread-unsafe like that. You can always add vertices and
92  /// initialize them later. This change was required in order for all
93  /// primitive types to be able to be constructed in parallel.
94  SYS_DEPRECATED_REPLACE(16.0, a threadsafe primitive constructor that doesnt add any vertices to the detail)
95  void setMergeConstructor(GA_Primitive *(*ctor)(const GA_MergeMap &map, GA_Detail &dest_detail, GA_Offset dest_offset, const GA_Primitive &src_prim))
96  { UT_ASSERT_MSG(0, "This should never be called anymore! All regular constructors must be threadsafe. This function is only here for the deprecation warning message."); }
97 
98  /// Return whether the primitive has a transform associated with it
99  bool hasLocalTransform() const { return myHasLocalTransform; }
100  /// Set whether the primitive is has a transform associated with it
101  void setHasLocalTransform(bool x) { myHasLocalTransform = x; }
102 
103  /// Return whether the primitive is able to be cached on the GPU.
104  bool hasCECaches() const { return myHasCECaches; }
105  void setHasCECaches(bool x) { myHasCECaches = x; }
106 
107  /// Returns true if this type is for use by GEO_Detail and false
108  /// if this type is for use by GD_Detail.
109  bool isForPrimaryDetail() const { return myForPrimaryDetail; }
110 
111  /// Class to load shared data.
113  {
114  public:
116  virtual ~SharedDataLoader() {}
117  /// Loads shared data from the parser given returning the shared load data object
118  ///
119  /// The loader also takes one of two things:
120  ///
121  /// 1. A random primitive (for now the first that requests shared) is given to the loader
122  /// because voxel array shared data loader needs one because of incorrect splitting of
123  /// data across the primitive and the shared voxels.
124  ///
125  /// 2. The load map from IOJSON. This is used when we are loading without delay. To get a primitive
126  /// the loader must ask the load map for one using its key.
127  ///
128  /// It takes these things when it really should not because volume shared data was designed
129  /// poorly and some of the data that should be shared is kept with the primitive and is
130  /// needed to load the shared data. (Examples: Size, Border of voxel array, there may be more)
131  ///
132  /// IF YOU ARE WRITING A NEW SHARED DATA LOADER DO NOT USE THE SECOND TWO PARAMETERS!!
133  virtual GA_SharedLoadData *load(UT_JSONParser &p,
134  GA_LoadMap *load_map,
135  GA_Primitive *random_prim) const = 0;
136 
137  /// Stats the shared data from the parser given returning a shared load data stat object
138  /// The default implementation for stat is to return a NULL pointer because most
139  /// shared data does not have stat. (mostly used for packed geometry)
140  /// This should only be called when delayed loading
141  virtual GA_SharedLoadDataStat* stat(UT_JSONParser& parser) const { return NULL; }
142  };
143  /// Return whether the primitive type has a shared data loader.
144  bool hasSharedLoadData() const
145  { return mySharedDataLoader != 0; }
146  /// Associate the primitive type with a shared data loader.
148  { mySharedDataLoader = l; }
150  { return mySharedDataLoader; }
151 
152 private:
153  /// Get the primitive block constructor.
154  /// NOTE: This should only be called via GA_PrimitiveList.
155  GA_PrimitiveBlockConstructor getConstructor() const
156  { return myConstructor; }
157 
158  /// Constructor
160  GA_PrimitiveFactory &factory,
161  const UT_StringHolder &name,
162  const GA_PrimitiveTypeId &id,
163  GA_PrimitiveFamilyMask family_mask,
165  bool isforprimarydetail);
166 
167  /// Destructor
169 
170  /// Back pointer to the factory which owns this
171  GA_PrimitiveFactory &myFactory;
172 
173  /// Intrinsics defined for this primitive type
174  GA_IntrinsicManager myIntrinsicManager;
175 
176  /// Name of the primitive
177  UT_StringHolder myToken;
178 
179  /// Label for the primitive (a nice name)
180  UT_StringHolder myLabel;
181 
182  /// Icon for the primitive (to show in the data tree and elsewhere)
183  UT_StringHolder myIcon;
184 
185  /// Unique ID (assigned at run-time)
186  GA_PrimitiveTypeId myId;
187  /// Optional family mask
188  GA_PrimitiveFamilyMask myFamilyMask;
189 
190  /// This creates a block of primitives, so that only one call
191  /// needs to be done via a function pointer.
192  GA_PrimitiveBlockConstructor myConstructor;
193 
194  const SharedDataLoader *mySharedDataLoader;
195 
196  /// Whether the primitive has a transform (like a quadric)
197  bool myHasLocalTransform;
198 
199  /// Whether the primitive can be cached on the GPU
200  bool myHasCECaches;
201 
202  /// true iff this primitive type is for use in GEO_Detail,
203  /// and not GD_Detail.
204  const bool myForPrimaryDetail;
205 
206  friend class GA_PrimitiveFactory;
207  friend class GA_PrimitiveList;
208 };
209 
210 #endif
void setHasLocalTransform(bool x)
Set whether the primitive is has a transform associated with it.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
virtual GA_SharedLoadDataStat * stat(UT_JSONParser &parser) const
void
Definition: png.h:1083
bool hasCECaches() const
Return whether the primitive is able to be cached on the GPU.
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
Manager to keep track of global handle to name mappings.
#define GA_API
Definition: GA_API.h:14
const GA_IntrinsicManager & getIntrinsicManager() const
Primitive intrinsic attributes defined for this primitive.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
void setSharedDataLoader(const SharedDataLoader *l)
Associate the primitive type with a shared data loader.
GA_PrimitiveFamilyMask
const UT_StringHolder & getIcon() const
The icon associated with the primitive type (if any).
#define UT_ASSERT_MSG(ZZ,...)
Definition: UT_Assert.h:159
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
GA_Size GA_Offset
Definition: GA_Types.h:641
GA_PrimitiveFamilyMask getFamilyMask() const
The optional family mask.
void setIcon(const UT_StringHolder &icon)
Set the icon for the primitive.
GA_IntrinsicManager & getIntrinsicManager()
const UT_StringHolder & getToken() const
The name of the primitive.
bool any(const vbool4 &v)
Definition: simd.h:3468
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Options during loading.
Definition: GA_LoadMap.h:42
bool hasSharedLoadData() const
Return whether the primitive type has a shared data loader.
GLuint const GLchar * name
Definition: glcorearb.h:786
GLint GLenum GLint x
Definition: glcorearb.h:409
A list of primitives.
SYS_FORCE_INLINE const GA_PrimitiveTypeId & getId() const
The unique ID assigned by the GA_PrimitiveFactory.
A map of string to various well defined value types.
Definition: UT_Options.h:84
const SharedDataLoader * sharedDataLoader() 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)
Container class for all geometry.
Definition: GA_Detail.h:96
Definition of a geometric primitive.
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define const
Definition: zconf.h:214
bool hasLocalTransform() const
Return whether the primitive has a transform associated with it.
const UT_StringHolder & getLabel() const
The label (user friendly & readable token) of the primitive.
void setLabel(const UT_StringHolder &label)
Set the label for the primitive.