HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimAgentShape.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_PrimAgentShape.h (GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef GT_PrimAgentShape_h
11 #define GT_PrimAgentShape_h
12 
13 #include "GT_API.h"
14 #include "GT_GEOPackedAgent.h"
15 #include "GT_AgentSupport.h"
16 
17 #include <GU/GU_DetailHandle.h>
18 
19 #include <UT/UT_IntArray.h>
20 #include <UT/UT_Map.h>
21 #include <UT/UT_Matrix4.h>
22 #include <UT/UT_VectorTypes.h>
23 #include <UT/UT_IntrusivePtr.h>
24 #include <UT/UT_NonCopyable.h>
25 
26 #include <SYS/SYS_AtomicInt.h>
27 #include <SYS/SYS_Types.h>
28 
29 class RE_VertexArray;
30 
31 /// A shape belonging to agents, instanced with material assignments.
33 {
34 public:
36  {
38  DEFORMING
39  };
42  GT_PrimAgentShape(const GT_PrimitiveHandle &geometry,
43  const GU_ConstDetailHandle &dh,
44  const GT_ShapeLODGroupHandle &agent_group,
45  ShapeClass shape_class,
46  int lod_level,
47  GT_DataArray *mat_remap);
48  virtual ~GT_PrimAgentShape();
49 
50  /// Whether the shape's geometry is static or deformed
51  ShapeClass getShapeClass() const;
52 
53  /// shape geometry.
54  const GT_PrimitiveHandle &geometry() const;
55  GU_ConstDetailHandle &detail() const;
56 
57  /// Access to the shared data between LOD levels of the same agent shape
58  const GT_ShapeLODGroupHandle &shapeGroup() const;
59 
60  /// Which LOD level this shape represents: 0=primary, 1+ lower resolutions
61  int lodLevel() const;
62 
63  /// one set of transforms per material.
64  exint getNumMatGroups() const;
65  exint getMatGroupNumInstances(exint grp_idx) const;
66  int getMatGroupMaterialID(exint grp_idx) const;
67  const UT_IntArray &getMatGroupAgentPrimIDs(exint grp_idx) const;
68  const UT_IntArray &getMatGroupAgentPointIDs(exint grp_idx) const;
69 
70  GT_DataArrayHandle getMatRemapAttrib() const { return myMatRemap; }
71 
72  int getNumTransformsPerInstance() const;
73 
74  /// Import computed transforms into 'xforms'. If packed_xform_only is true,
75  /// only the agent transforms are returned. If false, the rig * agent
76  /// transforms are returned.
77  void getMatGroupTransforms(exint grp_idx, UT_Matrix4FArray &xforms,
78  bool packed_xform_only) const;
79 
80  /// Copy transforms into a fp32 mat buffer. Must be num_instances in size.
81  void fetchMatGroupTransforms(int idx,
83  bool packed_xform_only) const;
84 
85  /// Copy rig transforms into a fp32 4x3 matrix buffer.
86  /// Must be num_instances * getNumTransformsPerInstance() in size.
87  void fetchMatGroupRigTransforms(int idx, fpreal32 *buf) const;
88 
89  /// Copy colors into a 4 x uint8 buffer.
90  void fetchMatGroupColors(int idx, uint8 *buf) const;
91 
92  /// Return a list of visible instances in this material group, based on the
93  /// visibility info computed by the GT_GEOPackedAgent. returns -1 if
94  /// only some are visible, 0 if none are visible, and 1 if all are visible.
95  /// The 'lod_bias' is a factor that will favour lower LOD levels if > 1,
96  /// and higher LOD levels if < 1. A bias of zero will disable LOD.
97  int getVisibleInstances(int grp_idx,
98  UT_IntArray &inst_idx,
99  int lod_base = 0.0,
100  fpreal lod_bias = 1.0) const;
101 
102 
103  // non-const methods for GT_GEOPackedAgent to modify the shapes
104 
105  /// Add a instance
106  void addShapeInstance(int xform_index,
107  int material_id,
108  GA_Index agent_prim_idx,
109  GA_Index agent_pnt_idx,
110  int shape_binding);
111 
112  /// Transform arrays assigned by GT_GEOPackedAgent
113  void setDeformTransformMap(UT_IntArray *map);
114  void setInvRestTransforms(UT_Matrix4FArray *rest);
115 
116 
117  // GT_Primitive pure virtual overrides
118  virtual const char *className() const { return "GT_PrimAgentShape"; }
119  virtual int getPrimitiveType() const { return GT_PRIM_AGENT_SHAPE; }
120  virtual void enlargeBounds(UT_BoundingBox boxes[],
121  int nsegments) const
122  { doEnlargeBounds(boxes, nsegments, false); }
123  virtual void enlargeRenderBounds(UT_BoundingBox boxes[],
124  int nsegments) const
125  { doEnlargeBounds(boxes, nsegments, true); }
126  virtual int getMotionSegments() const { return 1; }
127  virtual int64 getMemoryUsage() const;
129  { return new GT_PrimAgentShape(*this); }
130  virtual GT_PrimitiveHandle doHarden() const { return doSoftCopy(); }
131 
132  virtual bool refine(GT_Refine &refiner,
133  const GT_RefineParms *parms = NULL) const;
134 
135  virtual bool getTopologyVersion(int64 &version) const;
136 
138  {
139  public:
145  };
146 
147  // Stylesheet agent shape support. Unstyled groups are those with just
148  // primitive agent material assignments, whereas styled groups have the
149  // shape assignments as well.
150  int getNumUnstyledGroups() const;
151  ShapeInstance &getShapeInstancesForUnstyledGroup(int mat_group);
152  void resetStyledMatGroups();
153  ShapeInstance *addStyledMatGroup(int mat_id);
154 
155 private:
156  void doEnlargeBounds(UT_BoundingBox boxes[], int nsegments,
157  bool render) const;
158 
159  UT_SortedMap<int,int> myMatGroupMap;
160 
161 private:
162 
163  UT_Array<ShapeInstance> myMatGroup;
164  UT_Array<ShapeInstance *> myStyledMatGroup;
165  bool myUseStyledMatGroups;
166 
167  GT_ShapeLODGroupHandle myLODGroup;
168  GT_PrimitiveHandle myGeometry;
169  GU_ConstDetailHandle myDetail;
170  ShapeClass myShapeClass;
171  mutable UT_Vector2iArray myVisibleInstances;
172  int myLODLevel;
173  GT_DataArrayHandle myMatRemap;
174 };
175 
176 
177 inline const GT_PrimitiveHandle &
179 { return myGeometry; }
180 
181 inline exint
183 {
184  return myUseStyledMatGroups ? myStyledMatGroup.entries()
185  : myMatGroup.entries();
186 }
187 
188 inline exint
190 {
191  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
192  : myMatGroup(i);
193  return inst.myPrimIDs.entries();
194 }
195 
196 inline int
198 {
199  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
200  : myMatGroup(i);
201  return inst.myMaterialID;
202 }
203 
204 inline const UT_IntArray &
206 {
207  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
208  : myMatGroup(i);
209  return inst.myPrimIDs;
210 }
211 
212 inline const UT_IntArray &
214 {
215  const ShapeInstance &inst = myUseStyledMatGroups ? *myStyledMatGroup(i)
216  : myMatGroup(i);
217  return inst.myPointIDs;
218 }
219 
220 inline int
222 {
223  return myMatGroup.entries();
224 }
225 
228 {
229  return myMatGroup(mat_group);
230 }
231 
232 inline void
234 {
235  for(auto grp : myStyledMatGroup)
236  delete grp;
237  myStyledMatGroup.entries(0);
238  myUseStyledMatGroups = false;
239 }
240 
243 {
244  myUseStyledMatGroups = true;
245  myStyledMatGroup.append(new ShapeInstance);
246  myStyledMatGroup.last()->myMaterialID = mat_id;
247  return myStyledMatGroup.last();
248 }
249 
250 inline GU_ConstDetailHandle &
252 { return const_cast<GT_PrimAgentShape *>(this)->myDetail; }
253 
256 { return myShapeClass; }
257 
258 inline int
260 { return myLODLevel; }
261 
262 inline const GT_ShapeLODGroupHandle &
264 { return myLODGroup; }
265 
266 #endif
267 
268 
virtual const char * className() const
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
GT_DataArrayHandle getMatRemapAttrib() const
virtual bool getTopologyVersion(int64 &version) const
Returns the topology version for the primitive.
ShapeInstance & getShapeInstancesForUnstyledGroup(int mat_group)
virtual void enlargeRenderBounds(UT_BoundingBox boxes[], int nsegments) const
int getNumUnstyledGroups() const
#define GT_API
Definition: GT_API.h:11
ShapeInstance * addStyledMatGroup(int mat_id)
int getMatGroupMaterialID(exint grp_idx) const
png_uint_32 i
Definition: png.h:2877
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
const UT_IntArray & getMatGroupAgentPointIDs(exint grp_idx) const
long long int64
Definition: SYS_Types.h:107
ShapeClass getShapeClass() const
Whether the shape's geometry is static or deformed.
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
virtual GT_PrimitiveHandle doSoftCopy() const =0
int64 exint
Definition: SYS_Types.h:116
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const
virtual int getMotionSegments() const
int lodLevel() const
Which LOD level this shape represents: 0=primary, 1+ lower resolutions.
virtual int getPrimitiveType() const
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GU_ConstDetailHandle & detail() const
virtual int64 getMemoryUsage() const =0
exint getNumMatGroups() const
one set of transforms per material.
GT_API const UT_StringHolder version
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:453
double fpreal
Definition: SYS_Types.h:270
virtual GT_PrimitiveHandle doSoftCopy() const
const GT_ShapeLODGroupHandle & shapeGroup() const
Access to the shared data between LOD levels of the same agent shape.
const GT_PrimitiveHandle & geometry() const
shape geometry.
unsigned char uint8
Definition: SYS_Types.h:32
A shape belonging to agents, instanced with material assignments.
virtual GT_PrimitiveHandle doHarden() const
const UT_IntArray & getMatGroupAgentPrimIDs(exint grp_idx) const
GA_API const UT_StringHolder rest
float fpreal32
Definition: SYS_Types.h:191
exint getMatGroupNumInstances(exint grp_idx) const