HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <GA/GA_CEAttribute.h>
13 #include <GU/GU_DetailHandle.h>
14 #include <UT/UT_VectorTypes.h>
15 #include <UT/UT_Array.h>
16 #include "SIM_OptionsUser.h"
17 #include "SIM_DataUtils.h"
18 
19 class UT_IStream;
20 
21 /// This is the definitions for the SIM_Geometry interface. It also
22 /// provides a default implementation that returns an empty geometry and
23 /// an identity transform. It also has the facility to hold its own
24 /// geometry and transform as internal data. If set, these are saved and
25 /// loaded automatically. But there is no way for anyone except subclasses
26 /// to set these internal data. Thus they are really just a convenience
27 /// when writing SIM_Geometry subclasses.
28 class SIM_API SIM_Geometry : public SIM_Data,
29  public SIM_OptionsUser
30 {
31 public:
32  /// Accesses the relative path to the position data associated with
33  /// this geometry.
35 
36  /// Method for accessing the geometry. If we have some internal
37  /// geometry data, we return that. Otherwise this function calls
38  /// getGeometrySubclass().
39  GU_ConstDetailHandle getGeometry() const;
40 
41  /// Get the geometry transform. If we have some internal transform
42  /// data, we return that. Otherwise this function calls
43  /// getTransformSubclass().
44  void getTransform(UT_DMatrix4 &xform) const;
45 
46  /// Attempt to build a GPU-backed attribute from our geometry.
47  /// Returns 0 on failure.
48  /// You do not own the resulting GA_CEAttribute.
49  virtual GA_CEAttribute *getReadableCEAttribute(GA_AttributeOwner owner, const UT_StringRef &aname, GA_StorageClass storage, int &tuplesize, bool isarray, bool docopy) const;
50 
51  /// Acquires our geometry without triggering any write backs
52  /// of pending CE operations, this is useful if you care only
53  /// about meta data.
54  GU_ConstDetailHandle getGeometryWithoutCEFlush() const;
55 
56  /// Clear any pending writes from the GPU.
57  virtual void flushCEWriteCaches() const;
58  /// Clear all GPU caches.
59  virtual void flushCECaches() const;
60 
61 protected:
62  explicit SIM_Geometry(const SIM_DataFactory *factory);
63  virtual ~SIM_Geometry();
64 
65  /// Set initial values on all the geometry attributes.
66  virtual void initializeSubclass();
67  /// Makes this geometry equal to some other SIM_Geometry.
68  virtual void makeEqualSubclass(const SIM_Data *source);
69  /// Saves our attributes, and our internal data if it has been set.
70  virtual void saveSubclass(std::ostream &os) const;
71  virtual void saveIOSubclass(std::ostream &os, SIM_DataThreadedIO *io) const;
72  /// Loads our attributes and internal data if it was set when we saved.
73  virtual bool loadSubclass(UT_IStream &is);
74  virtual bool loadIOSubclass(UT_IStream &is, SIM_DataThreadedIO *io);
75  /// Creates a query object specifically for geometry data to access
76  /// the transforms associated with geometry data.
77  virtual SIM_Query *createQueryObjectSubclass() const;
78  /// Create an interpolation between two other SIM_Geometry subclasses.
79  /// This is one place where the internal data gets used automatically.
80  /// Since the source data may be of any subclass, the only way to
81  /// safely and correctly interpolate between two SIM_Geometry subclasses
82  /// is to copy one of the source geometry and transform to our internal
83  /// data, and then do a blend towards the second source data.
84  virtual void interpolateSubclass(const SIM_Data *source1,
85  const SIM_Data *source2,
86  fpreal interp);
87  virtual int64 getMemorySizeSubclass() const;
88 
89  /// This function is called by getGeometry() to return the actual
90  /// geometry data. The default implementation returns an empty geometry.
91  virtual GU_ConstDetailHandle getGeometrySubclass() const;
92  /// This function is called by getTransform() to return the actual
93  /// transform data. The default implementation returns an identity matrix.
94  virtual void getTransformSubclass(UT_DMatrix4 &xform) const;
95 
96 public:
97  /// Set our internal geometry data. If some internal data already exists,
98  /// it is deleted. The pointer passed in becomes controlled by the
99  /// SIM_Geometry so must not be deleted by external code. A null pointer
100  /// can be passed in to clear our internal geometry data.
101  void setOwnGeometry(GU_Detail *gdp);
102  /// Set our internal geometry data from an existing GU_DetailHandle.
103  /// If some internal data already exists, it is deleted.
104  void setOwnGeometry(const GU_DetailHandle &gdh);
105  virtual void setOwnGeometrySubclass(const GU_DetailHandle &gdh);
106  /// Returns a const pointer to our internal geometry data, if it is set.
107  GU_ConstDetailHandle getOwnGeometry() const;
108  /// Returns a pointer to our internal geometry data, if it is set.
109  GU_DetailHandle getOwnGeometry();
110 
111  /// Set our internal transform 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 transform data.
115  void setOwnTransform(UT_DMatrix4 *xform);
116  /// Returns a const pointer to our internal transform data, if it is set.
117  const UT_DMatrix4 *getOwnTransform() const;
118  /// Returns a pointer to our internal transform data, if it is set.
119  UT_DMatrix4 *getOwnTransform();
120 
121 private:
122  GU_DetailHandle myOwnGeometry;
123  UT_DMatrix4 *myOwnTransform;
124 
125 protected:
127  {
128  public:
133  bool myIsArray;
134 
135  bool myLoaded;
136  bool myDirty;
137 
139  };
140 
141  CECacheEntry *findOrCreateCECacheEntry(GA_AttributeOwner owner, const UT_StringRef &name, GA_StorageClass storage, int &tuplesize, bool isarray, bool docopy) const;
142 
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:168
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)
UT_Array< CECacheEntry > myCECache
Definition: SIM_Geometry.h:143
bool myLoaded
Definition: SIM_Geometry.h:135
virtual bool loadIOSubclass(UT_IStream &is, SIM_DataThreadedIO *io)
GA_StorageClass
Definition: GA_Types.h:68
virtual SIM_Query * createQueryObjectSubclass() const
#define GETSET_DATA_FUNCS_S(DataName, FuncName)
virtual void saveIOSubclass(std::ostream &os, SIM_DataThreadedIO *io) const
virtual int64 getMemorySizeSubclass() const
bool myDirty
Definition: SIM_Geometry.h:136
GA_CEAttribute * myCEAttribute
Definition: SIM_Geometry.h:138
GA_AttributeOwner myOwner
Definition: SIM_Geometry.h:129
long long int64
Definition: SYS_Types.h:106
Definition: SIM_Geometry.h:126
int myTupleSize
Definition: SIM_Geometry.h:132
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual void saveSubclass(std::ostream &os) const
virtual void interpolateSubclass(const SIM_Data *source1, const SIM_Data *source2, fpreal interp)
GLuint const GLchar * name
Definition: glcorearb.h:785
bool myIsArray
Definition: SIM_Geometry.h:133
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:269
GA_StorageClass myStorage
Definition: SIM_Geometry.h:131
#define SIM_API
Definition: SIM_API.h:10
const GU_Detail * getGdp() const
Definition: SIM_Geometry.h:160
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
SIM_GeometryAutoReadLock(const SIM_Geometry *simgeo)
Definition: SIM_Geometry.h:155
UT_StringHolder myName
Definition: SIM_Geometry.h:130
virtual void initializeSubclass()