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 
20 class GU_PackedFactory;
21 class GU_PackedImpl;
22 class GU_PackedContext;
23 class GEO_ConvertParms;
24 class UT_MemoryCounter;
25 
27 {
28 public:
29  // This constructor creates a new GU_PrimPacked but does
30  // not append it to the detail
32  GU_Detail *gdp,
34  virtual ~GU_PrimPacked();
35 
36  virtual const GA_PrimitiveDefinition &getTypeDef() const;
37 
38  /// @{
39  /// Find the type information for a given implementation. May return NULL
40  /// or invalid if the type isn't implemented.
41  static const GA_PrimitiveDefinition *lookupTypeDef(const UT_StringRef&type);
42  static GA_PrimitiveTypeId lookupTypeId(const UT_StringRef &type);
43  /// @}
44 
45  /// Build a packed primitive of the specified type name in the given detail.
46  /// @{
47  static GU_PrimPacked *build(GU_Detail &gdp, const UT_StringRef &type,
48  GA_Offset pt_off = GA_INVALID_OFFSET);
49  static GU_PrimPacked *build(GU_Detail &gdp, const UT_StringRef &type,
50  const UT_Options &options,
51  GA_Offset pt_off = GA_INVALID_OFFSET);
52  static GU_PrimPacked *build(GU_Detail &gdp, const GA_PrimitiveTypeId &type,
53  GA_Offset pt_off = GA_INVALID_OFFSET);
54  static GU_PrimPacked *build(GU_Detail &gdp, const GA_PrimitiveTypeId &type,
55  const UT_Options &options,
56  GA_Offset pt_off = GA_INVALID_OFFSET);
57  /// @}
58 
59  /// Return true if the primitive definition is implemented using the packed
60  /// primitive interface.
61  static bool isPackedPrimitive(const GA_PrimitiveDefinition &pdef);
62  static bool isPackedPrimitive(const GA_PrimitiveTypeId &type);
63  static bool isPackedPrimitive(const GA_Primitive &prim)
64  { return isPackedPrimitive(prim.getTypeId()); }
65 
66  /// Convenience method to check whether a detail has any packed primitives
67  static bool hasPackedPrimitives(const GA_Detail &gdp);
68 
69  /// Convenience method to return the number of packed primitives
70  static GA_Size countPackedPrimitives(const GA_Detail &gdp);
71 
72  /// Returns all the packed primitives in the gdp. Unlike the counting
73  /// functions above, this function requires iterating through all
74  /// primitives.
75  static bool getPackedPrimitives(const GA_Detail &gdp,
77 
78  /// Iterate over all packed primitive types and clear any cached geometry
79  /// for the type. The method returns the number of cached items cleared.
80  static exint clearCachedGeometry();
81 
82  /// @{
83  /// Implementation of methods from GEO level
84  virtual void stashed(bool beingstashed,
86  virtual bool isDegenerate() const;
87  virtual void transform(const UT_Matrix4 &xform);
88  virtual fpreal calcVolume(const UT_Vector3 &refpt) const;
89  virtual fpreal calcArea() const;
90  virtual fpreal calcPerimeter() const;
92  UT_BoundingBox &b) const;
93  virtual void getVelocityRange(UT_Vector3 &v0, UT_Vector3 &v1) const;
94  virtual void getWidthRange(fpreal &v0, fpreal &v1) const;
95  virtual void getFullTransform4(UT_Matrix4D &xform) const;
96  virtual bool saveOptions(UT_Options &options,
97  const GA_SaveMap &map) const;
98  virtual bool loadOptions(const UT_Options &options,
99  const GA_LoadMap &map);
100  virtual bool loadOptionsJSON(UT_JSONParser &p,
101  const GA_LoadMap &map);
102  virtual bool loadOptionsJSONMap(UT_JSONValueMap &options,
103  const GA_LoadMap &map);
104  virtual bool supportsJSONLoad() const;
105  virtual bool loadUnknownToken(const char *token,
106  UT_JSONParser &p,
107  const GA_LoadMap &map);
108  virtual void copyImplementation(const GEO_PrimPacked &src);
109  virtual bool saveSharedLoadData(UT_JSONWriter &w,
110  GA_SaveMap &map, GA_GeometryIndex* geometryIndex) const;
111  virtual bool registerSharedLoadData(int dtype, GA_SharedDataHandlePtr item);
112  /// @}
113  /// Implementation of methods from GEO level. If the boxCache() is valid,
114  /// it will be used instead of calling the implementation to perform the
115  /// computation. The implementation should make sure to properly call the
116  /// dirty() methods.
117  virtual bool getUntransformedBounds(UT_BoundingBox &b) const;
118 
119  /// Set the value for the path attribute. If the @c value is @c NULL, the
120  /// default primitive "path" from the implementation will be used.
121  /// This method may add the "path" attribute if it doesn't already exist.
122  bool setPathAttribute(const char *value=NULL,
123  const char *attrib="path");
124 
125  /// Report approximate memory usage.
126  virtual int64 getMemoryUsage() const;
127 
128  /// Count memory usage using a UT_MemoryCounter in order to count
129  /// shared memory correctly.
130  /// NOTE: This should always include sizeof(*this).
131  virtual void countMemory(UT_MemoryCounter &counter) const;
132 
133  /// Register a procedural factory.
134  static void registerPacked(GA_PrimitiveFactory *prim,
135  GU_PackedFactory *proc);
136 
137  // Conversion Methods
138  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
139  GA_PointGroup *usedpts = 0);
140  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
141 
142  virtual void normal(NormalComp &output) const;
143 
144  /// Return the implementation's packed detail. This might return a NULL
145  /// pointer.
146  /// This packed detail should be @b untransformed (i.e. the primitive's
147  /// transform shouldn't be included in this).
149  { return implementation()->getPackedDetail(); }
151  { return implementation()->getPackedDetail(&context); }
152  /// Unpack the packed geometry into the given detail. This method should
153  /// ensure that the unpacked geometry has the primitive's transform
154  /// applied.
155  bool unpack(GU_Detail &dest) const
156  { return implementation()->unpack(dest, this); }
157  bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
158  { return implementation()->unpackWithContext(dest, context, this); }
159  bool unpackUsingPolygons(GU_Detail &dest) const
160  { return implementation()->unpackUsingPolygons(dest, this); }
161 
162  /// Unpack the packed geometry as with the unpack function. In addition,
163  /// returns a STY_Styler for each unpacked primitive.
165  GU_Detail &dest,
166  STY_StylerGroup &prim_styler_group,
167  const STY_Styler &parent_styler) const
168  {
169  return implementation()->unpackWithStyler(
170  dest, prim_styler_group, parent_styler, this);
171  }
172 
173  void forceLoad() const
174  { return implementation()->forceLoad(); }
175 
176  bool isLoaded() const
177  { return implementation()->isLoaded(); }
178 
179  const GU_PackedImpl *implementation() const { return myImplementation; }
180  GU_PackedImpl *implementation() { return myImplementation; }
181 
182  /// The box cache can be used by the implementation to store the
183  /// untransformed bounding box. It should @b not store the transformed
184  /// box. The cache is automatically cleared when @c attributeDirty() or @c
185  /// topologyDirty() are called.
186  const UT_BoundingBox &boxCache() const { return myBoxCache; }
187  void setBoxCache(const UT_BoundingBox &b) { myBoxCache=b; }
188  void clearBoxCache() { myBoxCache.makeInvalid(); }
189 
190  /// @{
191  /// Implementation of dirty methods from GEO
192  virtual void transformDirty();
193  virtual void attributeDirty();
194  virtual void topologyDirty();
195  /// @}
196 
197  /// multiply xform by transform derived from pivot, local, P and instance
198  /// attributes
199  void multiplyByPrimTransform(UT_Matrix4D &xform) const;
200 protected:
202  bool doConvert(const GEO_ConvertParms &parms) const;
203 
204 private:
205  GU_PackedImpl *myImplementation;
206  mutable UT_BoundingBox myBoxCache;
207  mutable UT_Matrix4D myCachedFullTransform;
208  mutable int64 myCachedFullTransformCount;
210 };
212 
213 #endif
void forceLoad() const
GU_PackedImpl * implementation()
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
virtual bool getUntransformedRenderingBounds(UT_BoundingBox &box) const =0
bool isLoaded() const
virtual fpreal calcPerimeter() const =0
virtual bool getUntransformedBounds(UT_BoundingBox &box) const =0
virtual bool loadOptions(const UT_Options &options, const GA_LoadMap &map)=0
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual fpreal calcArea() const =0
void setBoxCache(const UT_BoundingBox &b)
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
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
3D Vector class.
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:201
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual void attributeDirty()
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
virtual void normal(NormalComp &output) const =0
bool unpackUsingPolygons(GU_Detail &dest) const
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual void transformDirty()
long long int64
Definition: SYS_Types.h:107
bool unpack(GU_Detail &dest) const
virtual fpreal calcVolume(const UT_Vector3 &refpt) const =0
virtual void countMemory(UT_MemoryCounter &counter) const
int64 exint
Definition: SYS_Types.h:116
virtual void getFullTransform4(UT_Matrix4D &matrix) const =0
virtual bool supportsJSONLoad() const =0
virtual void copyImplementation(const GEO_PrimPacked &src)=0
GLintptr offset
Definition: glcorearb.h:664
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:12
const UT_BoundingBox & boxCache() const
bool unpackWithContext(GU_Detail &dest, GU_PackedContext &context) const
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GLfloat v0
Definition: glcorearb.h:815
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:270
A map of string to various well defined value types.
Definition: UT_Options.h:42
virtual bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex *geometryIndex) const
virtual bool loadOptionsJSON(UT_JSONParser &p, const GA_LoadMap &map)=0
void clearBoxCache()
GLfloat GLfloat v1
Definition: glcorearb.h:816
const GU_PackedImpl * implementation() const
virtual bool loadUnknownToken(const char *token, UT_JSONParser &p, const GA_LoadMap &map)=0
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
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
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual void topologyDirty()
static bool isPackedPrimitive(const GA_Primitive &prim)
Definition: GU_PrimPacked.h:63
Definition of a geometric primitive.
virtual const GA_PrimitiveDefinition & getTypeDef() const =0
virtual bool saveOptions(UT_Options &options, const GA_SaveMap &map) const =0
virtual bool loadOptionsJSONMap(UT_JSONValueMap &options, const GA_LoadMap &map)=0
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
virtual bool registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item)
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
GLenum src
Definition: glcorearb.h:1792
bool unpackWithStyler(GU_Detail &dest, STY_StylerGroup &prim_styler_group, const STY_Styler &parent_styler) const