HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
38 namespace GABC_NAMESPACE
39 {
40 
42 {
43 public:
44  static void install(GA_PrimitiveFactory *fact);
45  static bool isInstalled();
47  {
48  return theTypeId;
49  }
50 
53  virtual ~GABC_PackedImpl();
54 
55  /// Note: The caller is responsible for setting the vertex/point for the
56  /// primitive.
57  /// In non-Alembic packed primitive code, you probably just want to call
58  /// GU_PrimPacked::build(gdp, "AlembicRef")
59  /// which handles the point creation automatically (see the packedsphere
60  /// HDK sample code).
61  static GU_PrimPacked *build(GU_Detail &gdp,
62  const UT_StringArray &filenames,
63  const GABC_IObject &obj,
64  fpreal frame,
65  bool useTransform,
66  bool useVisibility);
67 
68 
69  /// Get the factory associated with this procedural
70  virtual GU_PackedFactory *getFactory() const;
71 
72  /// Create a copy of this resolver
73  virtual GU_PackedImpl *copy() const;
74 
75  /// Report memory usage (includes all shared memory)
76  virtual int64 getMemoryUsage(bool inclusive) const;
77 
78  /// Count memory usage using a UT_MemoryCounter in order to count
79  /// shared memory correctly.
80  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
81 
82  /// Test whether the deferred load primitive data is valid
83  virtual bool isValid() const;
84 
85  /// Method to clear any data associated with the implementation. It's
86  /// possible that the implementation may need to re-construct the data, but
87  /// this should clear what it can.
88  virtual void clearData();
89 
90  /// Give a UT_Options of load data, create resolver data for the primitive
91  virtual bool load(GU_PrimPacked *prim, const UT_Options &options,
92  const GA_LoadMap &map)
93  { return loadFrom(prim, options, map); }
94  virtual bool supportsJSONLoad() const { return true; }
95  virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options,
96  const GA_LoadMap &map)
97  { return loadFrom(prim, options, map); }
98 
99  /// Depending on the update, the procedural should call one of:
100  /// - prim->transformDirty()
101  /// - prim->attributeDirty()
102  /// - prim->topologyDirty()
103  virtual void update(GU_PrimPacked *prim, const UT_Options &options);
104 
105  /// Copy the resolver data into the UT_Options for saving
106  virtual bool save(UT_Options &options,
107  const GA_SaveMap &map) const;
108 
109  /// Handle unknown token/value pairs when loading the primitive. By
110  /// default, this adds a warning and skips the next object. Return false
111  /// if there was a critical error.
112  virtual bool loadUnknownToken(const char *token, UT_JSONParser &p,
113  const GA_LoadMap &map);
114 
115  /// Get the bounding box for the geometry (not including transforms)
116  virtual bool getBounds(UT_BoundingBox &box) const;
117 
118  /// Get the rendering bounding box for the geometry (not including
119  /// transforms). For curve and point geometry, this needs to include any
120  /// "width" attributes.
121  virtual bool getRenderingBounds(UT_BoundingBox &box) const;
122 
123  /// When rendering with velocity blur, the renderer needs to know the
124  /// bounds on velocity to accurately compute the bounding box.
125  virtual void getVelocityRange(UT_Vector3 &min,
126  UT_Vector3 &max) const;
127  virtual void getWidthRange(fpreal &min, fpreal &max) const;
128 
129  /// Return the primitive's "description". This should be a unique
130  /// identifier for the primitive and defaults to:
131  /// <tt>"%s.%d" % (getFactory()->name(), prim->getMapIndex()) </tt>
132  virtual void getPrimitiveName(const GU_PrimPacked *prim, UT_WorkBuffer &wbuf) const;
133 
134  /// Some procedurals have an "intrinsic" transform. These are combined
135  /// with the local transform on the geometry primitive.
136  ///
137  /// The default method returns false and leaves the transform unchanged.
138  virtual bool getLocalTransform(UT_Matrix4D &m) const;
139 
140  /// Unpack the procedural into a GU_Detail. By default, this calls
141  /// getGTFull() and converts the GT geometry to a GU_Detail.
142  virtual bool unpack(GU_Detail &destgdp, const UT_Matrix4D *transform) const;
143 
144 protected:
145  /// Unpack the procedural into a GU_Detail. By default, this calls
146  /// getGTFull() and converts the GT geometry to a GU_Detail.
147  /// This signature is just for the questionable purpose of copying
148  /// primitive group membership from prim, so it might be removed
149  /// in the future.
150  virtual bool unpackWithPrim(
151  GU_Detail &destgdp,
152  const UT_Matrix4D *transform,
153  const GU_PrimPacked *prim) const;
154 public:
155 
156  /// Unpack without using polygon soups
157  virtual bool unpackUsingPolygons(GU_Detail &destgdp, const GU_PrimPacked *prim) const;
158 
159  /// Alembic packed primitives do have a faceset attribute, so set it.
160  virtual void setFacesetAttribute(const UT_StringHolder &s)
161  {
162  myFacesetAttribute = s;
163  }
164 
165  /// Alembic packed primitives do have a faceset attribute, so return it.
166  virtual const UT_StringHolder &facesetAttribute() const
167  { return myFacesetAttribute; }
168 
169  virtual void setAttributeNameMap(const GEO_PackedNameMapPtr &m);
170 
171  virtual const GEO_PackedNameMapPtr &attributeNameMap() const
172  {
173  if (mySharedNameMapData)
174  {
175  setupNameMap();
176  }
177  return myAttributeNameMap;
178  }
179 
180  /// This should only be called during load.
182  { mySharedNameMapData = std::move(s); }
183 
184  /// @{
185  /// Return GT representations of geometry
186  bool visibleGT(bool *is_animated = NULL) const;
187  GT_PrimitiveHandle fullGT(const GU_PrimPacked *packed, int load_style=GABC_IObject::GABC_LOAD_FULL) const;
188  GT_PrimitiveHandle pointGT(const GU_PrimPacked *packed) const;
189  GT_PrimitiveHandle boxGT(const GU_PrimPacked *packed) const;
190  GT_PrimitiveHandle centroidGT(const GU_PrimPacked *packed) const;
191  /// @}
192 
193  /// Get the geometry for "instancing". This geometry doesn't have the
194  /// transform to world space, nor does it have the Houdini attributes from
195  /// the primitive.
196  GT_PrimitiveHandle instanceGT(bool ignore_visibility = false) const;
197 
198  /// The xformGT will return the transform for the primitive, regardless of
199  /// whether the load_style for full geometry was set to force untransformed
200  /// geometry.
201  GT_TransformHandle xformGT(const GU_PrimPacked *packed) const;
202 
203  const GABC_IObject &object() const;
204  const UT_StringArray &filenames() const { return myFilenames; }
205  UT_StringHolder filenamesJSON() const;
207  {
208  if (myFilenames.size())
209  return myFilenames.last();
210  return "";
211  }
212  UT_StringHolder intrinsicFilenamesJSON(const GU_PrimPacked *prim) const;
213  const UT_StringHolder &objectPath() const { return myObjectPath; }
214  UT_StringHolder intrinsicObjectPath(const GU_PrimPacked *prim) const { return myObjectPath; }
216  { return object().getSourcePath(); }
218  { return object().getPointCount(myFrame); }
219  fpreal frame() const { return myFrame; }
220  fpreal intrinsicFrame(const GU_PrimPacked *prim) const { return myFrame; }
221  bool useTransform() const { return myUseTransform; }
222  bool intrinsicUseTransform(const GU_PrimPacked *prim) const { return myUseTransform; }
223  bool useVisibility() const { return myUseVisibility; }
224  bool intrinsicUseVisibility(const GU_PrimPacked *prim) const { return myUseVisibility; }
225  GABC_NodeType nodeType() const { return object().nodeType(); }
226  GEO_AnimationType animationType() const;
227  int currentLoadStyle() const { return myCache.loadStyle();}
228  bool isConstant() const
229  {
230  return animationType() == GEO_ANIMATION_CONSTANT;
231  }
232  const char *intrinsicAnimation(const GU_PrimPacked *prim) const
233  { return GEOanimationType(animationType()); }
234  const char *intrinsicNodeType(const GU_PrimPacked *prim) const
235  { return GABCnodeType(nodeType()); }
237  { return computeVisibility(false); }
239  { return computeVisibility(true); }
240 
242  { return getAttributeNames(GT_OWNER_POINT); }
244  { return getAttributeNames(GT_OWNER_VERTEX); }
246  { return getAttributeNames(GT_OWNER_PRIMITIVE); }
248  { return getAttributeNames(GT_OWNER_DETAIL); }
250  { return getFaceSetNames(); }
251 
252  /// Returns a sys_wang64 hash of the sum of 64B values making up the Alembic
253  /// property hash.
254  int64 getPropertiesHash() const;
255 
256  void setObject(const GABC_IObject &v);
257  void setFilename(GU_PrimPacked *prim, const UT_StringHolder &v);
258  void setFilenames(GU_PrimPacked *prim, const UT_StringArray &v);
259  void setFilenamesJSON(GU_PrimPacked *prim, const UT_StringHolder &v);
260  void setObjectPath(GU_PrimPacked *prim, const UT_StringHolder &v);
261  void setFrame(GU_PrimPacked *prim, fpreal f);
262  void setUseTransform(GU_PrimPacked *prim, bool v);
263  void setUseVisibility(GU_PrimPacked *prim, bool v);
264 
265 protected:
266 #if 0
267  /// Optional method to compute centroid (default uses bounding box)
268  virtual UT_Vector3 getBaryCenter() const;
269  /// Optional method to calculate volume (default uses bounding box)
270  virtual fpreal computeVolume(const UT_Vector3 &refpt) const;
271  /// Optional method to calculate surface area (default uses bounding box)
272  virtual fpreal computeArea() const;
273  /// Optional method to calculate perimeter (default uses bounding box)
274  virtual fpreal computePerimeter() const;
275 #endif
276 
277  /// Method to load from either UT_Options or UT_JSONValueMap
278  template <typename T>
279  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
280 
281  class GTCache
282  {
283  public:
285  : myAnimationType(GEO_ANIMATION_INVALID)
286  {
287  clear();
288  }
289  GTCache(const GTCache &)
290  : myAnimationType(GEO_ANIMATION_INVALID)
291  {
292  clear(); // Just clear
293  }
295  {
296  clear();
297  }
299  {
300  clear(); // Don't copy, just clear
301  return *this;
302  }
303 
304  int64 getMemoryUsage(bool inclusive) const;
305 
306  void clear(); // Clear all values
307  void updateFrame(fpreal frame);
308 
309  bool visible(const GABC_PackedImpl *abc,
310  bool *is_animated = NULL);
311  const GT_PrimitiveHandle &full(
312  const GA_Detail *detail,
313  const GA_Offset primoff,
314  const GABC_PackedImpl *abc,
315  int load_style);
316  const GT_PrimitiveHandle &points(const GABC_PackedImpl *abc);
317  const GT_PrimitiveHandle &box(const GABC_PackedImpl *abc);
318  const GT_PrimitiveHandle &centroid(const GABC_PackedImpl *abc);
319  GEO_AnimationType animationType(const GABC_PackedImpl *abc);
321  { return myAnimationType; }
322 
323  /// Return the current transform handle
325  {
326  refreshTransform(abc);
327  return myTransform;
328  }
329 
330  int loadStyle() const { return myLoadStyle; }
331 
332  private:
333  void refreshTransform(const GABC_PackedImpl *abc);
334  void updateTransform(const GABC_PackedImpl *abc);
335 
336  GT_PrimitiveHandle myPrim;
337  GT_TransformHandle myTransform;
338  GEO_AnimationType myAnimationType;
339  GEO_ViewportLOD myRep;
340  fpreal myFrame;
341  int myLoadStyle;
342  };
343 
344 private:
345  void markDirty(GU_PrimPacked *prim);
346 
347  GABC_VisibilityType computeVisibility(bool include_parent) const;
348 
349  UT_StringHolder getAttributeNames(GT_Owner owner) const;
350  UT_StringHolder getFaceSetNames() const;
351 
352  void clearGT();
353  bool unpackGeometry(
354  GU_Detail &destgdp,
355  const GU_Detail *srcgdp,
356  const GA_Offset srcprimoff,
357  const UT_Matrix4D *transform,
358  bool allow_psoup) const;
359 
360  void setupNameMap() const;
361 
362  UT_StringHolder myFacesetAttribute;
363  GEO_PackedNameMapPtr myAttributeNameMap;
364  GA_SharedDataHandlePtr mySharedNameMapData;
365  mutable UT_Lock myLock;
366  mutable GABC_IObject myObject;
367  mutable GTCache myCache;
368  mutable bool myCachedUniqueID;
369  mutable int64 myUniqueID;
370  UT_StringArray myFilenames;
371  UT_StringHolder myObjectPath;
372  fpreal myFrame;
373  bool myUseTransform;
374  bool myUseVisibility;
375 
376  mutable GABC_VisibilityType myConstVisibility;
377  mutable bool myHasConstBounds;
378  mutable UT_BoundingBox myConstBounds;
379 
380  static GA_PrimitiveTypeId theTypeId;
381 };
382 
383 }
384 
385 #endif
GLdouble s
Definition: glew.h:1390
UT_StringHolder intrinsicDetail(const GU_PrimPacked *prim) const
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
GABC_API const char * GABCnodeType(GABC_NodeType type)
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
UT_StringHolder intrinsicPoint(const GU_PrimPacked *prim) const
GLuint GLenum GLenum transform
Definition: glew.h:14742
GTCache & operator=(const GTCache &src)
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
GEO_API const char * GEOanimationType(GEO_AnimationType type)
const GLdouble * m
Definition: glew.h:9124
const GLdouble * v
Definition: glew.h:1391
GLhandleARB obj
Definition: glew.h:6236
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
UT_StringHolder intrinsicFaceSet(const GU_PrimPacked *prim) const
GEO_AnimationType animationType() const
#define GABC_NAMESPACE
Definition: GABC_API.h:42
bool intrinsicUseTransform(const GU_PrimPacked *prim) const
GA_Size GA_Offset
Definition: GA_Types.h:637
virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map)
long long int64
Definition: SYS_Types.h:111
int64 intrinsicPointCount(const GU_PrimPacked *prim) const
GLclampf f
Definition: glew.h:3499
virtual const UT_StringHolder & facesetAttribute() const
Alembic packed primitives do have a faceset attribute, so return it.
GEO_AnimationType
GLuint object
Definition: glew.h:8986
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:76
fpreal intrinsicFrame(const GU_PrimPacked *prim) const
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 void setFacesetAttribute(const UT_StringHolder &s)
Alembic packed primitives do have a faceset attribute, so set it.
const UT_StringArray & filenames() const
virtual const GEO_PackedNameMapPtr & attributeNameMap() const
GLuint counter
Definition: glew.h:2740
virtual bool supportsJSONLoad() const
GEO_ViewportLOD
GLuint GLenum GLsizei GLsizei GLboolean packed
Definition: glew.h:12722
UT_StringHolder intrinsicSourcePath(const GU_PrimPacked *prim) const
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3446
#define GABC_API
Definition: GABC_API.h:37
OIIO_API bool copy(string_view from, string_view to, std::string &err)
int64 intrinsicVisibility(const GU_PrimPacked *prim) const
static GA_PrimitiveTypeId typeId()
Container class for all geometry.
Definition: GA_Detail.h:95
const char * intrinsicNodeType(const GU_PrimPacked *prim) const
virtual void setSharedNameMapData(GA_SharedDataHandlePtr s)
This should only be called during load.
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
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.