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