HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PrimPacked.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: GU_PrimPacked.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PrimPacked__
12 #define __GU_PrimPacked__
13 
14 #include "GU_API.h"
15 #include "GU_Detail.h"
16 #include "GU_PackedImpl.h"
17 #include <GEO/GEO_PrimPacked.h>
19 #include <UT/UT_IntrusivePtr.h>
20 
21 class GU_PackedFactory;
22 class GU_PackedImpl;
23 class GU_PackedContext;
24 class GEO_ConvertParms;
25 class UT_MemoryCounter;
26 
28 {
29 public:
30  // This constructor creates a new GU_PrimPacked but does
31  // not append it to the detail.
32  // Set add_impl_ref to false if the caller is adding references in bulk.
34  const GU_PackedImpl *impl,
35  GU_Detail *gdp,
37  bool add_impl_ref=true);
38  ~GU_PrimPacked() override;
39 
40  const GA_PrimitiveDefinition &getTypeDef() const override;
41 
42  /// @{
43  /// Find the type information for a given implementation. May return NULL
44  /// or invalid if the type isn't implemented.
45  static const GA_PrimitiveDefinition *lookupTypeDef(const UT_StringRef&type);
46  static GA_PrimitiveTypeId lookupTypeId(const UT_StringRef &type);
47  /// @}
48 
49  /// Build a packed primitive of the specified type name in the given detail.
50  /// @{
51  static GU_PrimPacked *build(GU_Detail &gdp, const UT_StringRef &type,
52  GA_Offset pt_off = GA_INVALID_OFFSET);
53  static GU_PrimPacked *build(GU_Detail &gdp, const UT_StringRef &type,
54  const UT_Options &options,
55  GA_Offset pt_off = GA_INVALID_OFFSET);
56  static GU_PrimPacked *build(GU_Detail &gdp, const GA_PrimitiveTypeId &type,
57  GA_Offset pt_off = GA_INVALID_OFFSET);
58  static GU_PrimPacked *build(GU_Detail &gdp, const GA_PrimitiveTypeId &type,
59  const UT_Options &options,
60  GA_Offset pt_off = GA_INVALID_OFFSET);
61  /// @}
62 
63  /// Return true if the primitive definition is implemented using the packed
64  /// primitive interface.
65  static bool isPackedPrimitive(const GA_PrimitiveDefinition &pdef);
66  static bool isPackedPrimitive(const GA_PrimitiveTypeId &type);
67  static bool isPackedPrimitive(const GA_Primitive &prim);
68 
69  static bool isPackedPrimitiveFromLabel(const UT_StringHolder &label);
70  static bool isPackedPrimitiveFromToken(const UT_StringHolder &token);
71 
72  /// Convenience method to check whether a detail has any
73  /// packed primitives
74  static bool hasPackedPrimitives(const GA_Detail &gdp);
75 
76  /// Convenience method to return the number of packed primitives
77  static GA_Size countPackedPrimitives(const GA_Detail &gdp);
78 
79  /// Returns all the packed primitives in the gdp. Unlike the counting
80  /// functions above, this function requires iterating through all
81  /// primitives.
82  static bool getPackedPrimitives(const GA_Detail &gdp,
84 
85  /// Returns a list of type-ids of all registered packed primitive types.
86  static void getPackedPrimitiveTypeIds(
88 
89  /// Iterate over all packed primitive types and clear any cached geometry
90  /// for the type. The method returns the number of cached items cleared.
91  static exint clearCachedGeometry();
92 
93  /// @{
94  /// Implementation of methods from GEO level
95  void stashed(bool beingstashed,
97  bool isDegenerate() const override;
98  void transform(const UT_Matrix4 &xform) override;
99  fpreal calcVolume(const UT_Vector3 &refpt) const override;
100  fpreal calcArea() const override;
101  fpreal calcPerimeter() const override;
103  UT_BoundingBox &b) const override;
105  UT_Vector3 &v1) const override;
106  virtual void getWidthRange(fpreal &v0, fpreal &v1) const;
107  void getFullTransform4(UT_Matrix4D &xform) const override;
108  bool saveOptions(UT_Options &options,
109  const GA_SaveMap &map) const override;
110  bool loadOptions(const UT_Options &options,
111  const GA_LoadMap &map) override;
113  const GA_LoadMap &map) override;
114  bool loadOptionsJSONMap(UT_JSONValueMap &options,
115  const GA_LoadMap &map) override;
116  bool supportsJSONLoad() const override;
117  bool loadUnknownToken(const char *token,
118  UT_JSONParser &p,
119  const GA_LoadMap &map) override;
120  void copyImplementation(const GEO_PrimPacked &src) override;
121  bool saveSharedLoadData(
122  UT_JSONWriter &w,
123  GA_SaveMap &map,
124  GA_GeometryIndex *geo_index) const override;
126  int dtype,
127  GA_SharedDataHandlePtr item) override;
128  void setAttributeNameMap(
129  const GEO_PackedNameMapPtr &m) override;
130  const GEO_PackedNameMapPtr &attributeNameMap() const override;
131  void setFacesetAttribute(
132  const UT_StringHolder &s) override;
133  const UT_StringHolder &facesetAttribute() const override;
134  /// @}
135 
136  /// Implementation of methods from GEO level. If the boxCache() is valid,
137  /// it will be used instead of calling the implementation to perform the
138  /// computation. The implementation should make sure to properly call the
139  /// dirty() methods.
141  bool getUntransformedBounds(UT_BoundingBox &b) const override final
142  { return sharedImplementation()->getBoundsCached(b); }
143 
145  bool getUntransformedVisibleBounds(UT_BoundingBox &b) const override final
146  { return sharedImplementation()->getVisibleBoundsCached(b); }
147 
148  /// Set the value for the path attribute. If the @c value is @c NULL, the
149  /// default primitive "path" from the implementation will be used.
150  /// This method may add the "path" attribute if it doesn't already exist.
151  bool setPathAttribute(const char *value=NULL,
152  const char *attrib="path");
153 
154  /// Report approximate memory usage.
155  int64 getMemoryUsage() const override;
156 
157  /// Count memory usage using a UT_MemoryCounter in order to count
158  /// shared memory correctly.
159  /// NOTE: This should always include sizeof(*this).
160  void countMemory(UT_MemoryCounter &counter) const override;
161 
162  /// Register a procedural factory.
163  static void registerPacked(GA_PrimitiveFactory *prim,
165 
166  // Conversion Methods
168  GA_PointGroup *usedpts = 0) override;
170 
171  void normal(NormalComp &output) const override {}
172  void normal(NormalCompD &output) const override {}
173 
174  /// Return the implementation's packed detail. This might return a NULL
175  /// pointer.
176  /// This packed detail should be @b untransformed (i.e. the primitive's
177  /// transform shouldn't be included in this).
179  { return sharedImplementation()->getPackedDetail(); }
181  { return sharedImplementation()->getPackedDetail(&context); }
182  /// Unpack the packed geometry into the given detail. This method should
183  /// ensure that the unpacked geometry has the primitive's transform
184  /// applied.
185  bool unpack(GU_Detail &dest) const
186  { return sharedImplementation()->unpack(dest, this); }
187  bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
188  { return sharedImplementation()->unpackWithContext(dest, context, this); }
189  bool unpackUsingPolygons(GU_Detail &dest) const
190  { return sharedImplementation()->unpackUsingPolygons(dest, this); }
191 
192  /// Return the number of Packed Prims contained in this Packed Prim.
193  /// Returns nullopt if the packedPrim does not
194  /// support a reliable or fast way to get the number
195  /// of sub-packed prims
196  UT_Optional<exint> getNumPackedPrims() const;
197 
198  /// Unpack the packed geometry as with the unpack function. In addition,
199  /// returns a STY_Styler for each unpacked primitive.
201  GU_Detail &dest,
202  STY_StylerGroup &prim_styler_group,
203  const STY_Styler &parent_styler) const
204  {
205  return sharedImplementation()->unpackWithStyler(
206  dest, prim_styler_group, parent_styler, this);
207  }
208 
209  void forceLoad() const
210  { return sharedImplementation()->forceLoad(); }
211 
212  bool isLoaded() const
213  { return sharedImplementation()->isLoaded(); }
214 
215  /// Returns a const pointer to the GU_PackedImpl.
216  /// If you need to modify the GU_PackedImpl, call hardenImplementation()
217  /// @{
219  const GU_PackedImpl *sharedImplementation() const { return myImplementation.get(); }
221  const GU_PackedImpl *sharedImplementation() { return myImplementation.get(); }
222  /// @}
223  SYS_DEPRECATED_REPLACE(18.5, sharedImplementation) SYS_FORCE_INLINE
224  const GU_PackedImpl *implementation() { return myImplementation.get(); }
225 
226 
227  /// Checks if the GU_PackedImpl is shared, and if so, copies it, to make it
228  /// unshared, before returning a non-const pointer to it.
231  {
232  const GU_PackedImpl *impl = myImplementation.get();
233  if (impl->isShared())
234  {
235  impl = impl->copy();
236  myImplementation = impl;
237  }
238  return SYSconst_cast(impl);
239  }
240 
241  /// Replaces the primitive's GU_PackedImpl with the specified one.
242  /// If add_ref is false, the caller is responsible for adding the
243  /// reference to the new impl. If remove_ref is false, the caller
244  /// is responsible for removing the reference from the old impl.
245  /// NB: This may change the TypeId of this primitive, requiring a
246  /// rebuildTracker on the primitive list.
248  void setImplementation(const GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
249  {
250  if (impl == myImplementation.get())
251  return;
252  if (!remove_ref)
253  myImplementation.detach();
254  myImplementation.reset(impl, add_ref);
255  }
256 
257  /// @{
258  /// Implementation of dirty methods from GEO
259  void transformDirty() override;
260  void attributeDirty() override;
261  void topologyDirty() override;
262  /// @}
263 
264  /// multiply xform by transform derived from pivot, local, P and instance
265  /// attributes
266  void multiplyByPrimTransform(UT_Matrix4D &xform) const;
267 
268  /// Implementation of getFullFullTransform4() which isn't virtual
269  /// and doesn't use caching.
270  void computeFullTransform4(UT_Matrix4D &xform) const;
271 protected:
272  GA_DECLARE_INTRINSICS(override);
273  bool doConvert(const GEO_ConvertParms &parms) const;
274 
275 private:
276  UT_IntrusivePtr<const GU_PackedImpl> myImplementation;
277  mutable UT_Matrix4D myCachedFullTransform;
278  mutable SYS_AtomicInt64 myCachedFullTransformCount;
279 };
280 
281 #endif
SYS_FORCE_INLINE const GU_PackedImpl * sharedImplementation() const
void forceLoad() const
fpreal calcPerimeter() const override=0
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
void normal(NormalComp &output) const override
virtual bool getUntransformedRenderingBounds(UT_BoundingBox &box) const =0
bool isLoaded() const
SYS_FORCE_INLINE bool getUntransformedBounds(UT_BoundingBox &b) const overridefinal
virtual bool loadOptions(const UT_Options &options, const GA_LoadMap &map)=0
GLsizei const GLfloat * value
Definition: glcorearb.h:824
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:136
int64 exint
Definition: SYS_Types.h:125
virtual const UT_StringHolder & facesetAttribute() const =0
GLdouble s
Definition: glad.h:3009
GU_ConstDetailHandle getPackedDetail(GU_PackedContext &context) const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
void transform(const UT_Matrix4 &xform) override=0
virtual void setAttributeNameMap(const GEO_PackedNameMapPtr &m)=0
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:243
virtual const GEO_PackedNameMapPtr & attributeNameMap() const =0
virtual void attributeDirty()
#define GA_INVALID_OFFSET
Definition: GA_Types.h:694
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
bool unpackUsingPolygons(GU_Detail &dest) const
virtual void setFacesetAttribute(const UT_StringHolder &s)=0
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
GA_Size GA_Offset
Definition: GA_Types.h:653
virtual void transformDirty()
bool isDegenerate() const override=0
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
GLintptr offset
Definition: glcorearb.h:665
bool unpack(GU_Detail &dest) const
SYS_FORCE_INLINE bool isShared() const
virtual void countMemory(UT_MemoryCounter &counter) const
virtual void getFullTransform4(UT_Matrix4D &matrix) const =0
virtual bool supportsJSONLoad() const =0
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
virtual void copyImplementation(const GEO_PrimPacked &src)=0
SYS_FORCE_INLINE bool getUntransformedVisibleBounds(UT_BoundingBox &b) const overridefinal
long long int64
Definition: SYS_Types.h:116
virtual void getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const =0
Options during loading.
Definition: GA_LoadMap.h:42
#define GU_API
Definition: GU_API.h:14
bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET) override
GLfloat v0
Definition: glcorearb.h:816
SYS_FORCE_INLINE const GU_PackedImpl * sharedImplementation()
bool registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item) override=0
A map of string to various well defined value types.
Definition: UT_Options.h:87
GA_API const UT_StringHolder parms
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex *geo_index) const override
fpreal64 fpreal
Definition: SYS_Types.h:283
virtual bool loadOptionsJSON(UT_JSONParser &p, const GA_LoadMap &map)=0
fpreal calcVolume(const UT_Vector3 &refpt) const override=0
GLfloat GLfloat v1
Definition: glcorearb.h:817
Processor proc(inIter, Adapter::tree(outGrid), op, merge)
GU_API void xform(CE_Context &context, bool recompile, int npts, const cl::Buffer &outPos, const cl::Buffer &inPos, const cl::Buffer &surfacexform, const cl::Buffer *grp=nullptr)
virtual bool loadUnknownToken(const char *token, UT_JSONParser &p, const GA_LoadMap &map)=0
void normal(NormalCompD &output) const override
GU_ConstDetailHandle getPackedDetail() const
Container class for all geometry.
Definition: GA_Detail.h:105
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
virtual void topologyDirty()
Definition of a geometric primitive.
SYS_FORCE_INLINE void setImplementation(const GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
virtual const GA_PrimitiveDefinition & getTypeDef() const =0
virtual bool saveOptions(UT_Options &options, const GA_SaveMap &map) const =0
SYS_FORCE_INLINE GU_PackedImpl * hardenImplementation()
virtual bool loadOptionsJSONMap(UT_JSONValueMap &options, const GA_LoadMap &map)=0
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
GLenum src
Definition: glcorearb.h:1793
bool unpackWithStyler(GU_Detail &dest, STY_StylerGroup &prim_styler_group, const STY_Styler &parent_styler) const
fpreal calcArea() const override=0