HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GT_GEOPrimPacked.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  * NAME: GT_GEOPrimPacked.h (GEO Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_GEOPrimPacked__
12 #define __GT_GEOPrimPacked__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include <GU/GU_PrimPacked.h>
17 
18 /// Container for a GU packed primitive
20 {
21 public:
22  /// Create a GT representation of the packed primitive @c prim. If @c
23  /// transformed is true, the transform on the packed primitive will be used
24  /// when refining.
25  /// The @c prim_gdh is the detail handle for the detail containing the
26  /// packed @c prim.
28  const GU_PrimPacked *prim, bool transformed=true)
29  : myPrimDetail(prim_gdh)
30  , myPrim(prim)
31  , myAttribs()
32  , myTransformed(transformed)
33  {
34  createPointPrimIDs();
35  }
37  : GT_Primitive(src)
38  , myPrimDetail(src.myPrimDetail)
39  , myPrim(src.myPrim)
40  , myAttribs(src.myAttribs)
41  , myTransformed(src.myTransformed)
42  {
43  }
44  virtual ~GT_GEOPrimPacked();
45 
46  /// @{
47  /// GT_Primitive interface
48  virtual const char *className() const;
49  virtual int getPrimitiveType() const { return GT_GEO_PACKED; }
50  virtual void enlargeBounds(UT_BoundingBox boxes[], int nseg) const;
51  virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nseg) const;
52  virtual void getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax,
53  const char *attribute_name) const;
54  virtual int getMotionSegments() const;
55  virtual int64 getMemoryUsage() const;
56  virtual bool save(UT_JSONWriter &w) const;
57  virtual const GT_ViewportRefineOptions &viewportRefineOptions() const;
59  { return new GT_GEOPrimPacked(*this); }
60 
62  { return myAttribs; }
63  /// @}
64 
65  /// The default refine method will process primitives, providing a bounding
66  /// box, point cloud, etc. based on the viewport LOD stored on the
67  /// primitive.
68  virtual bool refine(GT_Refine &refiner,
69  const GT_RefineParms *parms=NULL) const;
70 
71  /// @{
72  /// Normally, the primitive will pick up the transform from the GU
73  /// primitive implementation and use this in the GT representation.
74  /// However, when doing instancing of shared geometry, the transforms will
75  /// be picked up by the instance object, and so should be ignored on the
76  /// base primitive.
77  bool transformed() const { return myTransformed; }
78  void setTransformed(bool f) { myTransformed = f; }
79  /// @}
80 
81  /// @{
82  /// Set or query the viewport LOD - full, points, bbox, centroid, hidden.
83  virtual void setViewportLOD(GEO_ViewportLOD, int /*instance*/ )
84  {}
85  virtual GEO_ViewportLOD getViewportLOD(int /*instance*/) const
86  { return myPrim ? myPrim->viewportLOD()
88  /// @}
89 
90  /// Test whether a packed primitive should use the viewport LOD setting or
91  /// not. There are at least two factors in this determination:
92  /// - Whether the GT_RefineParms::getPackedViewportLOD() is true
93  /// - Whether the LOD is being overriden using
94  /// GT_RefineParms::getOverridePackedViewportLOD()
95  static bool useViewportLOD(const GT_RefineParms *parms);
96 
97  /// Get the full, un-transformed geometry.
98  /// @note Some packed primitives will always create "deformed" geometry.
99  void geometryAndTransform(
100  const GT_RefineParms *parms,
101  GT_PrimitiveHandle &result,
102  GT_TransformHandle &xform) const;
103 
104  /// Test whether instancing of the underlying geometry can be done
105  /// Returns @c false by default. If you return @c true, you must implement
106  /// - getInstanceKey()
107  /// - getInstanceGeometry()
108  /// - getInstanceTransform()
109  /// at a minimum.
110  virtual bool canInstance() const;
111 
112  /// If "instancing" is supported by the packed primitive, this method
113  /// should return true. The options that define the packed primitive
114  /// should be stored in the UT_Options. Primitives which have matching
115  /// UT_Options can be considered to be shared.
116  virtual bool getInstanceKey(UT_Options &options) const;
117 
118  /// Return the geometry the geometry for instancing. This may be different
119  /// than getFullGeometry() in that
120  /// - The geometry should not be transformed
121  /// - The packed primitive attributes should not be included in the
122  /// geometry
123  /// This allows multiple instances to share the geometry unmodified
124  /// The default method returns a NULL ptr.
125  virtual GT_PrimitiveHandle getInstanceGeometry(
126  const GT_RefineParms *parms,
127  bool ignore_visibility =false) const;
128  /// When instancing, this method extracts the attributes on the packed
129  /// primitive and returns them as a GT_AttributeList. The default method
130  /// scoops up all attributes on the primitive (point, vertex, primitive &
131  /// detail).
132  virtual GT_AttributeListHandle getInstanceAttributes() const;
133 
134  /// Return the transform handle for this particular instance. This method
135  /// should return the transform required to transform the instance geometry
136  /// to the space of this instance. The default method returns an identity
137  /// transform.
138  virtual GT_TransformHandle getInstanceTransform() const;
139 
140 
141  /// Returns either the primitive transform or the instance transform,
142  /// depending on whether canInstance() returns true.
143  GT_TransformHandle getFullTransform() const;
144 
145  /// Accessor to the primitive
146  const GU_PrimPacked *getPrim() const { return myPrim; }
147  /// Accessor to the packed implementation
149  { return myPrim->implementation(); }
150 
151  /// The default implementation of getPackedDetail() is @code
152  /// return getPrim->getPackedDetail();
153  /// @endcode
154  /// It's called by @c getPointCloud() and @c getFullGeometry() to allow for
155  /// sharing of geometry.
156  virtual GU_ConstDetailHandle getPackedDetail() const;
157 
158 protected:
159  /// @{
160  /// Sub-classes may want to override these methods which currently just
161  /// call getPackedDetail() and unpack() to access the geometry.
162  /// These methods should return the "untransformed" primitives.
163  ///
164  /// @warning It is important to ensure that the primitive attributes refer
165  /// to the GU_PrimPacked primitive, vertex, point. For example, in
166  /// GT_GEODetailList, you'd want to set the primitive id otherwise you'll
167  /// get crashes in the viewport as it tries to dereference the
168  /// points/vertices in the base detail (not the packed detail).
169  ///
170  /// If @c requires_transform is false if the point cloud is in the
171  /// primitive's transformed space (the same as unpacking). If it's true
172  /// the packed transform will be applied to the resulting primitive
173  /// (without modifying the returned geometry). @c require_transform will
174  /// be true by default, so it doesn't have to be written in most cases.
175  virtual GT_PrimitiveHandle getPointCloud(const GT_RefineParms *parms,
176  bool &requires_transform) const;
177  virtual GT_PrimitiveHandle getFullGeometry(const GT_RefineParms *parms,
178  bool &requires_transform) const;
179  /// @}
180 
181  /// When extracting geometry for a single primitive, the base class may
182  /// automatically copy some attributes from the packed primitive to the GT
183  /// instance. If you've written a custom handler which is able to instance
184  /// geometry (i.e. share the geometry through a GT_PrimInstance), this will
185  /// do the wrong thing, since the shader attributes will be copied to the
186  /// geometry (rather than being able to change on a per-instance basis).
187  /// So, you must override this method to indicate that you're handling the
188  /// packed attributes yourself.
189  ///
190  /// The default is to copy the attributes, if you're handling them
191  /// yourself, return @c false.
192  virtual bool copyPackedAttributesToGeometry() const;
193 
194  /// For fragments, the GU interface only provides a means of unpacking(),
195  /// but not querying the fragment range. This convenience method will
196  /// create geometry for a range of a gdp without unpacking.
197  /// The fragment_gdh is a detail representing the geometry of the fragment.
198  GT_PrimitiveHandle buildUntransformedFragment(
199  const GU_ConstDetailHandle &fragment_gdh,
200  const GA_Range &range) const;
201 
202  /// @{
203  /// Sub-classes may want to override these methods which currently just
204  /// call the bounding box method and create transformed geometry based on
205  /// the bounds.
206  /// The box & centroid should be @b untransformed.
207  virtual GT_PrimitiveHandle getBoxGeometry(const GT_RefineParms *parms) const;
208  virtual GT_PrimitiveHandle getCentroidGeometry(const GT_RefineParms *parms) const;
209  /// @}
210 
211  void createPointPrimIDs();
212  void appendAttribute(const char *name,
213  const GT_DataArrayHandle &attrib);
214 
215  /// Hardening a packed primitive will extract the full geometry
216  virtual GT_PrimitiveHandle doHarden() const;
217 
219  const GU_PrimPacked *prim)
220  {
221  myPrimDetail = dh;
222  myPrim = prim;
223  }
224 private:
225  GU_ConstDetailHandle myPrimDetail;
226  const GU_PrimPacked *myPrim;
227  GT_AttributeListHandle myAttribs;
228  bool myTransformed;
229 };
230 
231 #endif
virtual int getMotionSegments() const =0
GLenum GLint * range
Definition: glcorearb.h:1924
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
virtual const GT_ViewportRefineOptions & viewportRefineOptions() const
virtual GEO_ViewportLOD getViewportLOD(int) const
void setDetailPrim(const GU_ConstDetailHandle &dh, const GU_PrimPacked *prim)
#define GT_API
Definition: GT_API.h:11
virtual int getPrimitiveType() const
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max, const char *attribute_name="v") const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
3D Vector class.
virtual const GT_AttributeListHandle & getPointAttributes() const
A range of elements in an index-map.
Definition: GA_Range.h:42
GT_GEOPrimPacked(const GT_GEOPrimPacked &src)
long long int64
Definition: SYS_Types.h:100
GT_GEOPrimPacked(const GU_ConstDetailHandle &prim_gdh, const GU_PrimPacked *prim, bool transformed=true)
void appendAttribute(PointDataTree &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr metaDefaultValue=Metadata::Ptr(), const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType) ...
GLfloat f
Definition: glcorearb.h:1925
const GU_PackedImpl * getImplementation() const
Accessor to the packed implementation.
virtual GT_PrimitiveHandle doSoftCopy() const
const GU_PrimPacked * getPrim() const
Accessor to the primitive.
virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegments) const
bool transformed() const
virtual void setViewportLOD(GEO_ViewportLOD, int)
GLuint const GLchar * name
Definition: glcorearb.h:785
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
virtual GT_PrimitiveHandle doHarden() const
virtual int64 getMemoryUsage() const =0
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
Container for a GU packed primitive.
A map of string to various well defined value types.
Definition: UT_Options.h:42
GEO_ViewportLOD
virtual bool save(UT_JSONWriter &w) const
void setTransformed(bool f)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
virtual const char * className() const =0
GLenum src
Definition: glcorearb.h:1792