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