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