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