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