HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_Util.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_Util.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_Util__
12 #define __GT_Util__
13 
14 #include "GT_API.h"
15 
16 #include <UT/UT_Array.h>
17 #include <GA/GA_Types.h>
18 #include <GEO/GEO_PackedTypes.h>
19 #include "GT_DANumeric.h"
20 #include "GT_Types.h"
21 #include "GT_Handles.h"
22 
23 class GA_Attribute;
24 class GA_Range;
25 class GU_Detail;
26 class GU_DetailHandle;
27 class GD_Detail;
28 class GT_RefineParms;
29 class GT_TrimNuCurves;
30 class GT_PrimPolygonMesh;
32 
34 {
35 public:
36  /// Create a list of geometry details. Each refined primitive is stored in
37  /// a separate detail.
38  /// Refine parameters include:
39  /// - bool "gconvert:include_ids" (default: false)@n
40  /// Keep the __vertex_id and __primitive_id attributes in conversion
41  /// - bool "gconvert:particleprim" (default: false)@n
42  /// Convert point mesh primitives to a particle primitive. If off, the
43  /// detail will just contain points (no primitives).
44  /// - bool "gconvert:pack" (default: false) @n
45  /// Each primitive will be packed into a packed primitive, meaning the
46  /// list of returned details will each have a single packed primitive.
47  static void makeGEO(UT_Array<GU_Detail *> &result,
48  const GT_PrimitiveHandle &prim,
49  const GT_RefineParms *rparms = NULL,
50  int segment = 0);
51  /// Create a list of geometry details for a single GT primitive. Each
52  /// refined primitive is stored in a separate detail. These details must be
53  /// deleted by the caller.
54  static void makeGEO(UT_Array<GU_Detail *> &result,
55  const GT_Primitive &prim,
56  const GT_RefineParms *rparms = NULL,
57  int segment = 0);
58 
59  /// Create a list of geometry details, but return the result in an array of
60  /// GU_DetailHandle's. Each primitive's refined geometry is stored in a
61  /// separate detail.
62  ///
63  /// Refine parameters include:
64  /// - bool "gconvert:include_ids" (default: false)@n
65  /// Keep the __vertex_id and __primitive_id attributes in conversion
66  /// - bool "gconvert:particleprim" (default: false)@n
67  /// Convert point mesh primitives to a particle primitive. If off, the
68  /// detail will just contain points (no primitives).
69  static void makeGEO(UT_Array<GU_DetailHandle> &result,
70  const GT_PrimitiveHandle &prim,
71  const GT_RefineParms *parms = NULL,
72  int segment = 0);
73  /// Create a list of geometry details for a single GT primitive. Each
74  /// refined primitive is stored in a separate detail.
75  static void makeGEO(UT_Array<GU_DetailHandle> &result,
76  const GT_Primitive &prim,
77  const GT_RefineParms *rparms = NULL,
78  int segment = 0);
79 
80 
81  /// Test whether a primitive is atomic (i.e. converts to a single gdp)
82  static bool isSimpleGEO(const GT_Primitive &prim,
83  const GT_RefineParms *rparms = NULL);
84 
85  /// Convert a GT_TrimNuCurves primitive to a GD_Detail for trim curves
86  static void makeGD(GD_Detail &gdp, const GT_TrimNuCurves &curves);
87 
88  /// Map from GA_Type info to a GT_Type info
89  static GT_Type getType(GA_TypeInfo type);
90 
91  /// Map from GT_Type to GA_TypeInfo
92  static GA_TypeInfo getGAType(GT_Type type);
93 
94  /// Map from GA_Storage to GT_Storage
95  static GT_Storage getStorage(GA_Storage storage);
96 
97  /// Map from GT_Storage to GA_Storage
98  static GA_Storage getGAStorage(GT_Storage storage);
99 
100  /// Extract a data array from a GA attribute
101  static GT_DataArrayHandle extractAttribute(const GA_Attribute &attrib,
102  const GA_Range &range);
103 
104  /// Copies attributes from an attribute list to a detail
105  static void copyAttributeListToDetail( GU_Detail *gdp,
106  GA_AttributeOwner owner,
107  const GT_RefineParms *parms,
108  const GT_AttributeListHandle &alist,
109  int segment );
110 
111  /// Some software represents crease weights as a list of edges and
112  /// sharpnesses, or corners and sharpnesses. This code will look for the
113  /// Houdini "crease" attributes and map them to edge or corner crease
114  /// weights. Edge creases are specified by two indices and a single
115  /// sharpneess (i.e. the length of @c edge_indices will be twice the length
116  /// of @c edge_sharpness). @n
117  /// Each index (edge or corner) refers to a vertex in the vertex list. @n
118  /// @note: This function relies on being able to find the __primitive_id
119  /// and __vertex_id attributes on the polygon mesh to evaluate the @c
120  /// creaseweight attribute.
121  /// @note: You only need a GT_PrimPolygonMesh to compute creases...
122  /// GT_PrimSubdivisionMesh is a sub-class of GT_PrimPolygonMesh.
123  static bool computeSubdivisionCreases(const GU_Detail &gdp,
124  const GT_PrimPolygonMesh &polymesh,
125  GT_DataArrayHandle &edge_indices,
126  GT_DataArrayHandle &edge_sharpnesses,
127  GT_DataArrayHandle &corner_indices,
128  GT_DataArrayHandle &corner_sharpnesses,
129  GT_DataArrayHandle &hole_indices);
130  /// This version of @c computeSubdivisionCreases() looks for uniform or
131  /// vertex attributes named "creaseweight" on the GT_PrimPolygonMesh.
132  static bool computeSubdivisionCreases(
133  const GT_PrimPolygonMesh &polymesh,
134  GT_DataArrayHandle &edge_indices,
135  GT_DataArrayHandle &edge_sharpnesses,
136  GT_DataArrayHandle &corner_indices,
137  GT_DataArrayHandle &corner_sharpnesses,
138  GT_DataArrayHandle &hole_indices);
139 
140  /// Add the standard subdivision tags from the mesh attributes (e.g.
141  /// creaseweight).
142  /// If allow_uniform_parms is enabled, attributes for subdivision
143  /// parameters (like osd_vtxboundaryinterpolation) can be read from the
144  /// first element of a uniform attribute if the detail attribute does not
145  /// exist.
146  /// The gdp can optionally be provided as the source for the attributes and
147  /// groups, if e.g. facesets aren't being imported.
148  static void
149  addStandardSubdTagsFromAttribs(GT_PrimSubdivisionMesh &subd_mesh,
150  bool allow_uniform_parms = false,
151  const GU_Detail *gdp = nullptr);
152 
153  /// Return an array of the point IDs of the primitives (in GA_Index's).
154  static GT_DataArrayHandle getPointIndex(const GT_Primitive &prim,
155  const GU_Detail &parent_detail,
156  int npoints);
157  static GT_DataArrayHandle getPointIndex(const GT_Primitive &prim,
158  const GU_ConstDetailHandle &geo,
159  int npoints);
160 
161  static GT_DataArrayHandle getPointOffset(const GT_Primitive &prim,
162  const GU_Detail &parent_detail,
163  int npoints);
164  static GT_DataArrayHandle getPointOffset(const GT_Primitive &prim,
165  const GU_ConstDetailHandle &geo,
166  int npoints);
167 
168  /// Return an array of the primitive IDs (in GA_Index's).
169  /// If 'use_nested' is true, attempt to find __nested_prim_id first, then
170  /// fall back to __primitive_id.
171  static GT_DataArrayHandle getPrimitiveIndex(const GT_Primitive &prim,
172  const GU_Detail &parent_dtl,
173  bool use_nested = false);
174  static GT_DataArrayHandle getPrimitiveIndex(const GT_Primitive &prim,
175  const GU_ConstDetailHandle &pdtl,
176  bool use_nested = false);
177 
178  static GT_DataArrayHandle getPrimitiveOffset(const GT_Primitive &prim,
179  const GU_Detail &parent_dtl,
180  bool use_nested = false);
181  static GT_DataArrayHandle getPrimitiveOffset(const GT_Primitive &prim,
182  const GU_ConstDetailHandle &pdtl,
183  bool use_nested = false);
184 
185  template <typename T>
187  GT_Size npoints,
188  GT_Size newpoints)
189  {
190  GT_DANumeric<T> *array;
191  T *data;
192  array = new GT_DANumeric<T>(newpoints, 1);
193  data = array->data();
194  exint dpt = 0;
195  for (exint i = 0; i < npoints; ++i)
196  {
197  if (points[i] > 0)
198  {
199  points[i] = dpt; // Old point to new point index
200  data[dpt] = i; // New point to old point index
201  dpt++;
202  }
203  }
204  return GT_DataArrayHandle(array);
205  }
206 
207  template <typename T>
209  const GT_DataArrayHandle &vtx)
210  {
211  GT_DANumeric<T> *array;
212  T *data;
213  GT_Size nvtx = vtx->entries();
214 
215  array = new GT_DANumeric<T>(nvtx, 1);
216  data = array->data();
217  for (exint i = 0; i < nvtx; ++i)
218  {
219  GT_Size voff = vtx->getI64(i);
220  UT_ASSERT_P(points[voff] >= 0);
221  data[i] = points[voff];
222  }
223  return GT_DataArrayHandle(array);
224  }
225 
226 
227  static GT_PrimitiveHandle optimizePolyMeshForGL(
228  const GT_PrimitiveHandle &mesh,
229  const GU_ConstDetailHandle &parent_dtl,
230  const UT_Array<int> *bone_index_remap = nullptr);
231  static GT_PrimitiveHandle optimizeCurveMeshForGL(
232  const GT_PrimitiveHandle &mesh,
233  const UT_Array<int> *bone_index_remap = nullptr);
234 
235  static void addViewportLODAttribs(const UT_Array<GEO_ViewportLOD> &lods,
236  GT_AttributeListHandle &uniform,
237  GT_AttributeListHandle &detail);
238 
239  static void addBBoxAttrib(const UT_BoundingBox &bbox,
240  GT_AttributeListHandle &detail);
241 private:
242 };
243 
244 #endif
GT_Storage
Definition: GT_Types.h:19
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GLenum GLint * range
Definition: glcorearb.h:1925
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
A mesh of polygons.
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GLboolean * data
Definition: glcorearb.h:131
#define GT_API
Definition: GT_API.h:13
int64 exint
Definition: SYS_Types.h:125
GT_Type
Definition: GT_Types.h:36
T * data() const
Raw access to the data array.
Definition: GT_DANumeric.h:130
**But if you need a result
Definition: thread.h:613
A range of elements in an index-map.
Definition: GA_Range.h:42
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
static GT_DataArrayHandle buildPointIndirect(GT_Size *points, GT_Size npoints, GT_Size newpoints)
Definition: GT_Util.h:186
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GA_TypeInfo
Definition: GA_Types.h:101
int64 GT_Size
Definition: GT_Types.h:128
GA_AttributeOwner
Definition: GA_Types.h:35
static GT_DataArrayHandle buildVertexIndirect(const GT_Size *points, const GT_DataArrayHandle &vtx)
Definition: GT_Util.h:208
An array of numeric values (int32, int64, fpreal16, fpreal32, fpreal64)
Definition: GT_DANumeric.h:23
Trim loops specified by a number of individual NURBS curves.
type
Definition: core.h:1059
GA_Storage
Definition: GA_Types.h:51