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  ~GABC_PackedImpl() override;
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  GU_PackedFactory *getFactory() const override;
71 
72  /// Create a copy of this resolver
73  GU_PackedImpl *copy() const override;
74 
75  /// Report memory usage (includes all shared memory)
76  int64 getMemoryUsage(bool inclusive) const override;
77 
78  /// Count memory usage using a UT_MemoryCounter in order to count
79  /// shared memory correctly.
80  void countMemory(UT_MemoryCounter &counter,
81  bool inclusive) const override;
82 
83  /// Test whether the deferred load primitive data is valid
84  bool isValid() const override;
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  void clearData() override;
90 
91  /// Give a UT_Options of load data, create resolver data for the primitive
92  bool load(GU_PrimPacked *prim, const UT_Options &options,
93  const GA_LoadMap &map) override
94  { return loadFrom(prim, options, map); }
95  bool supportsJSONLoad() const override
96  { return true; }
98  const UT_JSONValueMap &options,
99  const GA_LoadMap &map) override
100  { return loadFrom(prim, options, map); }
101 
102  /// Depending on the update, the procedural should call one of:
103  /// - prim->transformDirty()
104  /// - prim->attributeDirty()
105  /// - prim->topologyDirty()
106  void update(GU_PrimPacked *prim,
107  const UT_Options &options) override;
108 
109  /// Copy the resolver data into the UT_Options for saving
110  bool save(UT_Options &options,
111  const GA_SaveMap &map) const override;
112 
113  /// Handle unknown token/value pairs when loading the primitive. By
114  /// default, this adds a warning and skips the next object. Return false
115  /// if there was a critical error.
116  bool loadUnknownToken(const char *token, UT_JSONParser &p,
117  const GA_LoadMap &map) override;
118 
119  /// Get the bounding box for the geometry (not including transforms)
120  bool getBounds(UT_BoundingBox &box) const override;
121 
122  /// Get the rendering bounding box for the geometry (not including
123  /// transforms). For curve and point geometry, this needs to include any
124  /// "width" attributes.
125  bool getRenderingBounds(UT_BoundingBox &box) const override;
126 
127  /// When rendering with velocity blur, the renderer needs to know the
128  /// bounds on velocity to accurately compute the bounding box.
129  void getVelocityRange(UT_Vector3 &min,
130  UT_Vector3 &max) const override;
131  void getWidthRange(fpreal &min, fpreal &max) const override;
132 
133  UT_Optional<exint> getNumPackedPrims(const GU_PrimPacked *prim) const;
134 
135  /// Return the primitive's "description". This should be a unique
136  /// identifier for the primitive and defaults to:
137  /// <tt>"%s.%d" % (getFactory()->name(), prim->getMapIndex()) </tt>
138  void getPrimitiveName(const GU_PrimPacked *prim,
139  UT_WorkBuffer &wbuf) const override;
140 
141  /// Some procedurals have an "intrinsic" transform. These are combined
142  /// with the local transform on the geometry primitive.
143  ///
144  /// The default method returns false and leaves the transform unchanged.
145  bool getLocalTransform(UT_Matrix4D &m) const override;
146 
147  /// Unpack the procedural into a GU_Detail. By default, this calls
148  /// getGTFull() and converts the GT geometry to a GU_Detail.
149  bool unpack(GU_Detail &destgdp,
150  const UT_Matrix4D *transform) const override;
151 
152 protected:
153  /// Unpack the procedural into a GU_Detail. By default, this calls
154  /// getGTFull() and converts the GT geometry to a GU_Detail.
155  /// This signature is just for the questionable purpose of copying
156  /// primitive group membership from prim, so it might be removed
157  /// in the future.
158  bool unpackWithPrim(
159  GU_Detail &destgdp,
160  const UT_Matrix4D *transform,
161  const GU_PrimPacked *prim) const override;
162 public:
163 
164  /// Unpack without using polygon soups
165  bool unpackUsingPolygons(GU_Detail &destgdp,
166  const GU_PrimPacked *prim) const override;
167 
168  /// Alembic packed primitives do have a faceset attribute, so set it.
169  void setFacesetAttribute(const UT_StringHolder &s) override
170  {
171  myFacesetAttribute = s;
172  }
173 
174  /// Alembic packed primitives do have a faceset attribute, so return it.
175  const UT_StringHolder &facesetAttribute() const override
176  { return myFacesetAttribute; }
177 
178  void setAttributeNameMap(const GEO_PackedNameMapPtr &m) override;
179 
180  const GEO_PackedNameMapPtr &attributeNameMap() const override
181  {
182  if (mySharedNameMapData)
183  {
184  setupNameMap();
185  }
186  return myAttributeNameMap;
187  }
188 
189  /// This should only be called during load.
191  { mySharedNameMapData = std::move(s); }
192 
193  /// @{
194  /// Return GT representations of geometry
195  bool visibleGT(bool *is_animated = NULL) const;
196  GT_PrimitiveHandle fullGT(const GU_PrimPacked *packed, int load_style=GABC_IObject::GABC_LOAD_FULL) const;
197  GT_PrimitiveHandle pointGT(const GU_PrimPacked *packed) const;
198  GT_PrimitiveHandle boxGT(const GU_PrimPacked *packed) const;
199  GT_PrimitiveHandle centroidGT(const GU_PrimPacked *packed) const;
200  /// @}
201 
202  /// Get the geometry for "instancing". This geometry doesn't have the
203  /// transform to world space, nor does it have the Houdini attributes from
204  /// the primitive.
205  GT_PrimitiveHandle instanceGT(bool ignore_visibility = false) const;
206 
207  /// The xformGT will return the transform for the primitive, regardless of
208  /// whether the load_style for full geometry was set to force untransformed
209  /// geometry.
210  GT_TransformHandle xformGT(const GU_PrimPacked *packed) const;
211 
212  const GABC_IObject &object() const;
213  const UT_StringArray &filenames() const { return myFilenames; }
214  UT_StringHolder filenamesJSON() const;
216  {
217  if (myFilenames.size())
218  return myFilenames.last();
219  return "";
220  }
221  UT_StringHolder intrinsicFilenamesJSON(const GU_PrimPacked *prim) const;
222  const UT_StringHolder &objectPath() const { return myObjectPath; }
223  UT_StringHolder intrinsicObjectPath(const GU_PrimPacked *prim) const { return myObjectPath; }
225  { return object().getSourcePath(); }
227  { return object().getPointCount(myFrame); }
228  fpreal frame() const { return myFrame; }
229  fpreal intrinsicFrame(const GU_PrimPacked *prim) const { return myFrame; }
230  bool useTransform() const { return myUseTransform; }
231  bool intrinsicUseTransform(const GU_PrimPacked *prim) const { return myUseTransform; }
232  bool useVisibility() const { return myUseVisibility; }
233  bool intrinsicUseVisibility(const GU_PrimPacked *prim) const { return myUseVisibility; }
234  GABC_NodeType nodeType() const { return object().nodeType(); }
235  GEO_AnimationType animationType() const;
236  int currentLoadStyle() const { return myCache.loadStyle();}
237  bool isConstant() const
238  {
239  return animationType() == GEO_ANIMATION_CONSTANT;
240  }
241  const char *intrinsicAnimation(const GU_PrimPacked *prim) const
242  { return GEOanimationType(animationType()); }
243  const char *intrinsicNodeType(const GU_PrimPacked *prim) const
244  { return GABCnodeType(nodeType()); }
246  { return computeVisibility(false); }
248  { return computeVisibility(true); }
249 
251  { return getAttributeNames(GT_OWNER_POINT); }
253  { return getAttributeNames(GT_OWNER_VERTEX); }
255  { return getAttributeNames(GT_OWNER_PRIMITIVE); }
257  { return getAttributeNames(GT_OWNER_DETAIL); }
259  { return getFaceSetNames(); }
260 
261  /// Returns a sys_wang64 hash of the sum of 64B values making up the Alembic
262  /// property hash.
263  int64 getPropertiesHash() const;
264 
265  void setObject(const GABC_IObject &v);
266  void setFilename(GU_PrimPacked *prim, const UT_StringHolder &v);
267  void setFilenames(GU_PrimPacked *prim, const UT_StringArray &v);
268  void setFilenamesJSON(GU_PrimPacked *prim, const UT_StringHolder &v);
269  void setObjectPath(GU_PrimPacked *prim, const UT_StringHolder &v);
270  void setFrame(GU_PrimPacked *prim, fpreal f);
271  void setUseTransform(GU_PrimPacked *prim, bool v);
272  void setUseVisibility(GU_PrimPacked *prim, bool v);
273 
274 protected:
275 #if 0
276  /// Optional method to compute centroid (default uses bounding box)
277  virtual UT_Vector3 getBaryCenter() const;
278  /// Optional method to calculate volume (default uses bounding box)
279  virtual fpreal computeVolume(const UT_Vector3 &refpt) const;
280  /// Optional method to calculate surface area (default uses bounding box)
281  virtual fpreal computeArea() const;
282  /// Optional method to calculate perimeter (default uses bounding box)
283  virtual fpreal computePerimeter() const;
284 #endif
285 
286  /// Method to load from either UT_Options or UT_JSONValueMap
287  template <typename T>
288  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
289 
290  class GTCache
291  {
292  public:
294  : myAnimationType(GEO_ANIMATION_INVALID)
295  {
296  clear();
297  }
298  GTCache(const GTCache &)
299  : myAnimationType(GEO_ANIMATION_INVALID)
300  {
301  clear(); // Just clear
302  }
304  {
305  clear();
306  }
308  {
309  clear(); // Don't copy, just clear
310  return *this;
311  }
312 
313  int64 getMemoryUsage(bool inclusive) const;
314 
315  void clear(); // Clear all values
316  void updateFrame(fpreal frame);
317 
318  bool visible(const GABC_PackedImpl *abc,
319  bool *is_animated = NULL);
320  const GT_PrimitiveHandle &full(
321  const GA_Detail *detail,
322  const GA_Offset primoff,
323  const GABC_PackedImpl *abc,
324  int load_style);
325  const GT_PrimitiveHandle &points(const GABC_PackedImpl *abc);
326  const GT_PrimitiveHandle &box(const GABC_PackedImpl *abc);
327  const GT_PrimitiveHandle &centroid(const GABC_PackedImpl *abc);
328  GEO_AnimationType animationType(const GABC_PackedImpl *abc);
330  { return myAnimationType; }
331 
332  /// Return the current transform handle
334  {
335  refreshTransform(abc);
336  return myTransform;
337  }
338 
339  int loadStyle() const { return myLoadStyle; }
340 
341  private:
342  void refreshTransform(const GABC_PackedImpl *abc);
343  void updateTransform(const GABC_PackedImpl *abc);
344 
345  GT_PrimitiveHandle myPrim;
346  GT_TransformHandle myTransform;
347  GEO_AnimationType myAnimationType;
348  GEO_ViewportLOD myRep;
349  fpreal myFrame;
350  int myLoadStyle;
351  };
352 
353 private:
354  void markDirty(GU_PrimPacked *prim);
355 
356  GABC_VisibilityType computeVisibility(bool include_parent) const;
357 
358  UT_StringHolder getAttributeNames(GT_Owner owner) const;
359  UT_StringHolder getFaceSetNames() const;
360 
361  void clearGT();
362  bool unpackGeometry(
363  GU_Detail &destgdp,
364  const GU_Detail *srcgdp,
365  const GA_Offset srcprimoff,
366  const UT_Matrix4D *transform,
367  bool allow_psoup) const;
368 
369  void setupNameMap() const;
370 
371  UT_StringHolder myFacesetAttribute;
372  GEO_PackedNameMapPtr myAttributeNameMap;
373  GA_SharedDataHandlePtr mySharedNameMapData;
374  mutable UT_Lock myLock;
375  mutable GABC_IObject myObject;
376  mutable GTCache myCache;
377  mutable bool myCachedUniqueID;
378  mutable int64 myUniqueID;
379  UT_StringArray myFilenames;
380  UT_StringHolder myObjectPath;
381  fpreal myFrame;
382  bool myUseTransform;
383  bool myUseVisibility;
384 
385  mutable GABC_VisibilityType myConstVisibility;
386  mutable bool myHasConstBounds;
387  mutable UT_BoundingBox myConstBounds;
388 
389  static GA_PrimitiveTypeId theTypeId;
390 };
391 
392 }
393 
394 #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.
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
UT_StringHolder intrinsicPoint(const GU_PrimPacked *prim) const
const UT_StringHolder & facesetAttribute() const override
Alembic packed primitives do have a faceset attribute, so return it.
const GLdouble * v
Definition: glcorearb.h:837
GLdouble s
Definition: glad.h:3009
GTCache & operator=(const GTCache &src)
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GEO_API const char * GEOanimationType(GEO_AnimationType type)
void setSharedNameMapData(GA_SharedDataHandlePtr s) override
This should only be called during load.
bool supportsJSONLoad() const override
bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map) override
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
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
const GEO_PackedNameMapPtr & attributeNameMap() const override
bool intrinsicUseTransform(const GU_PrimPacked *prim) const
GA_Size GA_Offset
Definition: GA_Types.h:653
int64 intrinsicPointCount(const GU_PrimPacked *prim) const
GLfloat f
Definition: glcorearb.h:1926
GEO_AnimationType
UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const
long long int64
Definition: SYS_Types.h:116
const char * intrinsicAnimation(const GU_PrimPacked *prim) const
Options during loading.
Definition: GA_LoadMap.h:42
GABC_NodeType nodeType() const
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_14 uint8_t packed(VULKAN_HPP_NAMESPACE::Format format)
int64 intrinsicFullVisibility(const GU_PrimPacked *prim) const
GA_API const UT_StringHolder transform
bool intrinsicUseVisibility(const GU_PrimPacked *prim) const
void setFacesetAttribute(const UT_StringHolder &s) override
Alembic packed primitives do have a faceset attribute, so set it.
GT_Owner
Definition: GT_Types.h:90
fpreal intrinsicFrame(const GU_PrimPacked *prim) const
A map of string to various well defined value types.
Definition: UT_Options.h:87
const UT_StringArray & filenames() const
GEO_ViewportLOD
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_StringHolder intrinsicSourcePath(const GU_PrimPacked *prim) const
#define GABC_API
Definition: GABC_API.h:37
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int64 intrinsicVisibility(const GU_PrimPacked *prim) const
static GA_PrimitiveTypeId typeId()
Container class for all geometry.
Definition: GA_Detail.h:105
const char * intrinsicNodeType(const GU_PrimPacked *prim) const
bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map) override
Give a UT_Options of load data, create resolver data for the primitive.
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:1793