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  // Cache the prim points per offset
158  {
159  public:
161  : myPrimOff(GA_INVALID_OFFSET)
162  , myPrimPacked(false)
163  {}
166  };
167 
169 
170  /// Same code as updateGeoPrim but extracts the transforms to flat arrays
171  /// instead of GT_TransformArray. It uses a cache of extracted prim offsets
172  /// and the cache is rebuilt only if it is empty.
173  /// @transforms: Returned transforms
174  /// @cache: cache pointers to primitives, prim types and prim offset
175  bool extractTransforms(const GU_ConstDetailHandle &dtl,
176  UT_Matrix4DArray &transforms,
177  ExtractTransformCache &cache) const;
178 
179 protected:
180  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegs,
181  bool forrender) const;
182 
190 };
191 
192 #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
bool myPrimPacked
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)
GLboolean GLboolean g
Definition: glcorearb.h:1222
#define GT_API
Definition: GT_API.h:13
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
const GT_TransformArrayHandle & transforms() const
Return transforms for instances.
const GT_GEOOffsetList & packedPrimOffsets() const
UT_Array< ExtractTransformEntry > ExtractTransformCache
#define GA_INVALID_OFFSET
Definition: GA_Types.h:678
const GT_AttributeListHandle & getUniformAttributes() const override
GT_GEOOffsetList myPackedPrimOffsets
GA_Size GA_Offset
Definition: GA_Types.h:641
GT_AttributeListHandle myDetail
virtual GT_PrimitiveHandle doSoftCopy() const =0
GT_PrimitiveHandle myGeometry
virtual fpreal computeSurfaceArea(int seg=0) const
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
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
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:128
ExtractTransformEntry()
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
GA_Offset myPrimOff
const GT_GEODetailListHandle & sourceGeometry() const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GT_Size entries() const
Return number of instances.
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
virtual const char * className() const =0
GT_GEODetailListHandle mySourceGeometry
GLenum src
Definition: glcorearb.h:1793
const GT_AttributeListHandle & getDetailAttributes() const override