HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Geometry.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  */
7 
8 #ifndef __SIM_Geometry_h__
9 #define __SIM_Geometry_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_DataUtils.h"
13 #include "SIM_OptionsUser.h"
14 
15 #include <GA/GA_CEAttribute.h>
16 #include <GU/GU_DetailHandle.h>
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_VectorTypes.h>
20 
21 class UT_IStream;
22 
23 /// This is the definitions for the SIM_Geometry interface. It also
24 /// provides a default implementation that returns an empty geometry and
25 /// an identity transform. It also has the facility to hold its own
26 /// geometry and transform as internal data. If set, these are saved and
27 /// loaded automatically. But there is no way for anyone except subclasses
28 /// to set these internal data. Thus they are really just a convenience
29 /// when writing SIM_Geometry subclasses.
30 class SIM_API SIM_Geometry : public SIM_Data,
31  public SIM_OptionsUser
32 {
33 public:
34  /// Accesses the relative path to the position data associated with
35  /// this geometry.
37 
38  /// Method for accessing the geometry. If we have some internal
39  /// geometry data, we return that. Otherwise this function calls
40  /// getGeometrySubclass().
41  GU_ConstDetailHandle getGeometry() const;
42 
43  /// Get the geometry transform. If we have some internal transform
44  /// data, we return that. Otherwise this function calls
45  /// getTransformSubclass().
46  void getTransform(UT_DMatrix4 &xform) const;
47 
48  /// Attempt to build a GPU-backed attribute from our geometry.
49  /// Returns 0 on failure.
50  /// You do not own the resulting GA_CEAttribute.
51  GA_CEAttribute *getReadableCEAttribute(GA_AttributeOwner owner, const UT_StringRef &aname, GA_StorageClass storage, int &tuplesize, bool isarray, bool docopy) const { return getReadableCEAttributePrec(owner, aname, storage, GA_PRECISION_32, tuplesize, isarray, docopy); }
52  virtual GA_CEAttribute *getReadableCEAttributePrec(GA_AttributeOwner owner, const UT_StringRef &aname, GA_StorageClass storage, GA_Precision prec, int &tuplesize, bool isarray, bool docopy) const;
53 
54  /// Acquires our geometry without triggering any write backs
55  /// of pending CE operations, this is useful if you care only
56  /// about meta data.
57  GU_ConstDetailHandle getGeometryWithoutCEFlush() const;
58 
59  /// Convenience methods to query the geometry without inducing
60  /// a flush.
61  GA_Size getNumPoints() const;
62  GA_Size getNumPrimitives() const;
63 
64  /// Clear any pending writes from the GPU.
65  virtual void flushCEWriteCaches() const;
66  /// Clear all GPU caches.
67  virtual void flushCECaches() const;
68 
69  /// Should only be used externally to flag if the geometry has
70  /// CE buffers in it. So if you acquire read or write buffers
71  /// you need to flag it so they are copied/flushed properly.
72  void markCECacheStatus(bool status) const
73  { myHasCECache = status; }
74 
75 
76 protected:
77  explicit SIM_Geometry(const SIM_DataFactory *factory);
78  ~SIM_Geometry() override;
79 
80  /// Set initial values on all the geometry attributes.
81  void initializeSubclass() override;
82  /// Makes this geometry equal to some other SIM_Geometry.
83  void makeEqualSubclass(const SIM_Data *source) override;
84  /// Saves our attributes, and our internal data if it has been set.
85  void saveSubclass(std::ostream &os) const override;
86  void saveIOSubclass(std::ostream &os,
87  SIM_DataThreadedIO *io) const override;
88  /// Loads our attributes and internal data if it was set when we saved.
89  bool loadSubclass(UT_IStream &is) override;
90  bool loadIOSubclass(UT_IStream &is,
91  SIM_DataThreadedIO *io) override;
92  /// Creates a query object specifically for geometry data to access
93  /// the transforms associated with geometry data.
94  SIM_Query *createQueryObjectSubclass() const override;
95  /// Create an interpolation between two other SIM_Geometry subclasses.
96  /// This is one place where the internal data gets used automatically.
97  /// Since the source data may be of any subclass, the only way to
98  /// safely and correctly interpolate between two SIM_Geometry subclasses
99  /// is to copy one of the source geometry and transform to our internal
100  /// data, and then do a blend towards the second source data.
101  void interpolateSubclass(const SIM_Data *source1,
102  const SIM_Data *source2,
103  fpreal interp) override;
104  int64 getMemorySizeSubclass() const override;
105 
106  /// This function is called by getGeometry() to return the actual
107  /// geometry data. The default implementation returns an empty geometry.
108  virtual GU_ConstDetailHandle getGeometrySubclass() const;
109  /// This function is called by getTransform() to return the actual
110  /// transform data. The default implementation returns an identity matrix.
111  virtual void getTransformSubclass(UT_DMatrix4 &xform) const;
112 
113 public:
114  /// Set our internal geometry data. If some internal data already exists,
115  /// it is deleted. The pointer passed in becomes controlled by the
116  /// SIM_Geometry so must not be deleted by external code. A null pointer
117  /// can be passed in to clear our internal geometry data.
118  void setOwnGeometry(GU_Detail *gdp);
119  /// Set our internal geometry data from an existing GU_DetailHandle.
120  /// If some internal data already exists, it is deleted.
121  void setOwnGeometry(const GU_DetailHandle &gdh);
122  virtual void setOwnGeometrySubclass(const GU_DetailHandle &gdh);
123  /// Returns a const pointer to our internal geometry data, if it is set.
124  GU_ConstDetailHandle getOwnGeometry() const;
125  /// Returns a pointer to our internal geometry data, if it is set.
126  GU_DetailHandle getOwnGeometry();
127  /// Makes our own geometry unique, breaking any internal sharing
128  /// it may have.
129  void makeOwnGeometryUnique();
130 
131  /// Set our internal transform data. If some internal data already exists,
132  /// it is deleted. The pointer passed in becomes controlled by the
133  /// SIM_Geometry so must not be deleted by external code. A null pointer
134  /// can be passed in to clear our internal transform data.
135  void setOwnTransform(UT_DMatrix4 *xform);
136  /// Returns a const pointer to our internal transform data, if it is set.
137  const UT_DMatrix4 *getOwnTransform() const;
138  /// Returns a pointer to our internal transform data, if it is set.
139  UT_DMatrix4 *getOwnTransform();
140 
141 private:
142  GU_DetailHandle myOwnGeometry;
143  UT_DMatrix4 *myOwnTransform;
144 
145 protected:
146  mutable bool myHasCECache;
147 
148 private:
151 };
152 
153 /// Utility class that handles creating a GU_DetailHandleAutoReadLock for the
154 /// (possibly NULL) SIM_Geometry.
156 {
157 public:
159  : myReadLock(simgeo ? simgeo->getGeometry() : GU_DetailHandle())
160  {
161  }
162 
163  const GU_Detail *getGdp() const { return myReadLock.getGdp(); }
164 
165 private:
166  GU_DetailHandleAutoReadLock myReadLock;
167 };
168 
169 #endif
#define SIM_NAME_POSITIONPATH
Definition: SIM_Names.h:169
virtual void makeEqualSubclass(const SIM_Data *source)
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
virtual bool loadSubclass(UT_IStream &is)
virtual bool loadIOSubclass(UT_IStream &is, SIM_DataThreadedIO *io)
GA_StorageClass
Definition: GA_Types.h:72
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
virtual SIM_Query * createQueryObjectSubclass() const
GA_Precision
Definition: GA_Types.h:87
#define GETSET_DATA_FUNCS_S(DataName, FuncName)
virtual void saveIOSubclass(std::ostream &os, SIM_DataThreadedIO *io) const
virtual int64 getMemorySizeSubclass() const
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
GA_CEAttribute * getReadableCEAttribute(GA_AttributeOwner owner, const UT_StringRef &aname, GA_StorageClass storage, int &tuplesize, bool isarray, bool docopy) const
Definition: SIM_Geometry.h:51
void markCECacheStatus(bool status) const
Definition: SIM_Geometry.h:72
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
virtual void saveSubclass(std::ostream &os) const
long long int64
Definition: SYS_Types.h:116
virtual void interpolateSubclass(const SIM_Data *source1, const SIM_Data *source2, fpreal interp)
GA_AttributeOwner
Definition: GA_Types.h:34
fpreal64 fpreal
Definition: SYS_Types.h:277
#define SIM_API
Definition: SIM_API.h:12
const GU_Detail * getGdp() const
Definition: SIM_Geometry.h:163
SIM_GeometryAutoReadLock(const SIM_Geometry *simgeo)
Definition: SIM_Geometry.h:158
virtual void initializeSubclass()