HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GABC_PackedImpl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __GABC_PackedImpl__
29 #define __GABC_PackedImpl__
30 
31 #include "GABC_API.h"
32 #include "GABC_Util.h"
33 #include <GU/GU_PackedImpl.h>
34 #include <GT/GT_Primitive.h>
35 #include <UT/UT_Lock.h>
36 
37 class GT_AlembicCache;
38 
39 namespace GABC_NAMESPACE
40 {
41 
43 {
44 public:
45  static void install(GA_PrimitiveFactory *fact);
46  static bool isInstalled();
48  {
49  return theTypeId;
50  }
51 
54  virtual ~GABC_PackedImpl();
55 
56  /// Note: The caller is responsible for setting the vertex/point for the
57  /// primitive.
58  /// In non-Alembic packed primitive code, you probably just want to call
59  /// GU_PrimPacked::build(gdp, "AlembicRef")
60  /// which handles the point creation automatically (see the packedsphere
61  /// HDK sample code).
62  static GU_PrimPacked *build(GU_Detail &gdp,
63  const UT_StringHolder &filename,
64  const GABC_IObject &obj,
65  fpreal frame,
66  bool useTransform,
67  bool useVisibility);
68 
69 
70  /// Get the factory associated with this procedural
71  virtual GU_PackedFactory *getFactory() const;
72 
73  /// Create a copy of this resolver
74  virtual GU_PackedImpl *copy() const;
75 
76  /// Report memory usage (includes all shared memory)
77  virtual int64 getMemoryUsage(bool inclusive) const;
78 
79  /// Count memory usage using a UT_MemoryCounter in order to count
80  /// shared memory correctly.
81  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
82 
83  /// Test whether the deferred load primitive data is valid
84  virtual bool isValid() const;
85 
86  /// Method to clear any data associated with the implementation. It's
87  /// possible that the implementation may need to re-construct the data, but
88  /// this should clear what it can.
89  virtual void clearData();
90 
91  /// Give a UT_Options of load data, create resolver data for the primitive
92  virtual bool load(GU_PrimPacked *prim, const UT_Options &options,
93  const GA_LoadMap &map)
94  { return loadFrom(prim, options, map); }
95  virtual bool supportsJSONLoad() const { return true; }
96  virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options,
97  const GA_LoadMap &map)
98  { return loadFrom(prim, options, map); }
99 
100  /// Depending on the update, the procedural should call one of:
101  /// - prim->transformDirty()
102  /// - prim->attributeDirty()
103  /// - prim->topologyDirty()
104  virtual void update(GU_PrimPacked *prim, const UT_Options &options);
105 
106  /// Copy the resolver data into the UT_Options for saving
107  virtual bool save(UT_Options &options,
108  const GA_SaveMap &map) const;
109 
110  /// Handle unknown token/value pairs when loading the primitive. By
111  /// default, this adds a warning and skips the next object. Return false
112  /// if there was a critical error.
113  virtual bool loadUnknownToken(const char *token, UT_JSONParser &p,
114  const GA_LoadMap &map);
115 
116  /// Get the bounding box for the geometry (not including transforms)
117  virtual bool getBounds(UT_BoundingBox &box) const;
118 
119  /// Get the rendering bounding box for the geometry (not including
120  /// transforms). For curve and point geometry, this needs to include any
121  /// "width" attributes.
122  virtual bool getRenderingBounds(UT_BoundingBox &box) const;
123 
124  /// When rendering with velocity blur, the renderer needs to know the
125  /// bounds on velocity to accurately compute the bounding box.
126  virtual void getVelocityRange(UT_Vector3 &min,
127  UT_Vector3 &max) const;
128  virtual void getWidthRange(fpreal &min, fpreal &max) const;
129 
130  /// Return the primitive's "description". This should be a unique
131  /// identifier for the primitive and defaults to:
132  /// <tt>"%s.%d" % (getFactory()->name(), prim->getMapIndex()) </tt>
133  virtual void getPrimitiveName(const GU_PrimPacked *prim, UT_WorkBuffer &wbuf) const;
134 
135  /// Some procedurals have an "intrinsic" transform. These are combined
136  /// with the local transform on the geometry primitive.
137  ///
138  /// The default method returns false and leaves the transform unchanged.
139  virtual bool getLocalTransform(UT_Matrix4D &m) const;
140 
141  /// Unpack the procedural into a GU_Detail. By default, this calls
142  /// getGTFull() and converts the GT geometry to a GU_Detail.
143  virtual bool unpack(GU_Detail &destgdp) const;
144 
145  /// Unpack without using polygon soups
146  virtual bool unpackUsingPolygons(GU_Detail &destgdp) const;
147 
148  /// @{
149  /// Return GT representations of geometry
150  bool visibleGT(bool *is_animated = NULL) const;
151  GT_PrimitiveHandle fullGT(int load_style=GABC_IObject::GABC_LOAD_FULL) const;
152  GT_PrimitiveHandle pointGT() const;
153  GT_PrimitiveHandle boxGT() const;
154  GT_PrimitiveHandle centroidGT() const;
155  /// @}
156 
157  /// Get the geometry for "instancing". This geometry doesn't have the
158  /// transform to world space, nor does it have the Houdini attributes from
159  /// the primitive.
160  GT_PrimitiveHandle instanceGT(bool ignore_visibility = false) const;
161 
162  /// The xformGT will return the transform for the primitive, regardless of
163  /// whether the load_style for full geometry was set to force untransformed
164  /// geometry.
165  GT_TransformHandle xformGT() const;
166 
167  const GABC_IObject &object() const;
168  const UT_StringHolder &filename() const { return myFilename; }
169  UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const { return myFilename; }
170  const UT_StringHolder &objectPath() const { return myObjectPath; }
171  UT_StringHolder intrinsicObjectPath(const GU_PrimPacked *prim) const { return myObjectPath; }
173  { return object().getSourcePath(); }
175  { return object().getPointCount(myFrame); }
176  fpreal frame() const { return myFrame; }
177  fpreal intrinsicFrame(const GU_PrimPacked *prim) const { return myFrame; }
178  bool useTransform() const { return myUseTransform; }
179  bool intrinsicUseTransform(const GU_PrimPacked *prim) const { return myUseTransform; }
180  bool useVisibility() const { return myUseVisibility; }
181  bool intrinsicUseVisibility(const GU_PrimPacked *prim) const { return myUseVisibility; }
182  GABC_NodeType nodeType() const { return object().nodeType(); }
183  GEO_AnimationType animationType() const;
184  int currentLoadStyle() const { return myCache.loadStyle();}
185  bool isConstant() const
186  {
187  return animationType() == GEO_ANIMATION_CONSTANT;
188  }
189  const char *intrinsicAnimation(const GU_PrimPacked *prim) const
190  { return GEOanimationType(animationType()); }
191  const char *intrinsicNodeType(const GU_PrimPacked *prim) const
192  { return GABCnodeType(nodeType()); }
194  { return computeVisibility(false); }
196  { return computeVisibility(true); }
197 
199  { return getAttributeNames(GT_OWNER_POINT); }
201  { return getAttributeNames(GT_OWNER_VERTEX); }
203  { return getAttributeNames(GT_OWNER_PRIMITIVE); }
205  { return getAttributeNames(GT_OWNER_DETAIL); }
207  { return getFaceSetNames(); }
208 
209  /// Returns a sys_wang64 hash of the sum of 64B values making up the Alembic
210  /// property hash.
211  int64 getPropertiesHash() const;
212 
213  void setObject(const GABC_IObject &v);
214  void setFilename(GU_PrimPacked *prim, const UT_StringHolder &v);
215  void setObjectPath(GU_PrimPacked *prim, const UT_StringHolder &v);
216  void setFrame(GU_PrimPacked *prim, fpreal f);
217  void setUseTransform(GU_PrimPacked *prim, bool v);
218  void setUseVisibility(GU_PrimPacked *prim, bool v);
219 
220  void setViewportCache(GT_AlembicCache *cache) const;
221 protected:
222 #if 0
223  /// Optional method to compute centroid (default uses bounding box)
224  virtual UT_Vector3 getBaryCenter() const;
225  /// Optional method to calculate volume (default uses bounding box)
226  virtual fpreal computeVolume(const UT_Vector3 &refpt) const;
227  /// Optional method to calculate surface area (default uses bounding box)
228  virtual fpreal computeArea() const;
229  /// Optional method to calculate perimeter (default uses bounding box)
230  virtual fpreal computePerimeter() const;
231 #endif
232 
233  /// Method to load from either UT_Options or UT_JSONValueMap
234  template <typename T>
235  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
236 
237  class GTCache
238  {
239  public:
241  : myAnimationType(GEO_ANIMATION_INVALID)
242  {
243  clear();
244  }
245  GTCache(const GTCache &)
246  : myAnimationType(GEO_ANIMATION_INVALID)
247  {
248  clear(); // Just clear
249  }
251  {
252  clear();
253  }
255  {
256  clear(); // Don't copy, just clear
257  return *this;
258  }
259 
260  int64 getMemoryUsage(bool inclusive) const;
261 
262  void clear(); // Clear all values
263  void updateFrame(fpreal frame);
264 
265  bool visible(const GABC_PackedImpl *abc,
266  bool *is_animated = NULL);
267  const GT_PrimitiveHandle &full(const GABC_PackedImpl *abc,
268  int load_style);
269  const GT_PrimitiveHandle &points(const GABC_PackedImpl *abc);
270  const GT_PrimitiveHandle &box(const GABC_PackedImpl *abc);
271  const GT_PrimitiveHandle &centroid(const GABC_PackedImpl *abc);
272  GEO_AnimationType animationType(const GABC_PackedImpl *abc);
274  { return myAnimationType; }
275 
276  /// Return the current transform handle
278  {
279  refreshTransform(abc);
280  return myTransform;
281  }
282 
283  int loadStyle() const { return myLoadStyle; }
284 
285  private:
286  void refreshTransform(const GABC_PackedImpl *abc);
287  void updateTransform(const GABC_PackedImpl *abc);
288 
289  GT_PrimitiveHandle myPrim;
290  GT_TransformHandle myTransform;
291  GEO_AnimationType myAnimationType;
292  GEO_ViewportLOD myRep;
293  fpreal myFrame;
294  int myLoadStyle;
295  };
296 
297 private:
298  void markDirty(GU_PrimPacked *prim);
299 
300  GABC_VisibilityType computeVisibility(bool include_parent) const;
301 
302  UT_StringHolder getAttributeNames(GT_Owner owner) const;
303  UT_StringHolder getFaceSetNames() const;
304 
305  void clearGT();
306  bool unpackGeometry(GU_Detail &destgdp, bool allow_psoup) const;
307 
308  mutable UT_Lock myLock;
309  mutable GABC_IObject myObject;
310  mutable GTCache myCache;
311  mutable bool myCachedUniqueID;
312  mutable int64 myUniqueID;
313  UT_StringHolder myFilename;
314  UT_StringHolder myObjectPath;
315  fpreal myFrame;
316  bool myUseTransform;
317  bool myUseVisibility;
318 
319  mutable GABC_VisibilityType myConstVisibility;
320  mutable bool myHasConstBounds;
321  mutable UT_BoundingBox myConstBounds;
322  mutable GT_AlembicCache *myViewportCache;
323 
324  static GA_PrimitiveTypeId theTypeId;
325 };
326 
327 }
328 
329 #endif
UT_StringHolder intrinsicDetail(const GU_PrimPacked *prim) const
GABC_API const char * GABCnodeType(GABC_NodeType type)
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
UT_StringHolder intrinsicPoint(const GU_PrimPacked *prim) const
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
const UT_StringHolder & filename() const
const GLdouble * v
Definition: glcorearb.h:836
GTCache & operator=(const GTCache &src)
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
GEO_API const char * GEOanimationType(GEO_AnimationType type)
UT_StringHolder intrinsicFaceSet(const GU_PrimPacked *prim) const
GEO_AnimationType animationType() const
#define GABC_NAMESPACE
Definition: GABC_API.h:42
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
bool intrinsicUseTransform(const GU_PrimPacked *prim) const
virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map)
long long int64
Definition: SYS_Types.h:106
int64 intrinsicPointCount(const GU_PrimPacked *prim) const
GLfloat f
Definition: glcorearb.h:1925
GEO_AnimationType
UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const
const char * intrinsicAnimation(const GU_PrimPacked *prim) const
Options during loading.
Definition: GA_LoadMap.h:42
GABC_NodeType nodeType() const
virtual bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map)
Give a UT_Options of load data, create resolver data for the primitive.
int64 intrinsicFullVisibility(const GU_PrimPacked *prim) const
bool intrinsicUseVisibility(const GU_PrimPacked *prim) const
GT_Owner
Definition: GT_Types.h:72
fpreal intrinsicFrame(const GU_PrimPacked *prim) const
double fpreal
Definition: SYS_Types.h:269
A map of string to various well defined value types.
Definition: UT_Options.h:42
virtual bool supportsJSONLoad() const
GEO_ViewportLOD
UT_StringHolder intrinsicSourcePath(const GU_PrimPacked *prim) const
#define GABC_API
Definition: GABC_API.h:37
int64 intrinsicVisibility(const GU_PrimPacked *prim) const
static GA_PrimitiveTypeId typeId()
const char * intrinsicNodeType(const GU_PrimPacked *prim) const
UT_StringHolder intrinsicPrimitive(const GU_PrimPacked *prim) const
UT_StringHolder intrinsicObjectPath(const GU_PrimPacked *prim) const
UT_StringHolder intrinsicVertex(const GU_PrimPacked *prim) const
const UT_StringHolder & objectPath() const
const GT_TransformHandle & xform(const GABC_PackedImpl *abc)
Return the current transform handle.
GLenum src
Definition: glcorearb.h:1792