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  /// Iterate over all packed primitive types and clear any cached geometry
86  /// for the type. The method returns the number of cached items cleared.
87  static exint clearCachedGeometry();
88 
89  /// @{
90  /// Implementation of methods from GEO level
91  void stashed(bool beingstashed,
93  bool isDegenerate() const override;
94  void transform(const UT_Matrix4 &xform) override;
95  fpreal calcVolume(const UT_Vector3 &refpt) const override;
96  fpreal calcArea() const override;
97  fpreal calcPerimeter() const override;
99  UT_BoundingBox &b) const override;
101  UT_Vector3 &v1) const override;
102  virtual void getWidthRange(fpreal &v0, fpreal &v1) const;
103  void getFullTransform4(UT_Matrix4D &xform) const override;
104  bool saveOptions(UT_Options &options,
105  const GA_SaveMap &map) const override;
106  bool loadOptions(const UT_Options &options,
107  const GA_LoadMap &map) override;
109  const GA_LoadMap &map) override;
110  bool loadOptionsJSONMap(UT_JSONValueMap &options,
111  const GA_LoadMap &map) override;
112  bool supportsJSONLoad() const override;
113  bool loadUnknownToken(const char *token,
114  UT_JSONParser &p,
115  const GA_LoadMap &map) override;
116  void copyImplementation(const GEO_PrimPacked &src) override;
117  bool saveSharedLoadData(
118  UT_JSONWriter &w,
119  GA_SaveMap &map,
120  GA_GeometryIndex *geo_index) const override;
122  int dtype,
123  GA_SharedDataHandlePtr item) override;
124  void setAttributeNameMap(
125  const GEO_PackedNameMapPtr &m) override;
126  const GEO_PackedNameMapPtr &attributeNameMap() const override;
127  void setFacesetAttribute(
128  const UT_StringHolder &s) override;
129  const UT_StringHolder &facesetAttribute() const override;
130  /// @}
131 
132  /// Implementation of methods from GEO level. If the boxCache() is valid,
133  /// it will be used instead of calling the implementation to perform the
134  /// computation. The implementation should make sure to properly call the
135  /// dirty() methods.
137  bool getUntransformedBounds(UT_BoundingBox &b) const override final
138  { return sharedImplementation()->getBoundsCached(b); }
139 
141  bool getUntransformedVisibleBounds(UT_BoundingBox &b) const override final
142  { return sharedImplementation()->getVisibleBoundsCached(b); }
143 
144  /// Set the value for the path attribute. If the @c value is @c NULL, the
145  /// default primitive "path" from the implementation will be used.
146  /// This method may add the "path" attribute if it doesn't already exist.
147  bool setPathAttribute(const char *value=NULL,
148  const char *attrib="path");
149 
150  /// Report approximate memory usage.
151  int64 getMemoryUsage() const override;
152 
153  /// Count memory usage using a UT_MemoryCounter in order to count
154  /// shared memory correctly.
155  /// NOTE: This should always include sizeof(*this).
156  void countMemory(UT_MemoryCounter &counter) const override;
157 
158  /// Register a procedural factory.
159  static void registerPacked(GA_PrimitiveFactory *prim,
161 
162  // Conversion Methods
164  GA_PointGroup *usedpts = 0) override;
166 
167  void normal(NormalComp &output) const override {}
168  void normal(NormalCompD &output) const override {}
169 
170  /// Return the implementation's packed detail. This might return a NULL
171  /// pointer.
172  /// This packed detail should be @b untransformed (i.e. the primitive's
173  /// transform shouldn't be included in this).
175  { return sharedImplementation()->getPackedDetail(); }
177  { return sharedImplementation()->getPackedDetail(&context); }
178  /// Unpack the packed geometry into the given detail. This method should
179  /// ensure that the unpacked geometry has the primitive's transform
180  /// applied.
181  bool unpack(GU_Detail &dest) const
182  { return sharedImplementation()->unpack(dest, this); }
183  bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
184  { return sharedImplementation()->unpackWithContext(dest, context, this); }
185  bool unpackUsingPolygons(GU_Detail &dest) const
186  { return sharedImplementation()->unpackUsingPolygons(dest, this); }
187 
188  /// Return the number of Packed Prims contained in this Packed Prim.
189  /// Returns nullopt if the packedPrim does not
190  /// support a reliable or fast way to get the number
191  /// of sub-packed prims
192  UT_Optional<exint> getNumPackedPrims() const;
193 
194  /// Unpack the packed geometry as with the unpack function. In addition,
195  /// returns a STY_Styler for each unpacked primitive.
197  GU_Detail &dest,
198  STY_StylerGroup &prim_styler_group,
199  const STY_Styler &parent_styler) const
200  {
201  return sharedImplementation()->unpackWithStyler(
202  dest, prim_styler_group, parent_styler, this);
203  }
204 
205  void forceLoad() const
206  { return sharedImplementation()->forceLoad(); }
207 
208  bool isLoaded() const
209  { return sharedImplementation()->isLoaded(); }
210 
211  /// Returns a const pointer to the GU_PackedImpl.
212  /// If you need to modify the GU_PackedImpl, call hardenImplementation()
213  /// @{
215  const GU_PackedImpl *sharedImplementation() const { return myImplementation.get(); }
217  const GU_PackedImpl *sharedImplementation() { return myImplementation.get(); }
218  /// @}
219  SYS_DEPRECATED_REPLACE(18.5, sharedImplementation) SYS_FORCE_INLINE
220  const GU_PackedImpl *implementation() { return myImplementation.get(); }
221 
222 
223  /// Checks if the GU_PackedImpl is shared, and if so, copies it, to make it
224  /// unshared, before returning a non-const pointer to it.
227  {
228  const GU_PackedImpl *impl = myImplementation.get();
229  if (impl->isShared())
230  {
231  impl = impl->copy();
232  myImplementation = impl;
233  }
234  return SYSconst_cast(impl);
235  }
236 
237  /// Replaces the primitive's GU_PackedImpl with the specified one.
238  /// If add_ref is false, the caller is responsible for adding the
239  /// reference to the new impl. If remove_ref is false, the caller
240  /// is responsible for removing the reference from the old impl.
241  /// NB: This may change the TypeId of this primitive, requiring a
242  /// rebuildTracker on the primitive list.
244  void setImplementation(const GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
245  {
246  if (impl == myImplementation.get())
247  return;
248  if (!remove_ref)
249  myImplementation.detach();
250  myImplementation.reset(impl, add_ref);
251  }
252 
253  /// @{
254  /// Implementation of dirty methods from GEO
255  void transformDirty() override;
256  void attributeDirty() override;
257  void topologyDirty() override;
258  /// @}
259 
260  /// multiply xform by transform derived from pivot, local, P and instance
261  /// attributes
262  void multiplyByPrimTransform(UT_Matrix4D &xform) const;
263 
264  /// Implementation of getFullFullTransform4() which isn't virtual
265  /// and doesn't use caching.
266  void computeFullTransform4(UT_Matrix4D &xform) const;
267 protected:
268  GA_DECLARE_INTRINSICS(override);
269  bool doConvert(const GEO_ConvertParms &parms) const;
270 
271 private:
272  UT_IntrusivePtr<const GU_PackedImpl> myImplementation;
273  mutable UT_Matrix4D myCachedFullTransform;
274  mutable SYS_AtomicInt64 myCachedFullTransformCount;
275 };
276 
277 #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