HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimInstance.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_PrimInstance.h (GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_PrimInstance__
12 #define __GT_PrimInstance__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include "GT_TransformArray.h"
17 #include "GT_GEODetailList.h"
18 #include "GT_GEOSupport.h"
19 
20 class UT_StringRef;
21 
22 /// A primitive which instances another primitive
23 ///
24 /// The instance primitive can have attribute lists:
25 /// - detail: one for the whole primitive
26 /// - uniform: one per instance
27 /// The instance primitive does *not* pass these down when it refines.
29 {
30 public:
32  GT_PrimInstance(const GT_PrimitiveHandle &geometry,
33  const GT_TransformArrayHandle &transforms,
34  const GT_GEOOffsetList &packed_prim_offsets=GT_GEOOffsetList(),
39  ~GT_PrimInstance() override;
40 
41  /// @{
42  /// Interface from GT_Primitive
43  const char *className() const override;
44  int getPrimitiveType() const override;
46  int nsegs) const override
47  { doEnlargeBounds(boxes, nsegs, false); }
49  int nsegs) const override
50  { doEnlargeBounds(boxes, nsegs, true); }
51  void getVelocityRange(
52  UT_Vector3 &vmin, UT_Vector3 &vmax,
53  const UT_StringRef &attribute_name
54  ) const override;
55  bool refine(GT_Refine &refiner,
56  const GT_RefineParms *parms=NULL) const override;
57  int getMotionSegments() const override;
58  int64 getMemoryUsage() const override;
59  bool save(UT_JSONWriter &w) const override;
60  fpreal computePerimeter(int seg=0) const override;
61  fpreal computeSurfaceArea(int seg=0) const override;
62  fpreal computeVolume(const UT_Vector3 &ref_P,
63  int seg=0) const override;
64  GT_PrimitiveHandle doHarden() const override;
65  GT_PrimitiveHandle doSoftCopy() const override;
66  const GT_ViewportRefineOptions &viewportRefineOptions() const override;
68  { return myUniform; }
70  { return myDetail; }
71  /// @}
72 
73  /// Check valid
74  bool isValid() const
75  { return myGeometry && myTransforms; }
76 
77  /// Return number of instances
78  GT_Size entries() const
79  { return myTransforms ? myTransforms->entries():0; }
80 
81  /// Return geometry to be instanced
83  { return myGeometry; }
84 
85  /// Return transforms for instances
87  { return myTransforms; }
88  /// Non-const transform access (for appending new transforms).
90  { return myTransforms; }
91  /// Return uniform attributes
93  { return myUniform; }
94  /// Return detail attributes
96  { return myDetail; }
97 
99  { return myPackedPrimOffsets; }
100 
101  /// Return the transforms for instances, but combined with the transform
102  /// for the primitive itself.
103  GT_TransformArrayHandle combinedTransforms() const;
104 
105  /// Refine geometry to create new instance primitives for each refined
106  /// primitive. For example, if you refine an instance primitive containing
107  /// a GT_PrimPolygonMesh, the poly mesh will be refined to create
108  /// individual polygons. Each of these will be added to the refiner
109  /// contained in an instance primitive.
110  bool refineToInstances(GT_Refine &refiner,
111  const GT_RefineParms *parms) const;
112  /// Refine to individual pieces of geometry. This will create transformed
113  /// copies of the geometry for each transform in the instance primitive
114  bool flattenInstances(GT_Refine &refiner,
115  const GT_RefineParms *parms) const;
116  /// If the geometry contained by this instance primitive is an instance
117  /// primitive itself this method will expand the instances, by permuting
118  /// the transform arrays, creating a single flattened array of transforms.
119  GT_PrimitiveHandle expandInstanceTransforms() const;
120 
121  /// When the generic refine method is called, if the primitive is a
122  /// "simple" primitive, flattenInstances() will be called instead of
123  /// refineToInstances().
124  ///
125  /// Default method considers the following to be "simple"
126  /// - GT_PRIM_POLYGON_MESH
127  /// - GT_PRIM_POLYGON
128  /// - GT_PRIM_SUBDIVISION_MESH
129  /// - GT_PRIM_CURVE_MESH
130  /// - GT_PRIM_CURVE
131  /// - GT_PRIM_POINT_MESH
132  /// - GT_PRIM_NUPATCH
133  /// - GT_PRIM_CIRCLE
134  /// - GT_PRIM_SPHERE
135  /// - GT_PRIM_TUBE
136  /// - GT_PRIM_HYPERBOLOID
137  /// - GT_PRIM_CIRCLE_MESH
138  /// - GT_PRIM_SPHERE_MESH
139  /// - GT_PRIM_TUBE_MESH
140  /// - GT_PRIM_HYPERBOLOID_MESH
141  virtual bool isSimplePrimitive(int primitive_type) const;
142 
143  /// @{
144  /// If the geometry being instanced comes from a GU_Detail, then the source
145  /// geometry should be set to point to this geometry. This lets viewport
146  /// decorations be rendered properly.
148  { return mySourceGeometry; }
150  { mySourceGeometry = g; }
151  /// @}
152 
153  bool updateGeoPrim(const GU_ConstDetailHandle &dtl,
154  const GT_RefineParms &refine) override;
155 
156 protected:
157  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegs,
158  bool forrender) const;
159 
166 };
167 
168 #endif
virtual int getMotionSegments() const =0
virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl, const GT_RefineParms &parms)
update any cached data for geometry and its attributes
GLenum src
Definition: glew.h:2410
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
virtual const GT_ViewportRefineOptions & viewportRefineOptions() const
GT_TransformArrayHandle myTransforms
bool isValid() const
Check valid.
virtual int getPrimitiveType() const
virtual fpreal computePerimeter(int seg=0) const
UT_IntrusivePtr< GT_AttributeList > GT_AttributeListHandle
Definition: GT_Handles.h:24
virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg=0) const
void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegs) const override
void setSourceGeometry(const GT_GEODetailListHandle &g)
#define GT_API
Definition: GT_API.h:11
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
const GT_TransformArrayHandle & transforms() const
Return transforms for instances.
const GT_GEOOffsetList & packedPrimOffsets() const
const GT_AttributeListHandle & getUniformAttributes() const override
GT_GEOOffsetList myPackedPrimOffsets
GT_AttributeListHandle myDetail
virtual GT_PrimitiveHandle doSoftCopy() const =0
GT_PrimitiveHandle myGeometry
virtual fpreal computeSurfaceArea(int seg=0) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
const GT_AttributeListHandle & uniform() const
Return uniform attributes.
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max, const UT_StringRef &attribute_name=GA_Names::v) const
long long int64
Definition: SYS_Types.h:116
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
virtual GT_PrimitiveHandle doHarden() const
virtual int64 getMemoryUsage() const =0
GT_AttributeListHandle myUniform
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
int64 GT_Size
Definition: GT_Types.h:113
const GT_PrimitiveHandle & geometry() const
Return geometry to be instanced.
void enlargeBounds(UT_BoundingBox boxes[], int nsegs) const override
fpreal64 fpreal
Definition: SYS_Types.h:277
GT_TransformArrayHandle & transforms()
Non-const transform access (for appending new transforms).
const GT_AttributeListHandle & detail() const
Return detail attributes.
virtual bool save(UT_JSONWriter &w) const
const GT_GEODetailListHandle & sourceGeometry() const
GT_Size entries() const
Return number of instances.
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
virtual const char * className() const =0
GLboolean GLboolean g
Definition: glew.h:9477
GT_GEODetailListHandle mySourceGeometry
const GT_AttributeListHandle & getDetailAttributes() const override