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  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 
161  /// Return the implementation's packed detail. This might return a NULL
162  /// pointer.
163  /// This packed detail should be @b untransformed (i.e. the primitive's
164  /// transform shouldn't be included in this).
166  { return sharedImplementation()->getPackedDetail(); }
168  { return sharedImplementation()->getPackedDetail(&context); }
169  /// Unpack the packed geometry into the given detail. This method should
170  /// ensure that the unpacked geometry has the primitive's transform
171  /// applied.
172  bool unpack(GU_Detail &dest) const
173  { return sharedImplementation()->unpack(dest, this); }
175  { return sharedImplementation()->unpackWithContext(dest, context, this); }
176  bool unpackUsingPolygons(GU_Detail &dest) const
177  { return sharedImplementation()->unpackUsingPolygons(dest, this); }
178 
179  /// Unpack the packed geometry as with the unpack function. In addition,
180  /// returns a STY_Styler for each unpacked primitive.
182  GU_Detail &dest,
183  STY_StylerGroup &prim_styler_group,
184  const STY_Styler &parent_styler) const
185  {
186  return sharedImplementation()->unpackWithStyler(
187  dest, prim_styler_group, parent_styler, this);
188  }
189 
190  void forceLoad() const
191  { return sharedImplementation()->forceLoad(); }
192 
193  bool isLoaded() const
194  { return sharedImplementation()->isLoaded(); }
195 
196  /// Returns a const pointer to the GU_PackedImpl.
197  /// If you need to modify the GU_PackedImpl, call hardenImplementation()
198  /// @{
200  const GU_PackedImpl *sharedImplementation() const { return myImplementation.get(); }
202  const GU_PackedImpl *sharedImplementation() { return myImplementation.get(); }
203  /// @}
204  SYS_DEPRECATED_REPLACE(18.5, sharedImplementation) SYS_FORCE_INLINE
205  const GU_PackedImpl *implementation() { return myImplementation.get(); }
206 
207 
208  /// Checks if the GU_PackedImpl is shared, and if so, copies it, to make it
209  /// unshared, before returning a non-const pointer to it.
212  {
213  GU_PackedImpl *impl = myImplementation.get();
214  if (impl->isShared())
215  {
216  impl = impl->copy();
217  myImplementation = impl;
218  }
219  return impl;
220  }
221 
222  /// Replaces the primitive's GU_PackedImpl with the specified one.
223  /// If add_ref is false, the caller is responsible for adding the
224  /// reference to the new impl. If remove_ref is false, the caller
225  /// is responsible for removing the reference from the old impl.
227  void setImplementation(GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
228  {
229  if (impl == myImplementation.get())
230  return;
231  if (!remove_ref)
232  myImplementation.detach();
233  myImplementation.reset(impl, add_ref);
234  }
235 
236  /// @{
237  /// Implementation of dirty methods from GEO
238  void transformDirty() override;
239  void attributeDirty() override;
240  void topologyDirty() override;
241  /// @}
242 
243  /// multiply xform by transform derived from pivot, local, P and instance
244  /// attributes
245  void multiplyByPrimTransform(UT_Matrix4D &xform) const;
246 protected:
247  GA_DECLARE_INTRINSICS(override);
248  bool doConvert(const GEO_ConvertParms &parms) const;
249 
250 private:
251  UT_IntrusivePtr<GU_PackedImpl> myImplementation;
252  mutable UT_Matrix4D myCachedFullTransform;
253  mutable int64 myCachedFullTransformCount;
254 };
255 
256 #endif
GLdouble s
Definition: glew.h:1390
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.
GLenum src
Definition: glew.h:2410
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
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
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:76
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
const GLdouble * m
Definition: glew.h:9124
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
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:233
virtual const GEO_PackedNameMapPtr & attributeNameMap() const =0
virtual void attributeDirty()
#define GA_INVALID_OFFSET
Definition: GA_Types.h:676
virtual void normal(NormalComp &output) const =0
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:639
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
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
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
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
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET) override
SYS_FORCE_INLINE const GU_PackedImpl * sharedImplementation()
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
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.
GLuint counter
Definition: glew.h:2740
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 v0
Definition: glew.h:1848
virtual bool loadUnknownToken(const char *token, UT_JSONParser &p, const GA_LoadMap &map)=0
GU_ConstDetailHandle getPackedDetail() const
Container class for all geometry.
Definition: GA_Detail.h:95
SYS_FORCE_INLINE void setImplementation(GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
virtual void topologyDirty()
static bool isPackedPrimitive(const GA_Primitive &prim)
Definition: GU_PrimPacked.h:67
Definition of a geometric primitive.
#define const
Definition: zconf.h:214
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()
GLsizei const GLfloat * value
Definition: glew.h:1849
GLfloat GLfloat v1
Definition: glew.h:1852
virtual bool loadOptionsJSONMap(UT_JSONValueMap &options, const GA_LoadMap &map)=0
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
GLintptr offset
Definition: glew.h:1682
bool unpackWithStyler(GU_Detail &dest, STY_StylerGroup &prim_styler_group, const STY_Styler &parent_styler) const
fpreal calcArea() const override=0