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  virtual ~GU_PrimPacked();
39 
40  virtual const GA_PrimitiveDefinition &getTypeDef() const;
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  virtual void stashed(bool beingstashed,
90  virtual bool isDegenerate() const;
91  virtual void transform(const UT_Matrix4 &xform);
92  virtual fpreal calcVolume(const UT_Vector3 &refpt) const;
93  virtual fpreal calcArea() const;
94  virtual fpreal calcPerimeter() const;
96  UT_BoundingBox &b) const;
97  virtual void getVelocityRange(UT_Vector3 &v0, UT_Vector3 &v1) const;
98  virtual void getWidthRange(fpreal &v0, fpreal &v1) const;
99  virtual void getFullTransform4(UT_Matrix4D &xform) const;
100  virtual bool saveOptions(UT_Options &options,
101  const GA_SaveMap &map) const;
102  virtual bool loadOptions(const UT_Options &options,
103  const GA_LoadMap &map);
104  virtual bool loadOptionsJSON(UT_JSONParser &p,
105  const GA_LoadMap &map);
106  virtual bool loadOptionsJSONMap(UT_JSONValueMap &options,
107  const GA_LoadMap &map);
108  virtual bool supportsJSONLoad() const;
109  virtual bool loadUnknownToken(const char *token,
110  UT_JSONParser &p,
111  const GA_LoadMap &map);
112  virtual void copyImplementation(const GEO_PrimPacked &src);
113  virtual bool saveSharedLoadData(UT_JSONWriter &w,
114  GA_SaveMap &map, GA_GeometryIndex* geometryIndex) const;
115  virtual bool registerSharedLoadData(int dtype, GA_SharedDataHandlePtr item);
116  virtual void setAttributeNameMap(const GEO_PackedNameMapPtr &m);
117  virtual const GEO_PackedNameMapPtr &attributeNameMap() const;
118  virtual void setFacesetAttribute(const UT_StringHolder &s);
119  virtual const UT_StringHolder &facesetAttribute() const;
120  /// @}
121  /// Implementation of methods from GEO level. If the boxCache() is valid,
122  /// it will be used instead of calling the implementation to perform the
123  /// computation. The implementation should make sure to properly call the
124  /// dirty() methods.
126  virtual bool getUntransformedBounds(UT_BoundingBox &b) const final
127  { return implementation()->getBoundsCached(b); }
128 
129  /// Set the value for the path attribute. If the @c value is @c NULL, the
130  /// default primitive "path" from the implementation will be used.
131  /// This method may add the "path" attribute if it doesn't already exist.
132  bool setPathAttribute(const char *value=NULL,
133  const char *attrib="path");
134 
135  /// Report approximate memory usage.
136  virtual int64 getMemoryUsage() const;
137 
138  /// Count memory usage using a UT_MemoryCounter in order to count
139  /// shared memory correctly.
140  /// NOTE: This should always include sizeof(*this).
141  virtual void countMemory(UT_MemoryCounter &counter) const;
142 
143  /// Register a procedural factory.
144  static void registerPacked(GA_PrimitiveFactory *prim,
145  GU_PackedFactory *proc);
146 
147  // Conversion Methods
148  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
149  GA_PointGroup *usedpts = 0);
150  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
151 
152  virtual void normal(NormalComp &output) const;
153 
154  /// Return the implementation's packed detail. This might return a NULL
155  /// pointer.
156  /// This packed detail should be @b untransformed (i.e. the primitive's
157  /// transform shouldn't be included in this).
159  { return implementation()->getPackedDetail(); }
161  { return implementation()->getPackedDetail(&context); }
162  /// Unpack the packed geometry into the given detail. This method should
163  /// ensure that the unpacked geometry has the primitive's transform
164  /// applied.
165  bool unpack(GU_Detail &dest) const
166  { return implementation()->unpack(dest, this); }
168  { return implementation()->unpackWithContext(dest, context, this); }
169  bool unpackUsingPolygons(GU_Detail &dest) const
170  { return implementation()->unpackUsingPolygons(dest, this); }
171 
172  /// Unpack the packed geometry as with the unpack function. In addition,
173  /// returns a STY_Styler for each unpacked primitive.
175  GU_Detail &dest,
176  STY_StylerGroup &prim_styler_group,
177  const STY_Styler &parent_styler) const
178  {
179  return implementation()->unpackWithStyler(
180  dest, prim_styler_group, parent_styler, this);
181  }
182 
183  void forceLoad() const
184  { return implementation()->forceLoad(); }
185 
186  bool isLoaded() const
187  { return implementation()->isLoaded(); }
188 
189  /// Returns a const pointer to the GU_PackedImpl.
190  /// If you need to modify the GU_PackedImpl, call hardenImplementation()
191  /// @{
193  const GU_PackedImpl *implementation() const { return myImplementation.get(); }
195  const GU_PackedImpl *implementation() { return myImplementation.get(); }
196  /// @}
197 
198  /// Checks if the GU_PackedImpl is shared, and if so, copies it, to make it
199  /// unshared, before returning a non-const pointer to it.
202  {
203  GU_PackedImpl *impl = myImplementation.get();
204  if (impl->isShared())
205  {
206  impl = impl->copy();
207  myImplementation = impl;
208  }
209  return impl;
210  }
211 
212  /// Replaces the primitive's GU_PackedImpl with the specified one.
213  /// If add_ref is false, the caller is responsible for adding the
214  /// reference to the new impl. If remove_ref is false, the caller
215  /// is responsible for removing the reference from the old impl.
217  void setImplementation(GU_PackedImpl *impl, bool add_ref=true, bool remove_ref=true)
218  {
219  if (impl == myImplementation.get())
220  return;
221  if (!remove_ref)
222  myImplementation.detach();
223  myImplementation.reset(impl, add_ref);
224  }
225 
226  /// @{
227  /// Implementation of dirty methods from GEO
228  virtual void transformDirty();
229  virtual void attributeDirty();
230  virtual void topologyDirty();
231  /// @}
232 
233  /// multiply xform by transform derived from pivot, local, P and instance
234  /// attributes
235  void multiplyByPrimTransform(UT_Matrix4D &xform) const;
236 protected:
238  bool doConvert(const GEO_ConvertParms &parms) const;
239 
240 private:
241  UT_IntrusivePtr<GU_PackedImpl> myImplementation;
242  mutable UT_Matrix4D myCachedFullTransform;
243  mutable int64 myCachedFullTransformCount;
244 };
245 
246 #endif
GLdouble s
Definition: glew.h:1390
void forceLoad() const
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 registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item)=0
virtual bool getUntransformedRenderingBounds(UT_BoundingBox &box) const =0
bool isLoaded() const
virtual fpreal calcPerimeter() const =0
virtual bool loadOptions(const UT_Options &options, const GA_LoadMap &map)=0
virtual fpreal calcArea() const =0
virtual const UT_StringHolder & facesetAttribute() const =0
virtual void transform(const UT_Matrix4 &xform)=0
SYS_FORCE_INLINE const GA_PrimitiveTypeId & getTypeId() const
Definition: GA_Primitive.h:169
GU_ConstDetailHandle getPackedDetail(GU_PackedContext &context) const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#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:32
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:201
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
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:231
virtual const GEO_PackedNameMapPtr & attributeNameMap() const =0
virtual void attributeDirty()
#define GA_INVALID_OFFSET
Definition: GA_Types.h:674
virtual void normal(NormalComp &output) const =0
bool unpackUsingPolygons(GU_Detail &dest) const
virtual void setFacesetAttribute(const UT_StringHolder &s)=0
GA_Size GA_Offset
Definition: GA_Types.h:637
virtual void transformDirty()
long long int64
Definition: SYS_Types.h:111
bool unpack(GU_Detail &dest) const
SYS_FORCE_INLINE bool isShared() const
virtual fpreal calcVolume(const UT_Vector3 &refpt) const =0
virtual void countMemory(UT_MemoryCounter &counter) const
int64 exint
Definition: SYS_Types.h:120
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
virtual void getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const =0
Options during loading.
Definition: GA_LoadMap.h:42
virtual bool isDegenerate() const =0
#define GU_API
Definition: GU_API.h:14
bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
virtual SYS_FORCE_INLINE bool getUntransformedBounds(UT_BoundingBox &b) const final
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
SYS_FORCE_INLINE const GU_PackedImpl * implementation() const
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
double fpreal
Definition: SYS_Types.h:276
A map of string to various well defined value types.
Definition: UT_Options.h:42
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
GLuint counter
Definition: glew.h:2740
virtual bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex *geometryIndex) const
SYS_FORCE_INLINE const GU_PackedImpl * implementation()
virtual bool loadOptionsJSON(UT_JSONParser &p, const GA_LoadMap &map)=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.
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
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
GLintptr offset
Definition: glew.h:1682
bool unpackWithStyler(GU_Detail &dest, STY_StylerGroup &prim_styler_group, const STY_Styler &parent_styler) const