HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 /// A primitive which instances another primitive
21 ///
22 /// The instance primitive can have attribute lists:
23 /// - detail: one for the whole primitive
24 /// - uniform: one per instance
25 /// The instance primitive does *not* pass these down when it refines.
27 {
28 public:
30  GT_PrimInstance(const GT_PrimitiveHandle &geometry,
32  const GT_GEOOffsetList &packed_prim_offsets=GT_GEOOffsetList(),
37  virtual ~GT_PrimInstance();
38 
39  /// @{
40  /// Interface from GT_Primitive
41  virtual const char *className() const;
42  virtual int getPrimitiveType() const;
43  virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegs) const
44  { doEnlargeBounds(boxes, nsegs, false); }
45  virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegs) const
46  { doEnlargeBounds(boxes, nsegs, true); }
47  virtual void getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax,
48  const char *attribute_name) const;
49  virtual bool refine(GT_Refine &refiner,
50  const GT_RefineParms *parms=NULL) const;
51  virtual int getMotionSegments() const;
52  virtual int64 getMemoryUsage() const;
53  virtual bool save(UT_JSONWriter &w) const;
54  virtual fpreal computePerimeter(int seg=0) const;
55  virtual fpreal computeSurfaceArea(int seg=0) const;
56  virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg=0) const;
57  virtual GT_PrimitiveHandle doHarden() const;
58  virtual GT_PrimitiveHandle doSoftCopy() const;
59  virtual const GT_ViewportRefineOptions &viewportRefineOptions() const;
61  { return myUniform; }
63  { return myDetail; }
64  /// @}
65 
66  /// Check valid
67  bool isValid() const
68  { return myGeometry && myTransforms; }
69 
70  /// Return number of instances
71  GT_Size entries() const
72  { return myTransforms ? myTransforms->entries():0; }
73 
74  /// Return geometry to be instanced
76  { return myGeometry; }
77 
78  /// Return transforms for instances
80  { return myTransforms; }
81  /// Non-const transform access (for appending new transforms).
83  { return myTransforms; }
84  /// Return uniform attributes
86  { return myUniform; }
87  /// Return detail attributes
89  { return myDetail; }
90 
92  { return myPackedPrimOffsets; }
93 
94  /// Return the transforms for instances, but combined with the transform
95  /// for the primitive itself.
96  GT_TransformArrayHandle combinedTransforms() const;
97 
98  /// Refine geometry to create new instance primitives for each refined
99  /// primitive. For example, if you refine an instance primitive containing
100  /// a GT_PrimPolygonMesh, the poly mesh will be refined to create
101  /// individual polygons. Each of these will be added to the refiner
102  /// contained in an instance primitive.
103  bool refineToInstances(GT_Refine &refiner,
104  const GT_RefineParms *parms) const;
105  /// Refine to individual pieces of geometry. This will create transformed
106  /// copies of the geometry for each transform in the instance primitive
107  bool flattenInstances(GT_Refine &refiner,
108  const GT_RefineParms *parms) const;
109  /// If the geometry contained by this instance primitive is an instance
110  /// primitive itself this method will expand the instances, by permuting
111  /// the transform arrays, creating a single flattened array of transforms.
112  GT_PrimitiveHandle expandInstanceTransforms() const;
113 
114  /// When the generic refine method is called, if the primitive is a
115  /// "simple" primitive, flattenInstances() will be called instead of
116  /// refineToInstances().
117  ///
118  /// Default method considers the following to be "simple"
119  /// - GT_PRIM_POLYGON_MESH
120  /// - GT_PRIM_POLYGON
121  /// - GT_PRIM_SUBDIVISION_MESH
122  /// - GT_PRIM_CURVE_MESH
123  /// - GT_PRIM_CURVE
124  /// - GT_PRIM_POINT_MESH
125  /// - GT_PRIM_NUPATCH
126  /// - GT_PRIM_CIRCLE
127  /// - GT_PRIM_SPHERE
128  /// - GT_PRIM_TUBE
129  /// - GT_PRIM_HYPERBOLOID
130  /// - GT_PRIM_CIRCLE_MESH
131  /// - GT_PRIM_SPHERE_MESH
132  /// - GT_PRIM_TUBE_MESH
133  /// - GT_PRIM_HYPERBOLOID_MESH
134  virtual bool isSimplePrimitive(int primitive_type) const;
135 
136  /// @{
137  /// If the geometry being instanced comes from a GU_Detail, then the source
138  /// geometry should be set to point to this geometry. This lets viewport
139  /// decorations be rendered properly.
141  { return mySourceGeometry; }
143  { mySourceGeometry = g; }
144  /// @}
145 
146  virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl,
147  const GT_RefineParms &refine);
148 
149 protected:
150  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegs,
151  bool forrender) const;
152 
159 };
160 
161 #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
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
virtual const GT_ViewportRefineOptions & viewportRefineOptions() const
png_infop int transforms
Definition: png.h:2591
GT_TransformArrayHandle myTransforms
bool isValid() const
Check valid.
virtual int getPrimitiveType() const
virtual fpreal computePerimeter(int seg=0) const
virtual const GT_AttributeListHandle & getDetailAttributes() 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 setSourceGeometry(const GT_GEODetailListHandle &g)
GLboolean GLboolean g
Definition: glcorearb.h:1221
#define GT_API
Definition: GT_API.h:11
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max, const char *attribute_name="v") const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
const GT_TransformArrayHandle & transforms() const
Return transforms for instances.
3D Vector class.
virtual const GT_AttributeListHandle & getUniformAttributes() const
const GT_GEOOffsetList & packedPrimOffsets() const
GT_GEOOffsetList myPackedPrimOffsets
long long int64
Definition: SYS_Types.h:100
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.
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
virtual GT_PrimitiveHandle doHarden() const
virtual int64 getMemoryUsage() const =0
GT_AttributeListHandle myUniform
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
double fpreal
Definition: SYS_Types.h:263
const GT_PrimitiveHandle & geometry() const
Return geometry to be instanced.
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegs) const
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
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GT_Size entries() const
Return number of instances.
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
int64 GT_Size
Definition: GT_Types.h:109
virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegs) const
virtual const char * className() const =0
GT_GEODetailListHandle mySourceGeometry
GLenum src
Definition: glcorearb.h:1792