HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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; }
78  void setString(const UT_StringHolder &s)
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:
89  InstanceKey(const SingleItemKey &k0, const SingleItemKey &k1, fpreal t)
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  virtual ~GU_PackedSequence();
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  virtual bool isValid() const;
154  virtual bool getBounds(UT_BoundingBox &box) const;
155  virtual bool getRenderingBounds(UT_BoundingBox &box) const;
156  virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max)const;
157  virtual void getWidthRange(fpreal &min, fpreal &max) const;
158  virtual bool unpack(GU_Detail &destgdp) const;
160  GU_PackedContext *c = nullptr
161  ) const;
162  /// @}
163 
164  /// @{
165  /// Member data accessors for intrinsics
166  fpreal index() const { return myIndex; }
168  {
169  TimeSample s;
170  bool valid = getTimeSample(s,myIndex);
171  return valid ? s.i0() : -1;
172  }
173  fpreal intrinsicIndex(const GU_PrimPacked *prim) const { return index(); }
174  UT_StringHolder wrapModeLabel() const;
176  { return wrapModeLabel(); }
177  WrapMode wrapMode() const { return myWrap; }
178  void setIndex(GU_PrimPacked *prim, fpreal f);
179  void setWrapMode(GU_PrimPacked *prim, WrapMode w);
180  void setWrapMode(GU_PrimPacked *prim, const UT_StringHolder &mode);
181  /// @}
182 
183 protected:
184  /// Get time sample. Returns false if the index is invalid.
185  /// The time sample will be initialized with the two indices for blending
186  /// as well as the blending amount.
187  bool getTimeSample(TimeSample &sample, fpreal t) const;
188  bool getTimeSample(TimeSample &sample) const
189  { return getTimeSample(sample, myIndex); }
190 
191  /// @{
192  /// Methods to get information about individual items in the sequence
193  /// Subclass method to query the bounding box for the given item
194  virtual bool sequenceBounds(exint index,
195  UT_BoundingBox &box) const = 0;
196  virtual void sequenceVelocityRange(exint index,
197  UT_Vector3 &min, UT_Vector3 &max) const = 0;
198  virtual void sequenceWidthRange(exint index,
199  fpreal &min, fpreal &max) const = 0;
200  /// @}
201 
202  /// Subclass method to get point geometry for the n'th item
203  virtual GU_ConstDetailHandle sequencePointCloud(exint index) const=0;
204 
205  /// Subclass to return the geometry for the n'th item
206  virtual GU_ConstDetailHandle sequenceGeometry(exint index) const = 0;
207 
208  // Store the index and wrap mode in the options
209  void storeData(UT_Options &options) const;
210 
211  /// @{
212  /// update index/wrap from the options (returns true if data changed)
213  bool updateData(GU_PrimPacked *prim, const UT_JSONValueMap &options);
214  bool updateData(GU_PrimPacked *prim, const UT_Options &options);
215  /// @}
216 
217 private:
218  fpreal myIndex;
219  WrapMode myWrap;
220 };
221 
222 #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
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
virtual bool getBounds(UT_BoundingBox &box) const =0
Get the bounding box for the geometry (not including transforms)
3D Vector class.
UT_StringHolder intrinsicWrapModeLabel(const GU_PrimPacked *prim) const
png_uint_32 i
Definition: png.h:2877
fpreal intrinsicIndex(const GU_PrimPacked *prim) const
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
fpreal index() const
GLfloat f
Definition: glcorearb.h:1925
int64 exint
Definition: SYS_Types.h:115
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:11
SingleItemKey(const UT_StringHolder &k)
WrapMode wrapMode() const
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
GLenum mode
Definition: glcorearb.h:98
GU_PackedSequence(const GU_PackedSequence &src)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
void set(const SingleItemKey &k0, const SingleItemKey &k1, fpreal t)
double fpreal
Definition: SYS_Types.h:269
A map of string to various well defined value types.
Definition: UT_Options.h:42
GLuint index
Definition: glcorearb.h:785
bool operator==(const InstanceKey &k) const
virtual bool unpack(GU_Detail &destgdp) const =0
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
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:1792
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0