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  /// Implementation of methods from GEO level. If the boxCache() is valid,
129  /// it will be used instead of calling the implementation to perform the
130  /// computation. The implementation should make sure to properly call the
131  /// dirty() methods.
133  bool getUntransformedBounds(UT_BoundingBox &b) const override final
134  { return sharedImplementation()->getBoundsCached(b); }
135 
136  /// Set the value for the path attribute. If the @c value is @c NULL, the
137  /// default primitive "path" from the implementation will be used.
138  /// This method may add the "path" attribute if it doesn't already exist.
139  bool setPathAttribute(const char *value=NULL,
140  const char *attrib="path");
141 
142  /// Report approximate memory usage.
143  int64 getMemoryUsage() const override;
144 
145  /// Count memory usage using a UT_MemoryCounter in order to count
146  /// shared memory correctly.
147  /// NOTE: This should always include sizeof(*this).
148  void countMemory(UT_MemoryCounter &counter) const override;
149 
150  /// Register a procedural factory.
151  static void registerPacked(GA_PrimitiveFactory *prim,
152  GU_PackedFactory *proc);
153 
154  // Conversion Methods
156  GA_PointGroup *usedpts = 0) override;
157  GEO_Primitive *convertNew(GEO_ConvertParms &parms) override;
158 
159  void normal(NormalComp &output) const override {}
160  void normal(NormalCompD &output) const override {}
161 
162  /// Return the implementation's packed detail. This might return a NULL
163  /// pointer.
164  /// This packed detail should be @b untransformed (i.e. the primitive's
165  /// transform shouldn't be included in this).
167  { return sharedImplementation()->getPackedDetail(); }
169  { return sharedImplementation()->getPackedDetail(&context); }
170  /// Unpack the packed geometry into the given detail. This method should
171  /// ensure that the unpacked geometry has the primitive's transform
172  /// applied.
173  bool unpack(GU_Detail &dest) const
174  { return sharedImplementation()->unpack(dest, this); }
175  bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
176  { return sharedImplementation()->unpackWithContext(dest, context, this); }
177  bool unpackUsingPolygons(GU_Detail &dest) const
178  { return sharedImplementation()->unpackUsingPolygons(dest, this); }
179 
180  /// Unpack the packed geometry as with the unpack function. In addition,
181  /// returns a STY_Styler for each unpacked primitive.
183  GU_Detail &dest,
184  STY_StylerGroup &prim_styler_group,
185  const STY_Styler &parent_styler) const
186  {
187  return sharedImplementation()->unpackWithStyler(
188  dest, prim_styler_group, parent_styler, this);
189  }
190 
191  void forceLoad() const
192  { return sharedImplementation()->forceLoad(); }
193 
194  bool isLoaded() const
195  { return sharedImplementation()->isLoaded(); }
196 
197  /// Returns a const pointer to the GU_PackedImpl.
198  /// If you need to modify the GU_PackedImpl, call hardenImplementation()
199  /// @{
201  const GU_PackedImpl *sharedImplementation() const { return myImplementation.get(); }
203  const GU_PackedImpl *sharedImplementation() { return myImplementation.get(); }
204  /// @}
205  SYS_DEPRECATED_REPLACE(18.5, sharedImplementation) SYS_FORCE_INLINE
206  const GU_PackedImpl *implementation() { return myImplementation.get(); }
207 
208 
209  /// Checks if the GU_PackedImpl is shared, and if so, copies it, to make it
210  /// unshared, before returning a non-const pointer to it.
213  {
214  const GU_PackedImpl *impl = myImplementation.get();
215  if (impl->isShared())
216  {
217  impl = impl->copy();
218  myImplementation = impl;
219  }
220  return SYSconst_cast(impl);
221  }
222 
223  /// Replaces the primitive's GU_PackedImpl with the specified one.
224  /// If add_ref is false, the caller is responsible for adding the
225  /// reference to the new impl. If remove_ref is false, the caller
226  /// is responsible for removing the reference from the old impl.
227  /// NB: This may change the TypeId of this primitive, requiring a
228  /// rebuildTracker on the primitive list.
230  void setImplementation(const GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
231  {
232  if (impl == myImplementation.get())
233  return;
234  if (!remove_ref)
235  myImplementation.detach();
236  myImplementation.reset(impl, add_ref);
237  }
238 
239  /// @{
240  /// Implementation of dirty methods from GEO
241  void transformDirty() override;
242  void attributeDirty() override;
243  void topologyDirty() override;
244  /// @}
245 
246  /// multiply xform by transform derived from pivot, local, P and instance
247  /// attributes
248  void multiplyByPrimTransform(UT_Matrix4D &xform) const;
249 
250  /// Implementation of getFullFullTransform4() which isn't virtual
251  /// and doesn't use caching.
252  void computeFullTransform4(UT_Matrix4D &xform) const;
253 protected:
254  GA_DECLARE_INTRINSICS(override);
255  bool doConvert(const GEO_ConvertParms &parms) const;
256 
257 private:
258  UT_IntrusivePtr<const GU_PackedImpl> myImplementation;
259  mutable UT_Matrix4D myCachedFullTransform;
260  mutable SYS_AtomicInt64 myCachedFullTransformCount;
261 };
262 
263 #endif
SYS_FORCE_INLINE const GU_PackedImpl * sharedImplementation() const
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
void forceLoad() const
fpreal calcPerimeter() const override=0
GLuint counter
Definition: glew.h:2745
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
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:88
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
GLenum src
Definition: glcorearb.h:1793
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:234
virtual const GEO_PackedNameMapPtr & attributeNameMap() const =0
virtual void attributeDirty()
#define GA_INVALID_OFFSET
Definition: GA_Types.h:677
bool unpackUsingPolygons(GU_Detail &dest) const
virtual void setFacesetAttribute(const UT_StringHolder &s)=0
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
GA_Size GA_Offset
Definition: GA_Types.h:640
virtual void transformDirty()
bool isDegenerate() const override=0
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
long long int64
Definition: SYS_Types.h:116
virtual void getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const =0
GLfloat GLfloat p
Definition: glew.h:16656
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
GLfloat v0
Definition: glcorearb.h:816
void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET) override
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
const GLdouble * m
Definition: glew.h:9166
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:95
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
virtual void topologyDirty()
Definition: core.h:1131
GLintptr offset
Definition: glcorearb.h:665
static bool isPackedPrimitive(const GA_Primitive &prim)
Definition: GU_PrimPacked.h:67
Definition of a geometric primitive.
#define const
Definition: zconf.h:214
GLfloat GLfloat v1
Definition: glcorearb.h:817
SYS_FORCE_INLINE void setImplementation(const GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
virtual const GA_PrimitiveDefinition & getTypeDef() const =0
type
Definition: core.h:1059
virtual bool saveOptions(UT_Options &options, const GA_SaveMap &map) const =0
SYS_FORCE_INLINE GU_PackedImpl * hardenImplementation()
GLdouble s
Definition: glew.h:1395
virtual bool loadOptionsJSONMap(UT_JSONValueMap &options, const GA_LoadMap &map)=0
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
bool unpackWithStyler(GU_Detail &dest, STY_StylerGroup &prim_styler_group, const STY_Styler &parent_styler) const
fpreal calcArea() const override=0