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