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  /// Clear any pending writes from the GPU.
60  virtual void flushCEWriteCaches() const;
61  /// Clear all GPU caches.
62  virtual void flushCECaches() const;
63 
64  void markCECacheStatus(bool status)
65  { myHasCECache = status; }
66 
67 
68 protected:
69  explicit SIM_Geometry(const SIM_DataFactory *factory);
70  ~SIM_Geometry() override;
71 
72  /// Set initial values on all the geometry attributes.
73  void initializeSubclass() override;
74  /// Makes this geometry equal to some other SIM_Geometry.
75  void makeEqualSubclass(const SIM_Data *source) override;
76  /// Saves our attributes, and our internal data if it has been set.
77  void saveSubclass(std::ostream &os) const override;
78  void saveIOSubclass(std::ostream &os,
79  SIM_DataThreadedIO *io) const override;
80  /// Loads our attributes and internal data if it was set when we saved.
81  bool loadSubclass(UT_IStream &is) override;
82  bool loadIOSubclass(UT_IStream &is,
83  SIM_DataThreadedIO *io) override;
84  /// Creates a query object specifically for geometry data to access
85  /// the transforms associated with geometry data.
86  SIM_Query *createQueryObjectSubclass() const override;
87  /// Create an interpolation between two other SIM_Geometry subclasses.
88  /// This is one place where the internal data gets used automatically.
89  /// Since the source data may be of any subclass, the only way to
90  /// safely and correctly interpolate between two SIM_Geometry subclasses
91  /// is to copy one of the source geometry and transform to our internal
92  /// data, and then do a blend towards the second source data.
93  void interpolateSubclass(const SIM_Data *source1,
94  const SIM_Data *source2,
95  fpreal interp) override;
96  int64 getMemorySizeSubclass() const override;
97 
98  /// This function is called by getGeometry() to return the actual
99  /// geometry data. The default implementation returns an empty geometry.
100  virtual GU_ConstDetailHandle getGeometrySubclass() const;
101  /// This function is called by getTransform() to return the actual
102  /// transform data. The default implementation returns an identity matrix.
103  virtual void getTransformSubclass(UT_DMatrix4 &xform) const;
104 
105 public:
106  /// Set our internal geometry data. If some internal data already exists,
107  /// it is deleted. The pointer passed in becomes controlled by the
108  /// SIM_Geometry so must not be deleted by external code. A null pointer
109  /// can be passed in to clear our internal geometry data.
110  void setOwnGeometry(GU_Detail *gdp);
111  /// Set our internal geometry data from an existing GU_DetailHandle.
112  /// If some internal data already exists, it is deleted.
113  void setOwnGeometry(const GU_DetailHandle &gdh);
114  virtual void setOwnGeometrySubclass(const GU_DetailHandle &gdh);
115  /// Returns a const pointer to our internal geometry data, if it is set.
116  GU_ConstDetailHandle getOwnGeometry() const;
117  /// Returns a pointer to our internal geometry data, if it is set.
118  GU_DetailHandle getOwnGeometry();
119  /// Makes our own geometry unique, breaking any internal sharing
120  /// it may have.
121  void makeOwnGeometryUnique();
122 
123  /// Set our internal transform data. If some internal data already exists,
124  /// it is deleted. The pointer passed in becomes controlled by the
125  /// SIM_Geometry so must not be deleted by external code. A null pointer
126  /// can be passed in to clear our internal transform data.
127  void setOwnTransform(UT_DMatrix4 *xform);
128  /// Returns a const pointer to our internal transform data, if it is set.
129  const UT_DMatrix4 *getOwnTransform() const;
130  /// Returns a pointer to our internal transform data, if it is set.
131  UT_DMatrix4 *getOwnTransform();
132 
133 private:
134  GU_DetailHandle myOwnGeometry;
135  UT_DMatrix4 *myOwnTransform;
136 
137 protected:
138  mutable bool myHasCECache;
139 
140 private:
143 };
144 
145 /// Utility class that handles creating a GU_DetailHandleAutoReadLock for the
146 /// (possibly NULL) SIM_Geometry.
148 {
149 public:
151  : myReadLock(simgeo ? simgeo->getGeometry() : GU_DetailHandle())
152  {
153  }
154 
155  const GU_Detail *getGdp() const { return myReadLock.getGdp(); }
156 
157 private:
158  GU_DetailHandleAutoReadLock myReadLock;
159 };
160 
161 #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:45
#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:71
virtual SIM_Query * createQueryObjectSubclass() const
GA_Precision
Definition: GA_Types.h:86
#define GETSET_DATA_FUNCS_S(DataName, FuncName)
virtual void saveIOSubclass(std::ostream &os, SIM_DataThreadedIO *io) const
virtual int64 getMemorySizeSubclass() const
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
GLuint interp
Definition: glew.h:8277
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
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:33
fpreal64 fpreal
Definition: SYS_Types.h:277
#define SIM_API
Definition: SIM_API.h:10
const GU_Detail * getGdp() const
Definition: SIM_Geometry.h:155
void markCECacheStatus(bool status)
Definition: SIM_Geometry.h:64
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
SIM_GeometryAutoReadLock(const SIM_Geometry *simgeo)
Definition: SIM_Geometry.h:150
virtual void initializeSubclass()