HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PackedSequence.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_PackedSequence.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PackedSequence__
12 #define __GU_PackedSequence__
13 
14 #include "GU_PackedImpl.h"
15 #include <UT/UT_StringHolder.h>
16 #include <UT/UT_StringArray.h>
17 
19 class UT_MemoryCounter;
20 
21 /// The base class for a sequence of packed geometry.
23 {
24 public:
25  enum WrapMode
26  {
27  WRAP_CYCLE, // Cycle through disks
28  WRAP_CLAMP, // Clamp to range
29  WRAP_STRICT, // Strict range (no geometry outside range)
30  WRAP_MIRROR, // Bounce back and forth
31  };
32 
33  class TimeSample
34  {
35  public:
36  exint conditionalIndex() const { return myT < .5 ? myI0 : myI1; }
38  {
39  myI0 = myI1 = i;
40  myT = 0;
41  }
42 
43  // Quantize time into @c nstep individual slices
44  static fpreal quantize(fpreal time, exint nsteps);
45 
46  exint i0() const { return myI0; }
47  exint i1() const { return myI1; }
48  // Fractional time
49  fpreal t() const { return myT; }
50  // Quantized time sample
51  fpreal qt(exint nsteps) const { return myI0 + quantize(myT, nsteps); }
52 
53 
54  exint myI0; // First sample index
55  exint myI1; // Index of second sample
56  fpreal myT; // Blending factor
57  };
58 
59  // When generating shared instance keys for blended geometry, an
60  // SingleItemKey is used to uniquely identify key geometry. For example,
61  // for a disk sequence, the string value could be the filename for the
62  // file.
63  // Currently, this stores a string, but may be extended in the future.
65  {
66  public:
68  {
69  }
71  : myString(k)
72  {
73  }
74  bool operator==(const SingleItemKey &k) const
75  { return myString== k.myString; }
76  SYS_HashType hash() const { return myString.hash(); }
77  const UT_StringHolder &string() const { return myString; }
79  { myString= s; }
80  private:
81  UT_StringHolder myString;
82  };
83  /// Class to store keys for a blend key. If two separate primitives
84  /// generate identical keys, it's assumed they are equivalent.
86  {
87  public:
90  {
91  set(k0, k1, t);
92  }
93  const SingleItemKey &key0() const { return myKey[0]; }
94  const SingleItemKey &key1() const { return myKey[1]; }
95  void set(const SingleItemKey &k0, const SingleItemKey &k1, fpreal t)
96  {
97  myKey[0] = k0;
98  myKey[1] = k1;
99  myT = t;
100  }
101  void setKey0(const SingleItemKey &k) { myKey[0] = k; }
102  void setKey1(const SingleItemKey &k) { myKey[1] = k; }
103  fpreal t() const { return myT; }
104  void setT(fpreal t) { myT = t; }
105 
107  {
108  SYS_HashType h = myKey[0].hash();
109  SYShashCombine(h, myKey[1].hash());
110  SYShashCombine(h, myT);
111  return h;
112  }
113  bool operator==(const InstanceKey &k) const
114  {
115  return myT == k.myT
116  && myKey[0] == k.myKey[0]
117  && myKey[1] == k.myKey[1];
118  }
119  private:
120  SingleItemKey myKey[2];
121  fpreal myT;
122  };
123 
126  : GU_PackedImpl(src)
127  , myIndex(src.myIndex)
128  , myWrap(src.myWrap)
129  {
130  }
131  ~GU_PackedSequence() override;
132 
133  /// Subclass returns the number of pieces of geometry in the sequence
134  virtual exint sequenceSize() const = 0;
135 
137  { return sequenceSize(); }
138 
139  /// Get a detail handle representing the interpolated sub-frame geometry.
140  GU_ConstDetailHandle getBlendedDetail(fpreal t) const;
141 
142  /// Method to get an identifying key for the item. This is used to create
143  /// shared instances where possible. By default, the key will be a unique
144  /// string.
145  virtual InstanceKey getInstanceKey(exint quantize_steps) const;
146 
147  /// Make a unique instance key for this primitive. This can be used to
148  /// prevent any possible sharing of
149  InstanceKey getUniqueInstanceKey(exint quantize_steps) const;
150 
151  /// @{
152  /// Implementation of API on GU_PackedImpl
153  bool isValid() const override;
154  bool getBounds(UT_BoundingBox &box) const override;
155  bool getRenderingBounds(UT_BoundingBox &box) const override;
157  UT_Vector3 &max) const override;
158  void getWidthRange(fpreal &min,
159  fpreal &max) const override;
160  bool unpack(GU_Detail &destgdp,
161  const UT_Matrix4D *transform) const override;
163  GU_PackedContext *c = nullptr
164  ) const override;
165  /// @}
166 
167  /// @{
168  /// Member data accessors for intrinsics
169  fpreal index() const { return myIndex; }
171  {
172  TimeSample s;
173  bool valid = getTimeSample(s,myIndex);
174  return valid ? s.i0() : -1;
175  }
176  fpreal intrinsicIndex(const GU_PrimPacked *prim) const { return index(); }
177  UT_StringHolder wrapModeLabel() const;
179  { return wrapModeLabel(); }
180  WrapMode wrapMode() const { return myWrap; }
181  void setIndex(GU_PrimPacked *prim, fpreal f);
182  void setWrapMode(GU_PrimPacked *prim, WrapMode w);
183  void setWrapMode(GU_PrimPacked *prim, const UT_StringHolder &mode);
184  /// @}
185 
186 protected:
187  /// Get time sample. Returns false if the index is invalid.
188  /// The time sample will be initialized with the two indices for blending
189  /// as well as the blending amount.
190  bool getTimeSample(TimeSample &sample, fpreal t) const;
191  bool getTimeSample(TimeSample &sample) const
192  { return getTimeSample(sample, myIndex); }
193 
194  /// @{
195  /// Methods to get information about individual items in the sequence
196  /// Subclass method to query the bounding box for the given item
197  virtual bool sequenceBounds(exint index,
198  UT_BoundingBox &box) const = 0;
199  virtual bool sequenceVisibleBounds(exint index,
200  UT_BoundingBox &box) const = 0;
201  virtual void sequenceVelocityRange(exint index,
202  UT_Vector3 &min, UT_Vector3 &max) const = 0;
203  virtual void sequenceWidthRange(exint index,
204  fpreal &min, fpreal &max) const = 0;
205  /// @}
206 
207  /// Subclass method to get point geometry for the n'th item
208  virtual GU_ConstDetailHandle sequencePointCloud(exint index) const=0;
209 
210  /// Subclass to return the geometry for the n'th item
211  virtual GU_ConstDetailHandle sequenceGeometry(exint index) const = 0;
212 
213  // Store the index and wrap mode in the options
214  void storeData(UT_Options &options) const;
215 
216  /// @{
217  /// update index/wrap from the options (returns true if data changed)
218  bool updateData(GU_PrimPacked *prim, const UT_JSONValueMap &options);
219  bool updateData(GU_PrimPacked *prim, const UT_Options &options);
220  /// @}
221 
222 private:
223  fpreal myIndex;
224  WrapMode myWrap;
225 };
226 
227 #endif
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const =0
The base class for a sequence of packed geometry.
const SingleItemKey & key0() const
exint wrappedIndex() const
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
void setKey1(const SingleItemKey &k)
exint intrinsicSequenceSize(const GU_PrimPacked *prim) const
GT_API const UT_StringHolder time
int64 exint
Definition: SYS_Types.h:125
GLdouble s
Definition: glad.h:3009
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
virtual bool getBounds(UT_BoundingBox &box) const =0
Get the bounding box for the geometry (not including transforms)
UT_StringHolder intrinsicWrapModeLabel(const GU_PrimPacked *prim) const
fpreal intrinsicIndex(const GU_PrimPacked *prim) const
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
fpreal index() const
GLfloat f
Definition: glcorearb.h:1926
bool operator==(const SingleItemKey &k) const
fpreal qt(exint nsteps) const
virtual GU_ConstDetailHandle getPackedDetail(GU_PackedContext *context=0) const
void setString(const UT_StringHolder &s)
const UT_StringHolder & string() const
#define GU_API
Definition: GU_API.h:14
SingleItemKey(const UT_StringHolder &k)
GA_API const UT_StringHolder transform
WrapMode wrapMode() const
GLdouble t
Definition: glad.h:2397
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
GLenum mode
Definition: glcorearb.h:99
GU_PackedSequence(const GU_PackedSequence &src)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
void set(const SingleItemKey &k0, const SingleItemKey &k1, fpreal t)
A map of string to various well defined value types.
Definition: UT_Options.h:84
fpreal64 fpreal
Definition: SYS_Types.h:277
bool unpack(GU_Detail &destgdp, const GU_PrimPacked *prim) const
GLuint index
Definition: glcorearb.h:786
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool operator==(const InstanceKey &k) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
InstanceKey(const SingleItemKey &k0, const SingleItemKey &k1, fpreal t)
const SingleItemKey & key1() const
void setKey0(const SingleItemKey &k)
bool getTimeSample(TimeSample &sample) const
GLenum src
Definition: glcorearb.h:1793
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0