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;
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 getPointIndex(const GT_Primitive &prim,
134  const GU_Detail &parent_detail,
135  int npoints);
136  static GT_DataArrayHandle getPointIndex(const GT_Primitive &prim,
137  const GU_ConstDetailHandle &geo,
138  int npoints);
139 
140  static GT_DataArrayHandle getPointOffset(const GT_Primitive &prim,
141  const GU_Detail &parent_detail,
142  int npoints);
143  static GT_DataArrayHandle getPointOffset(const GT_Primitive &prim,
144  const GU_ConstDetailHandle &geo,
145  int npoints);
146 
147  /// Return an array of the primitive IDs (in GA_Index's).
148  /// If 'use_nested' is true, attempt to find __nested_prim_id first, then
149  /// fall back to __primitive_id.
150  static GT_DataArrayHandle getPrimitiveIndex(const GT_Primitive &prim,
151  const GU_Detail &parent_dtl,
152  bool use_nested = false);
153  static GT_DataArrayHandle getPrimitiveIndex(const GT_Primitive &prim,
154  const GU_ConstDetailHandle &pdtl,
155  bool use_nested = false);
156 
157  static GT_DataArrayHandle getPrimitiveOffset(const GT_Primitive &prim,
158  const GU_Detail &parent_dtl,
159  bool use_nested = false);
160  static GT_DataArrayHandle getPrimitiveOffset(const GT_Primitive &prim,
161  const GU_ConstDetailHandle &pdtl,
162  bool use_nested = false);
163 
164  template <typename T>
166  GT_Size npoints,
167  GT_Size newpoints)
168  {
169  GT_DANumeric<T> *array;
170  T *data;
171  array = new GT_DANumeric<T>(newpoints, 1);
172  data = array->data();
173  exint dpt = 0;
174  for (exint i = 0; i < npoints; ++i)
175  {
176  if (points[i] > 0)
177  {
178  points[i] = dpt; // Old point to new point index
179  data[dpt] = i; // New point to old point index
180  dpt++;
181  }
182  }
183  return GT_DataArrayHandle(array);
184  }
185 
186  template <typename T>
188  const GT_DataArrayHandle &vtx)
189  {
190  GT_DANumeric<T> *array;
191  T *data;
192  GT_Size nvtx = vtx->entries();
193 
194  array = new GT_DANumeric<T>(nvtx, 1);
195  data = array->data();
196  for (exint i = 0; i < nvtx; ++i)
197  {
198  GT_Size voff = vtx->getI64(i);
199  UT_ASSERT_P(points[voff] >= 0);
200  data[i] = points[voff];
201  }
202  return GT_DataArrayHandle(array);
203  }
204 
205 
206  static GT_PrimitiveHandle optimizePolyMeshForGL(
207  const GT_PrimitiveHandle &mesh,
208  GU_ConstDetailHandle &parent_dtl);
209 
210  static void addViewportLODAttribs(const UT_Array<GEO_ViewportLOD> &lods,
211  GT_AttributeListHandle &uniform,
212  GT_AttributeListHandle &detail);
213 
214  static void addBBoxAttrib(const UT_BoundingBox &bbox,
215  GT_AttributeListHandle &detail);
216 private:
217 };
218 
219 #endif
GT_Storage
Definition: GT_Types.h:17
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
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:33
T * data() const
Raw access to the data array.
Definition: GT_DANumeric.h:127
png_uint_32 i
Definition: png.h:2877
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:116
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:125
static GT_DataArrayHandle buildPointIndirect(GT_Size *points, GT_Size npoints, GT_Size newpoints)
Definition: GT_Util.h:165
GLboolean * data
Definition: glcorearb.h:130
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GA_TypeInfo
Definition: GA_Types.h:80
static GT_DataArrayHandle buildVertexIndirect(const GT_Size *points, const GT_DataArrayHandle &vtx)
Definition: GT_Util.h:187
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:112
Trim loops specified by a number of individual NURBS curves.
GA_Storage
Definition: GA_Types.h:48