HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GABC_OGTGeometry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __GABC_OGTGeometry__
29 #define __GABC_OGTGeometry__
30 
31 #include "GABC_API.h"
32 #include "GABC_Include.h"
33 #include "GABC_Util.h"
34 #include "GABC_LayerOptions.h"
35 #include <Alembic/AbcGeom/All.h>
37 #include <GT/GT_Primitive.h>
38 #include <UT/UT_StringSet.h>
39 
40 namespace GABC_NAMESPACE
41 {
42 
43 class GABC_OError;
44 class GABC_OOptions;
45 class GABC_OProperty;
46 
47 /// This class will translate and output a GT_Primitive to Alembic.
48 /// Each time the update function is called, this class will write a sample
49 /// to it's Alembic object. If updateFromPrevious is called, the most recent
50 /// sample will be reused. Before either of these functions can be called, the
51 /// start function must be called to setup the Alembic OObject. Start will also
52 /// call update for the first time.
54 {
55 public:
58 
67 
71  typedef std::pair<std::string, OFaceSet *> FaceSetMapInsert;
73  /// A simple set of strings
74  class IgnoreList
75  : public UT_StringSet
76  {
77  public:
79  : UT_StringSet()
80  {}
81  IgnoreList(const char *arg0, ...);
83 
85  { insert(skip); }
87  { return erase(skip); }
88  bool contains(const UT_StringRef &token) const
89  { return count(token) > 0; }
90  };
91 
92  /// The intrinsic cache is used to cache array values frame to frame when
93  /// optimizing the .abc file for space. Only arrays which change will be
94  /// written to the file. The cache has storage for most primitive types.
96  {
97  public:
99  ~IntrinsicCache() { clear(); }
100 
101  void clear();
102 
103  /// @{
104  /// Test whether topology arrays need to be written
105  bool needVertex(const GT_DataArrayHandle &vertex_list)
106  { return needWrite(vertex_list, myVertexList); }
107  bool needCounts(const GT_DataArrayHandle &counts)
108  { return needWrite(counts, myCounts); }
109  /// @}
110 
111  /// Test to see if the attribute needs to be written (true) or whether
112  /// we can use the sample from the previous frame (false)
113  bool needWrite(const char *name, const GT_DataArrayHandle &data);
114 
115  GT_DataArrayHandle &vertexList() { return myVertexList; }
116  GT_DataArrayHandle &counts() { return myCounts; }
117  GT_DataArrayHandle &P() { return myP; }
118  GT_DataArrayHandle &Pw() { return myPw; }
119  GT_DataArrayHandle &N() { return myN; }
120  GT_DataArrayHandle &uv() { return myUV; }
121  GT_DataArrayHandle &v() { return myVel; }
122  GT_DataArrayHandle &id() { return myId; }
123  GT_DataArrayHandle &width() { return myWidth; }
124  GT_DataArrayHandle &uknots() { return myUKnots; }
125  GT_DataArrayHandle &vknots() { return myVKnots; }
126 
127  private:
128  bool needWrite(const GT_DataArrayHandle &data,
129  GT_DataArrayHandle &cache);
130  GT_DataArrayHandle myVertexList;
131  GT_DataArrayHandle myCounts;
132  GT_DataArrayHandle myP;
133  GT_DataArrayHandle myPw;
134  GT_DataArrayHandle myN;
135  GT_DataArrayHandle myUV;
136  GT_DataArrayHandle myVel;
137  GT_DataArrayHandle myId;
138  GT_DataArrayHandle myWidth;
139  GT_DataArrayHandle myUKnots;
140  GT_DataArrayHandle myVKnots;
141  };
142 
143  /// Secondary cache is used to cache values for subdivision tags and trim
144  /// curves. This is an optional cache and is only created for some
145  /// primitive types.
147  {
148  public:
150  ~SecondaryCache() { clear(); }
151 
152  /// @{
153  /// Access trim curve information
154  GT_DataArrayHandle &trimNCurves() { return myData[0]; }
155  GT_DataArrayHandle &trimN() { return myData[1]; }
156  GT_DataArrayHandle &trimOrder() { return myData[2]; }
157  GT_DataArrayHandle &trimKnot() { return myData[3]; }
158  GT_DataArrayHandle &trimMin() { return myData[4]; }
159  GT_DataArrayHandle &trimMax() { return myData[5]; }
160  GT_DataArrayHandle &trimU() { return myData[6]; }
161  GT_DataArrayHandle &trimV() { return myData[7]; }
162  GT_DataArrayHandle &trimW() { return myData[8]; }
163  /// @}
164 
165  /// Updates the cache with the current values and returns @c true if
166  /// the values have changed or @c false if the previous values can be
167  /// used. There's no way in the Alembic API to set trim components
168  /// individually.
170  { return needWrite(data, trimNCurves()); }
172  { return needWrite(data, trimN()); }
174  { return needWrite(data, trimOrder()); }
176  { return needWrite(data, trimKnot()); }
178  { return needWrite(data, trimMin()); }
180  { return needWrite(data, trimMax()); }
182  { return needWrite(data, trimU()); }
184  { return needWrite(data, trimV()); }
186  { return needWrite(data, trimW()); }
187 
188  /// @{
189  /// Access to fixed subdivision tags
190  GT_DataArrayHandle &creaseIndices() { return myData[0]; }
191  GT_DataArrayHandle &creaseLengths() { return myData[1]; }
192  GT_DataArrayHandle &creaseSharpnesses() { return myData[2]; }
193  GT_DataArrayHandle &cornerIndices() { return myData[3]; }
194  GT_DataArrayHandle &cornerSharpnesses() { return myData[4]; }
195  GT_DataArrayHandle &holeIndices() { return myData[5]; }
196  /// @}
197 
198  /// @{
199  /// Check whether subdivision tags need to be written
201  { return needWrite(data, creaseIndices()); }
202  //bool needCreaseLengths(const GT_DataArrayHandle &data)
203  //{ return needWrite(data, creaseLengths()); }
205  { return needWrite(data, creaseSharpnesses()); }
207  { return needWrite(data, cornerIndices()); }
209  { return needWrite(data, cornerSharpnesses()); }
211  { return needWrite(data, holeIndices()); }
212  /// @}
213 
214  private:
215  void clear();
216  bool needWrite(const GT_DataArrayHandle &data,
217  GT_DataArrayHandle &cache);
218  GT_DataArrayHandle myData[9];
219  };
220 
221  static const IgnoreList &getDefaultSkip();
222  static const IgnoreList &getLayerSkip();
223 
226  ~GABC_OGTGeometry();
227 
228  /// Return true if the primitive can be processed
229  static bool isPrimitiveSupported(const GT_PrimitiveHandle &prim);
230 
231  // Create the output Alembic object, as well as it's attribute and user
232  // properties (if it has them and they are to be output).
233  bool start(const GT_PrimitiveHandle &prim,
234  const OObject &parent,
235  const GABC_OOptions &ctx,
236  const GABC_LayerOptions &lopt,
237  GABC_OError &err,
239  bool outputViz = true);
240  // Output geometry, attribute, and user property samples to Alembic for the
241  // current frame.
242  bool update(const GT_PrimitiveHandle &prim,
243  const GABC_OOptions &ctx,
244  const GABC_LayerOptions &lopt,
245  GABC_OError &err,
247  // Output samples to Alembic, reusing the samples for the previous frame.
248  bool updateFromPrevious(GABC_OError &err,
250  exint frames = 1);
251 
252  /// Return the OObject for this shape
253  OObject getOObject() const;
254 
255  /// Return the user properties for this shape.
256  OCompoundProperty getUserProperties() const;
257 
258  /// Return the secondary cache (allocating if needed)
259  SecondaryCache &getSecondaryCache();
260 
261  /// Dump information
262  void dump(int indent=0) const;
263 
264 protected:
265  // Make Alembic OFaceSet objects from groups of polygons.
266  void makeFaceSets(const OObject &parent, const GT_PrimitiveHandle &prim,
267  const GABC_OOptions &ctx, const GABC_LayerOptions &lopt);
268 
269  // Make Alembic arbGeomProperties from Houdini attributes.
270  bool makeArbProperties(const GT_PrimitiveHandle &prim,
271  GABC_OError &err,
272  const GABC_OOptions &ctx,
273  const GABC_LayerOptions &lopt);
274  // Output samples of attribute data to Alembic for current frame.
275  bool writeArbProperties(const GT_PrimitiveHandle &prim,
276  GABC_OError &err,
277  const GABC_OOptions &ctx);
278  // Reuse previous samples of attribute data for current frame.
279  void writeArbPropertiesFromPrevious();
280  // Clear out existing data.
281  void clearProperties();
282  void clearArbProperties();
283  void clearFaceSets();
284  void clearShape();
285  void clearCache();
286 
287 private:
288  // Attribute scopes.
289  enum
290  {
291  VERTEX_PROPERTIES,
292  POINT_PROPERTIES,
293  UNIFORM_PROPERTIES,
294  DETAIL_PROPERTIES,
295  MAX_PROPERTIES
296  };
297 
298  union {
304  void *myVoidPtr;
305  } myShape;
306 
307  IntrinsicCache myCache; // Cache for space optimization
308  OVisibilityProperty myVisibility;
309  CollisionResolver myKnownArbCollisionResolver;
310  UT_Set<std::string> myKnownArbProperties;
311  PropertyMap myArbProperties[MAX_PROPERTIES];
312  SecondaryCache *mySecondaryCache;
313  FaceSetMap myFaceSets;
314  std::string myName;
315  exint myElapsedFrames;
316  int myType;
317  GABC_LayerOptions::LayerType myLayerNodeType;
318 };
319 
320 } // GABC_NAMESPACE
321 
322 #endif
Alembic::AbcGeom::OSubD OSubD
GABC_Util::PropertyMap PropertyMap
vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Definition: simd.h:3340
bool needCreaseIndices(const GT_DataArrayHandle &data)
bool needTrimKnot(const GT_DataArrayHandle &data)
bool needTrimMin(const GT_DataArrayHandle &data)
GLuint const GLchar * name
Definition: glew.h:1814
Unsorted map container.
Definition: UT_Map.h:83
void skip(T &in, int n)
Definition: ImfXdr.h:885
bool needCornerSharpnesses(const GT_DataArrayHandle &data)
bool contains(const UT_StringRef &token) const
bool needTrimNCurves(const GT_DataArrayHandle &data)
int64 exint
Definition: SYS_Types.h:125
bool needTrimW(const GT_DataArrayHandle &data)
#define GABC_NAMESPACE
Definition: GABC_API.h:42
std::pair< std::string, OFaceSet * > FaceSetMapInsert
Alembic::AbcGeom::ObjectVisibility ObjectVisibility
bool needCornerIndices(const GT_DataArrayHandle &data)
bool needTrimV(const GT_DataArrayHandle &data)
The object has been explicitly made hidden.
Definition: Visibility.h:70
void addSkip(const UT_StringHolder &skip)
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
bool deleteSkip(const UT_StringRef &skip)
bool needVertex(const GT_DataArrayHandle &vertex_list)
bool needTrimN(const GT_DataArrayHandle &data)
Alembic::AbcGeom::OVisibilityProperty OVisibilityProperty
bool needTrimOrder(const GT_DataArrayHandle &data)
bool needCreaseSharpnesses(const GT_DataArrayHandle &data)
Alembic::AbcGeom::OPoints OPoints
Class to efficiently find a new name when a collision is detected.
Definition: GABC_Util.h:377
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GLuint start
Definition: glew.h:1253
bool needTrimU(const GT_DataArrayHandle &data)
bool needCounts(const GT_DataArrayHandle &counts)
Alembic::AbcGeom::ONuPatch ONuPatch
GLsizei const GLchar *const * string
Definition: glew.h:1844
bool needTrimMax(const GT_DataArrayHandle &data)
bool needHoleIndices(const GT_DataArrayHandle &data)
ObjectVisibility
Values for the visibility property The top-compound object of AbcGeom Schema objects can include an o...
Definition: Visibility.h:60
Alembic::AbcGeom::OFaceSet OFaceSet
Alembic::Abc::OCompoundProperty OCompoundProperty
Abc::OCharProperty OVisibilityProperty
Definition: Visibility.h:81
#define GABC_API
Definition: GABC_API.h:37
GLuint GLuint GLsizei count
Definition: glew.h:1253
Alembic::AbcGeom::OPolyMesh OPolyMesh
std::pair< std::string, GABC_OProperty * > PropertyMapInsert
Definition: GABC_Util.h:71
Alembic::AbcGeom::OCurves OCurves
GABC_Util::PropertyMapInsert PropertyMapInsert
GABC_Util::CollisionResolver CollisionResolver
UT_Map< std::string, OFaceSet * > FaceSetMap