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, GA_LoadMap* loadMap, GA_Primitive* randomPrimitive) const = 0;
134 
135  /// Stats the shared data from the parser given returning a shared load data stat object
136  /// The default implementation for stat is to return a NULL pointer because most
137  /// shared data does not have stat. (mostly used for packed geometry)
138  /// This should only be called when delayed loading
139  virtual GA_SharedLoadDataStat* stat(UT_JSONParser& parser) const { return NULL; }
140  };
141  /// Return whether the primitive type has a shared data loader.
142  bool hasSharedLoadData() const
143  { return mySharedDataLoader != 0; }
144  /// Associate the primitive type with a shared data loader.
146  { mySharedDataLoader = l; }
148  { return mySharedDataLoader; }
149 
150 private:
151  /// Get the primitive block constructor.
152  /// NOTE: This should only be called via GA_PrimitiveList.
153  GA_PrimitiveBlockConstructor getConstructor() const
154  { return myConstructor; }
155 
156  /// Constructor
158  GA_PrimitiveFactory &factory,
159  const UT_StringHolder &name,
160  const GA_PrimitiveTypeId &id,
161  GA_PrimitiveFamilyMask family_mask,
163  bool isforprimarydetail);
164 
165  /// Destructor
167 
168  /// Back pointer to the factory which owns this
169  GA_PrimitiveFactory &myFactory;
170 
171  /// Intrinsics defined for this primitive type
172  GA_IntrinsicManager myIntrinsicManager;
173 
174  /// Name of the primitive
175  UT_StringHolder myToken;
176 
177  /// Label for the primitive (a nice name)
178  UT_StringHolder myLabel;
179 
180  /// Icon for the primitive (to show in the data tree and elsewhere)
181  UT_StringHolder myIcon;
182 
183  /// Unique ID (assigned at run-time)
184  GA_PrimitiveTypeId myId;
185  /// Optional family mask
186  GA_PrimitiveFamilyMask myFamilyMask;
187 
188  /// This creates a block of primitives, so that only one call
189  /// needs to be done via a function pointer.
190  GA_PrimitiveBlockConstructor myConstructor;
191 
192  const SharedDataLoader *mySharedDataLoader;
193 
194  /// Whether the primitive has a transform (like a quadric)
195  bool myHasLocalTransform;
196 
197  /// Whether the primitive can be cached on the GPU
198  bool myHasCECaches;
199 
200  /// true iff this primitive type is for use in GEO_Detail,
201  /// and not GD_Detail.
202  const bool myForPrimaryDetail;
203 
204  friend class GA_PrimitiveFactory;
205  friend class GA_PrimitiveList;
206 };
207 
208 #endif
void setHasLocalTransform(bool x)
Set whether the primitive is has a transform associated with it.
virtual GA_SharedLoadDataStat * stat(UT_JSONParser &parser) const
GLuint const GLchar * name
Definition: glew.h:1814
bool hasCECaches() const
Return whether the primitive is able to be cached on the GPU.
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:76
Manager to keep track of global handle to name mappings.
#define GA_API
Definition: GA_API.h:12
GLdouble l
Definition: glew.h:9122
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:233
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:138
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
GA_Size GA_Offset
Definition: GA_Types.h:639
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:3372
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
void
Definition: png.h:1083
Options during loading.
Definition: GA_LoadMap.h:42
bool hasSharedLoadData() const
Return whether the primitive type has a shared data loader.
GLuint GLsizei GLsizei GLchar * label
Definition: glew.h:8986
A list of primitives.
GLfloat GLfloat p
Definition: glew.h:16321
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:95
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.