All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_Utils.h
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef __GUSD_GT_UTILS_H__
25 #define __GUSD_GT_UTILS_H__
26 
27 #include "gusd/api.h"
28 
29 #include <GT/GT_Primitive.h>
30 #include <GEO/GEO_Primitive.h>
31 #include <UT/UT_Map.h>
32 #include <UT/UT_Options.h>
33 #include <UT/UT_Set.h>
34 #include <UT/UT_Variadic.h>
35 
36 #include "pxr/pxr.h"
37 #include "pxr/base/gf/half.h"
38 #include "pxr/usd/usd/common.h"
39 #include "pxr/usd/usd/timeCode.h"
40 
41 #include <boost/function.hpp>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 class GfMatrix4d;
46 class GusdContext;
47 class SdfPath;
48 class SdfValueTypeName;
49 class TfToken;
50 class UsdAttribute;
51 class UsdGeomBoundable;
52 class UsdGeomImageable;
53 class UsdGeomXformable;
54 
55 //------------------------------------------------------------------------------
56 // class GusdGT_AttrFilter
57 //------------------------------------------------------------------------------
58 class GusdGT_AttrFilter
59 {
60 public:
61  typedef UT_VariadicT<GT_Owner> OwnerArgs;
62 
63 public:
64 
65  GUSD_API
66  explicit GusdGT_AttrFilter(const std::string& pattern="*");
67 
68  GUSD_API
69  GusdGT_AttrFilter( const GusdGT_AttrFilter& rhs );
70 
71  GUSD_API
72  void setPattern(GT_Owner owner, const std::string& pattern);
73 
74  GUSD_API
75  void appendPattern(GT_Owner owner, const std::string& pattern);
76 
77  GUSD_API
78  bool matches(const std::string& str) const;
79 
80  GUSD_API
81  void setActiveOwners(const OwnerArgs& owners) const;
82 
83 private:
84  UT_Map<GT_Owner, std::string> m_patterns;
85 
86  std::string m_overridePattern;
87 
88  mutable OwnerArgs m_activeOwners;
89 };
90 
91 //------------------------------------------------------------------------------
92 // class GusdGT_Utils
93 //------------------------------------------------------------------------------
94 class GusdGT_Utils
95 {
96 public:
97  enum TransformLevel {
98  TransformLevelObject,
99  TransformLevelIntrinsic,
100 
101  TransformLevelCount
102  };
103 
104 public:
105 
107  static GT_Type getType(const SdfValueTypeName& typeName);
108 
110  static TfToken getRole(GT_Type type);
111 
112  static bool setUsdAttribute(const UsdAttribute& destAttr,
113  const GT_DataArrayHandle& sourceAttr,
115 
116  static GT_DataArrayHandle getExtentsArray(const GT_PrimitiveHandle& gtPrim);
117 
118  static bool setPrimvarSample( const UsdGeomImageable& usdPrim,
119  const TfToken &name,
120  const GT_DataArrayHandle& data,
121  const TfToken& interpolation,
122  UsdTimeCode time );
123 
124  static bool isDataConstant( const GT_DataArrayHandle& data );
125 
126  static void setCustomAttributesFromGTPrim(
127  const UsdGeomImageable &usdGeomPrim,
128  const GT_AttributeListHandle& gtAttrs,
129  std::set<std::string>& excludeSet,
131 
132 
133  // TODO remove
134  static bool setTransformFromGTArray(const UsdGeomXformable& usdGeom,
135  const GT_DataArrayHandle& xform,
136  const TransformLevel transformLevel,
138 
139  static GT_DataArrayHandle
140  getTransformArray(const GT_PrimitiveHandle& gtPrim);
141 
142  static GT_DataArrayHandle
143  getPackedTransformArray(const GT_PrimitiveHandle& gtPrim);
144 
145  static GfMatrix4d getMatrixFromGTArray(const GT_DataArrayHandle& xform);
146 
147  static GT_DataArrayHandle
148  transformPoints(
149  GT_DataArrayHandle pts,
150  const GfMatrix4d& objXform );
151 
152  static GT_DataArrayHandle
153  transformPoints(
154  GT_DataArrayHandle pts,
155  const UT_Matrix4D& objXform );
156 
157  static GT_AttributeListHandle
158  getAttributesFromPrim( const GEO_Primitive *prim );
159 
160  static std::string
161  makeValidIdentifier(const TfToken& usdFilePath, const SdfPath& nodePath);
162 
163 
166  template <typename T>
168 };
169 //------------------------------------------------------------------------------
170 
171 
172 template <>
173 struct GusdGT_Utils::StorageByType<bool>
174 { static const GT_Storage value = GT_STORE_UINT8; };
175 
176 template <>
177 struct GusdGT_Utils::StorageByType<uint8>
178 { static const GT_Storage value = GT_STORE_UINT8; };
179 
180 #if SYS_VERSION_FULL_INT >= 0x11000000
181 template <>
182 struct GusdGT_Utils::StorageByType<int8>
183 { static const GT_Storage value = GT_STORE_INT8; };
184 
185 template <>
186 struct GusdGT_Utils::StorageByType<int16>
187 { static const GT_Storage value = GT_STORE_INT16; };
188 #endif
189 
190 template <>
191 struct GusdGT_Utils::StorageByType<int32>
192 { static const GT_Storage value = GT_STORE_INT32; };
193 
194 template <>
195 struct GusdGT_Utils::StorageByType<int64>
196 { static const GT_Storage value = GT_STORE_INT64; };
197 
198 template <>
199 struct GusdGT_Utils::StorageByType<fpreal16>
200 { static const GT_Storage value = GT_STORE_REAL16; };
201 
202 template <>
204 { static const GT_Storage value = GT_STORE_REAL16; };
205 
206 template <>
207 struct GusdGT_Utils::StorageByType<fpreal32>
208 { static const GT_Storage value = GT_STORE_REAL32; };
209 
210 template <>
211 struct GusdGT_Utils::StorageByType<fpreal64>
212 { static const GT_Storage value = GT_STORE_REAL64; };
213 
214 PXR_NAMESPACE_CLOSE_SCOPE
215 
216 #endif // __GUSD_GT_UTILS_H__
217 
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:42
Represents a value type name, i.e.
Definition: valueTypeName.h:83
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Boundable introduces the ability for a prim to persistently cache a rectilinear, local-space, extent.
Definition: boundable.h:82
A GusdContext structure is created by the ROPs that write USD files and passed to the GusdPrimWrapper...
Definition: context.h:46
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Struct for querying storage by POD type.
Definition: GT_Utils.h:167
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
Base class for all prims that may require rendering or visualization of some sort.
Definition: imageable.h:74
Base class for all transformable prims, which allows arbitrary sequences of component affine transfor...
Definition: xformable.h:252