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