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 GABC_OOptions &ctx,
106  const GT_DataArrayHandle &vertex_list)
107  { return needWrite(ctx, vertex_list, myVertexList); }
108  bool needCounts(const GABC_OOptions &ctx,
109  const GT_DataArrayHandle &counts)
110  { return needWrite(ctx, counts, myCounts); }
111  /// @}
112 
113  /// Test to see if the attribute needs to be written (true) or whether
114  /// we can use the sample from the previous frame (false)
115  bool needWrite(const GABC_OOptions &ctx,
116  const char *name, const GT_DataArrayHandle &data);
117 
118  GT_DataArrayHandle &vertexList() { return myVertexList; }
119  GT_DataArrayHandle &counts() { return myCounts; }
120  GT_DataArrayHandle &P() { return myP; }
121  GT_DataArrayHandle &Pw() { return myPw; }
122  GT_DataArrayHandle &N() { return myN; }
123  GT_DataArrayHandle &uv() { return myUV; }
124  GT_DataArrayHandle &v() { return myVel; }
125  GT_DataArrayHandle &id() { return myId; }
126  GT_DataArrayHandle &width() { return myWidth; }
127  GT_DataArrayHandle &uknots() { return myUKnots; }
128  GT_DataArrayHandle &vknots() { return myVKnots; }
129 
130  private:
131  bool needWrite(const GABC_OOptions &ctx,
132  const GT_DataArrayHandle &data,
133  GT_DataArrayHandle &cache);
134  GT_DataArrayHandle myVertexList;
135  GT_DataArrayHandle myCounts;
136  GT_DataArrayHandle myP;
137  GT_DataArrayHandle myPw;
138  GT_DataArrayHandle myN;
139  GT_DataArrayHandle myUV;
140  GT_DataArrayHandle myVel;
141  GT_DataArrayHandle myId;
142  GT_DataArrayHandle myWidth;
143  GT_DataArrayHandle myUKnots;
144  GT_DataArrayHandle myVKnots;
145  };
146 
147  /// Secondary cache is used to cache values for subdivision tags and trim
148  /// curves. This is an optional cache and is only created for some
149  /// primitive types.
151  {
152  public:
154  ~SecondaryCache() { clear(); }
155 
156  /// @{
157  /// Access trim curve information
158  GT_DataArrayHandle &trimNCurves() { return myData[0]; }
159  GT_DataArrayHandle &trimN() { return myData[1]; }
160  GT_DataArrayHandle &trimOrder() { return myData[2]; }
161  GT_DataArrayHandle &trimKnot() { return myData[3]; }
162  GT_DataArrayHandle &trimMin() { return myData[4]; }
163  GT_DataArrayHandle &trimMax() { return myData[5]; }
164  GT_DataArrayHandle &trimU() { return myData[6]; }
165  GT_DataArrayHandle &trimV() { return myData[7]; }
166  GT_DataArrayHandle &trimW() { return myData[8]; }
167  /// @}
168 
169  /// Updates the cache with the current values and returns @c true if
170  /// the values have changed or @c false if the previous values can be
171  /// used. There's no way in the Alembic API to set trim components
172  /// individually.
174  const GT_DataArrayHandle &data)
175  {
176  { return needWrite(ctx, data, trimNCurves()); }
177  }
178  bool needTrimN(const GABC_OOptions &ctx,
179  const GT_DataArrayHandle &data)
180  {
181  { return needWrite(ctx, data, trimN()); }
182  }
183  bool needTrimOrder(const GABC_OOptions &ctx,
184  const GT_DataArrayHandle &data)
185  {
186  { return needWrite(ctx, data, trimOrder()); }
187  }
188  bool needTrimKnot(const GABC_OOptions &ctx,
189  const GT_DataArrayHandle &data)
190  {
191  { return needWrite(ctx, data, trimKnot()); }
192  }
193  bool needTrimMin(const GABC_OOptions &ctx,
194  const GT_DataArrayHandle &data)
195  {
196  { return needWrite(ctx, data, trimMin()); }
197  }
198  bool needTrimMax(const GABC_OOptions &ctx,
199  const GT_DataArrayHandle &data)
200  {
201  { return needWrite(ctx, data, trimMax()); }
202  }
203  bool needTrimU(const GABC_OOptions &ctx,
204  const GT_DataArrayHandle &data)
205  {
206  { return needWrite(ctx, data, trimU()); }
207  }
208  bool needTrimV(const GABC_OOptions &ctx,
209  const GT_DataArrayHandle &data)
210  {
211  { return needWrite(ctx, data, trimV()); }
212  }
213  bool needTrimW(const GABC_OOptions &ctx,
214  const GT_DataArrayHandle &data)
215  {
216  { return needWrite(ctx, data, trimW()); }
217  }
218 
219  /// @{
220  /// Access to fixed subdivision tags
221  GT_DataArrayHandle &creaseIndices() { return myData[0]; }
222  GT_DataArrayHandle &creaseLengths() { return myData[1]; }
223  GT_DataArrayHandle &creaseSharpnesses() { return myData[2]; }
224  GT_DataArrayHandle &cornerIndices() { return myData[3]; }
225  GT_DataArrayHandle &cornerSharpnesses() { return myData[4]; }
226  GT_DataArrayHandle &holeIndices() { return myData[5]; }
227  /// @}
228 
229  /// @{
230  /// Check whether subdivision tags need to be written
232  const GT_DataArrayHandle &data)
233  { return needWrite(ctx, data, creaseIndices()); }
235  const GT_DataArrayHandle &data)
236  { return needWrite(ctx, data, creaseLengths()); }
238  const GT_DataArrayHandle &data)
239  { return needWrite(ctx, data, creaseSharpnesses()); }
241  const GT_DataArrayHandle &data)
242  { return needWrite(ctx, data, cornerIndices()); }
244  const GT_DataArrayHandle &data)
245  { return needWrite(ctx, data, cornerSharpnesses()); }
247  const GT_DataArrayHandle &data)
248  { return needWrite(ctx, data, holeIndices()); }
249  /// @}
250 
251  private:
252  void clear();
253  bool needWrite(const GABC_OOptions &ctx,
254  const GT_DataArrayHandle &data,
255  GT_DataArrayHandle &cache);
256  GT_DataArrayHandle myData[9];
257  };
258 
259  static const IgnoreList &getDefaultSkip();
260  static const IgnoreList &getLayerSkip();
261 
264  ~GABC_OGTGeometry();
265 
266  /// Return true if the primitive can be processed
267  static bool isPrimitiveSupported(const GT_PrimitiveHandle &prim);
268 
269  // Create the output Alembic object, as well as it's attribute and user
270  // properties (if it has them and they are to be output).
271  bool start(const GT_PrimitiveHandle &prim,
272  const OObject &parent,
273  const GABC_OOptions &ctx,
274  const GABC_LayerOptions &lopt,
275  GABC_OError &err,
277  bool outputViz = true);
278  // Output geometry, attribute, and user property samples to Alembic for the
279  // current frame.
280  bool update(const GT_PrimitiveHandle &prim,
281  const GABC_OOptions &ctx,
282  const GABC_LayerOptions &lopt,
283  GABC_OError &err,
285  // Output samples to Alembic, reusing the samples for the previous frame.
286  bool updateFromPrevious(GABC_OError &err,
288  exint frames = 1);
289 
290  /// Return the OObject for this shape
291  OObject getOObject() const;
292 
293  /// Return the user properties for this shape.
294  OCompoundProperty getUserProperties() const;
295 
296  /// Return the secondary cache (allocating if needed)
297  SecondaryCache &getSecondaryCache();
298 
299  /// Dump information
300  void dump(int indent=0) const;
301 
302 protected:
303  // Make Alembic OFaceSet objects from groups of polygons.
304  void makeFaceSets(const OObject &parent, const GT_PrimitiveHandle &prim,
305  const GABC_OOptions &ctx, const GABC_LayerOptions &lopt);
306 
307  // Make Alembic arbGeomProperties from Houdini attributes.
308  bool makeArbProperties(const GT_PrimitiveHandle &prim,
309  GABC_OError &err,
310  const GABC_OOptions &ctx,
311  const GABC_LayerOptions &lopt);
312  // Output samples of attribute data to Alembic for current frame.
313  bool writeArbProperties(const GT_PrimitiveHandle &prim,
314  GABC_OError &err,
315  const GABC_OOptions &ctx);
316  // Reuse previous samples of attribute data for current frame.
317  void writeArbPropertiesFromPrevious();
318  // Clear out existing data.
319  void clearProperties();
320  void clearArbProperties();
321  void clearFaceSets();
322  void clearShape();
323  void clearCache();
324 
325 private:
326  // Attribute scopes.
327  enum
328  {
329  VERTEX_PROPERTIES,
330  POINT_PROPERTIES,
331  UNIFORM_PROPERTIES,
332  DETAIL_PROPERTIES,
333  MAX_PROPERTIES
334  };
335 
336  union {
342  void *myVoidPtr;
343  } myShape;
344 
345  IntrinsicCache myCache; // Cache for space optimization
346  OVisibilityProperty myVisibility;
347  CollisionResolver myKnownArbCollisionResolver;
348  UT_Set<std::string> myKnownArbProperties;
349  PropertyMap myArbProperties[MAX_PROPERTIES];
350  SecondaryCache *mySecondaryCache;
351  FaceSetMap myFaceSets;
352  std::string myName;
353  exint myElapsedFrames;
354  int myType;
355  GABC_LayerOptions::LayerType myLayerNodeType;
356 };
357 
358 } // GABC_NAMESPACE
359 
360 #endif
Alembic::AbcGeom::OSubD OSubD
GABC_Util::PropertyMap PropertyMap
bool needTrimMin(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needTrimOrder(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
Unsorted map container.
Definition: UT_Map.h:83
void skip(T &in, int n)
Definition: ImfXdr.h:885
GLuint start
Definition: glcorearb.h:474
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
bool contains(const UT_StringRef &token) const
bool needTrimNCurves(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needTrimU(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needVertex(const GABC_OOptions &ctx, const GT_DataArrayHandle &vertex_list)
#define GABC_NAMESPACE
Definition: GABC_API.h:42
std::pair< std::string, OFaceSet * > FaceSetMapInsert
Alembic::AbcGeom::ObjectVisibility ObjectVisibility
The object has been explicitly made hidden.
Definition: Visibility.h:70
void addSkip(const UT_StringHolder &skip)
int64 exint
Definition: SYS_Types.h:116
bool deleteSkip(const UT_StringRef &skip)
bool needHoleIndices(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needTrimN(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
Alembic::AbcGeom::OVisibilityProperty OVisibilityProperty
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
Alembic::AbcGeom::OPoints OPoints
Class to efficiently find a new name when a collision is detected.
Definition: GABC_Util.h:377
GLint GLsizei count
Definition: glcorearb.h:404
bool needCounts(const GABC_OOptions &ctx, const GT_DataArrayHandle &counts)
Alembic::AbcGeom::ONuPatch ONuPatch
bool needTrimW(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needCreaseSharpnesses(const GABC_OOptions &ctx, 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
bool needCreaseLengths(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
Alembic::Abc::OCompoundProperty OCompoundProperty
Abc::OCharProperty OVisibilityProperty
Definition: Visibility.h:81
#define GABC_API
Definition: GABC_API.h:37
bool needCreaseIndices(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
Alembic::AbcGeom::OPolyMesh OPolyMesh
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
bool needTrimV(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
std::pair< std::string, GABC_OProperty * > PropertyMapInsert
Definition: GABC_Util.h:71
Alembic::AbcGeom::OCurves OCurves
bool needCornerSharpnesses(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needCornerIndices(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
GABC_Util::PropertyMapInsert PropertyMapInsert
bool needTrimMax(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
bool needTrimKnot(const GABC_OOptions &ctx, const GT_DataArrayHandle &data)
GABC_Util::CollisionResolver CollisionResolver
UT_Map< std::string, OFaceSet * > FaceSetMap