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