HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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;
31 
33 {
34 public:
35  /// Create a list of geometry details. Each refined primitive is stored in
36  /// a separate detail.
37  /// Refine parameters include:
38  /// - bool "gconvert:include_ids" (default: false)@n
39  /// Keep the __vertex_id and __primitive_id attributes in conversion
40  /// - bool "gconvert:particleprim" (default: false)@n
41  /// Convert point mesh primitives to a particle primitive. If off, the
42  /// detail will just contain points (no primitives).
43  /// - bool "gconvert:pack" (default: false) @n
44  /// Each primitive will be packed into a packed primitive, meaning the
45  /// list of returned details will each have a single packed primitive.
46  static void makeGEO(UT_Array<GU_Detail *> &result,
47  const GT_PrimitiveHandle &prim,
48  const GT_RefineParms *rparms = NULL,
49  int segment = 0);
50  /// Create a list of geometry details for a single GT primitive. Each
51  /// refined primitive is stored in a separate detail. These details must be
52  /// deleted by the caller.
53  static void makeGEO(UT_Array<GU_Detail *> &result,
54  const GT_Primitive &prim,
55  const GT_RefineParms *rparms = NULL,
56  int segment = 0);
57 
58  /// Create a list of geometry details, but return the result in an array of
59  /// GU_DetailHandle's. Each primitive's refined geometry is stored in a
60  /// separate detail.
61  ///
62  /// Refine parameters include:
63  /// - bool "gconvert:include_ids" (default: false)@n
64  /// Keep the __vertex_id and __primitive_id attributes in conversion
65  /// - bool "gconvert:particleprim" (default: false)@n
66  /// Convert point mesh primitives to a particle primitive. If off, the
67  /// detail will just contain points (no primitives).
68  static void makeGEO(UT_Array<GU_DetailHandle> &result,
69  const GT_PrimitiveHandle &prim,
70  const GT_RefineParms *parms = NULL,
71  int segment = 0);
72  /// Create a list of geometry details for a single GT primitive. Each
73  /// refined primitive is stored in a separate detail.
74  static void makeGEO(UT_Array<GU_DetailHandle> &result,
75  const GT_Primitive &prim,
76  const GT_RefineParms *rparms = NULL,
77  int segment = 0);
78 
79 
80  /// Test whether a primitive is atomic (i.e. converts to a single gdp)
81  static bool isSimpleGEO(const GT_Primitive &prim,
82  const GT_RefineParms *rparms = NULL);
83 
84  /// Convert a GT_TrimNuCurves primitive to a GD_Detail for trim curves
85  static void makeGD(GD_Detail &gdp, const GT_TrimNuCurves &curves);
86 
87  /// Map from GA_Type info to a GT_Type info
88  static GT_Type getType(GA_TypeInfo type);
89 
90  /// Map from GT_Type to GA_TypeInfo
91  static GA_TypeInfo getGAType(GT_Type type);
92 
93  /// Map from GA_Storage to GT_Storage
94  static GT_Storage getStorage(GA_Storage storage);
95 
96  /// Map from GT_Storage to GA_Storage
97  static GA_Storage getGAStorage(GT_Storage storage);
98 
99  /// Extract a data array from a GA attribute
100  static GT_DataArrayHandle extractAttribute(const GA_Attribute &attrib,
101  const GA_Range &range);
102 
103  /// Some software represents crease weights as a list of edges and
104  /// sharpnesses, or corners and sharpnesses. This code will look for the
105  /// Houdini "crease" attributes and map them to edge or corner crease
106  /// weights. Edge creases are specified by two indices and a single
107  /// sharpneess (i.e. the length of @c edge_indices will be twice the length
108  /// of @c edge_sharpness). @n
109  /// Each index (edge or corner) refers to a vertex in the vertex list. @n
110  /// @note: This function relies on being able to find the __primitive_id
111  /// and __vertex_id attributes on the polygon mesh to evaluate the @c
112  /// creaseweight attribute.
113  /// @note: You only need a GT_PrimPolygonMesh to compute creases...
114  /// GT_PrimSubdivisionMesh is a sub-class of GT_PrimPolygonMesh.
115  static bool computeSubdivisionCreases(const GU_Detail &gdp,
116  const GT_PrimPolygonMesh &polymesh,
117  GT_DataArrayHandle &edge_indices,
118  GT_DataArrayHandle &edge_sharpnesses,
119  GT_DataArrayHandle &corner_indices,
120  GT_DataArrayHandle &corner_sharpnesses,
121  GT_DataArrayHandle &hole_indices);
122  /// This version of @c computeSubdivisionCreases() looks for uniform or
123  /// vertex attributes named "creaseweight" on the GT_PrimPolygonMesh.
124  static bool computeSubdivisionCreases(
125  const GT_PrimPolygonMesh &polymesh,
126  GT_DataArrayHandle &edge_indices,
127  GT_DataArrayHandle &edge_sharpnesses,
128  GT_DataArrayHandle &corner_indices,
129  GT_DataArrayHandle &corner_sharpnesses,
130  GT_DataArrayHandle &hole_indices);
131 
132  /// Return an array of the point IDs of the primitives (in GA_Index's).
133  static GT_DataArrayHandle getPointID(const GT_Primitive &prim,
134  const GU_Detail &parent_detail,
135  int npoints);
136  static GT_DataArrayHandle getPointID(const GT_Primitive &prim,
137  const GU_ConstDetailHandle &parent,
138  int npoints);
139 
140  /// Return an array of the primitive IDs (in GA_Index's).
141  /// If 'use_nested' is true, attempt to find __nested_prim_id first, then
142  /// fall back to __primitive_id.
143  static GT_DataArrayHandle getPrimitiveID(const GT_Primitive &prim,
144  const GU_Detail &parent_detail,
145  bool use_nested = false);
146  static GT_DataArrayHandle getPrimitiveID(const GT_Primitive &prim,
147  const GU_ConstDetailHandle &parent,
148  bool use_nested = false);
149 
150  template <typename T>
152  GT_Size npoints,
153  GT_Size newpoints)
154  {
155  GT_DANumeric<T> *array;
156  T *data;
157  array = new GT_DANumeric<T>(newpoints, 1);
158  data = array->data();
159  exint dpt = 0;
160  for (exint i = 0; i < npoints; ++i)
161  {
162  if (points[i] > 0)
163  {
164  points[i] = dpt; // Old point to new point index
165  data[dpt] = i; // New point to old point index
166  dpt++;
167  }
168  }
169  return GT_DataArrayHandle(array);
170  }
171 
172  template <typename T>
174  const GT_DataArrayHandle &vtx)
175  {
176  GT_DANumeric<T> *array;
177  T *data;
178  GT_Size nvtx = vtx->entries();
179 
180  array = new GT_DANumeric<T>(nvtx, 1);
181  data = array->data();
182  for (exint i = 0; i < nvtx; ++i)
183  {
184  GT_Size voff = vtx->getI64(i);
185  UT_ASSERT_P(points[voff] >= 0);
186  data[i] = points[voff];
187  }
188  return GT_DataArrayHandle(array);
189  }
190 
191 
192  static GT_PrimitiveHandle optimizePolyMeshForGL(
193  const GT_PrimitiveHandle &mesh,
194  GU_ConstDetailHandle &parent_dtl);
195 
196  static void addViewportLODAttribs(const UT_Array<GEO_ViewportLOD> &lods,
197  GT_AttributeListHandle &uniform,
198  GT_AttributeListHandle &detail);
199 
200  static void addBBoxAttrib(const UT_BoundingBox &bbox,
201  GT_AttributeListHandle &detail);
202 private:
203 };
204 
205 #endif
GT_Storage
Definition: GT_Types.h:17
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
GLenum GLint * range
Definition: glcorearb.h:1924
A mesh of polygons.
#define GT_API
Definition: GT_API.h:11
GT_Type
Definition: GT_Types.h:31
T * data() const
Raw access to the data array.
Definition: GT_DANumeric.h:127
png_uint_32 i
Definition: png.h:2877
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
A range of elements in an index-map.
Definition: GA_Range.h:42
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:30
int64 exint
Definition: SYS_Types.h:109
static GT_DataArrayHandle buildPointIndirect(GT_Size *points, GT_Size npoints, GT_Size newpoints)
Definition: GT_Util.h:151
GLboolean * data
Definition: glcorearb.h:130
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
GA_TypeInfo
Definition: GA_Types.h:80
static GT_DataArrayHandle buildVertexIndirect(const GT_Size *points, const GT_DataArrayHandle &vtx)
Definition: GT_Util.h:173
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
An array of numeric values (int32, int64, fpreal16, fpreal32, fpreal64)
Definition: GT_DANumeric.h:23
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
int64 GT_Size
Definition: GT_Types.h:109
Trim loops specified by a number of individual NURBS curves.
GA_Storage
Definition: GA_Types.h:48