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_Util.h"
33 #include "GABC_LayerOptions.h"
34 #include <Alembic/AbcGeom/All.h>
36 #include <GT/GT_Primitive.h>
37 #include <UT/UT_StringSet.h>
38 
39 namespace GABC_NAMESPACE
40 {
41 
42 class GABC_OError;
43 class GABC_OOptions;
44 class GABC_OProperty;
45 
46 /// This class will translate and output a GT_Primitive to Alembic.
47 /// Each time the update function is called, this class will write a sample
48 /// to it's Alembic object. If updateFromPrevious is called, the most recent
49 /// sample will be reused. Before either of these functions can be called, the
50 /// start function must be called to setup the Alembic OObject. Start will also
51 /// call update for the first time.
53 {
54 public:
57 
66 
70  typedef std::pair<std::string, OFaceSet *> FaceSetMapInsert;
72  /// A simple set of strings
73  class IgnoreList
74  : public UT_StringSet
75  {
76  public:
78  : UT_StringSet()
79  {}
80  IgnoreList(const char *arg0, ...);
82 
84  { insert(skip); }
86  { return erase(skip); }
87  bool contains(const UT_StringRef &token) const
88  { return count(token) > 0; }
89  };
90 
91  /// The intrinsic cache is used to cache array values frame to frame when
92  /// optimizing the .abc file for space. Only arrays which change will be
93  /// written to the file. The cache has storage for most primitive types.
95  {
96  public:
98  ~IntrinsicCache() { clear(); }
99 
100  void clear();
101 
102  /// @{
103  /// Test whether topology arrays need to be written
104  bool needVertex(const GT_DataArrayHandle &vertex_list)
105  { return needWrite(vertex_list, myVertexList); }
106  bool needCounts(const GT_DataArrayHandle &counts)
107  { return needWrite(counts, myCounts); }
108  /// @}
109 
110  /// Test to see if the attribute needs to be written (true) or whether
111  /// we can use the sample from the previous frame (false)
112  bool needWrite(const char *name, const GT_DataArrayHandle &data);
113 
114  GT_DataArrayHandle &vertexList() { return myVertexList; }
115  GT_DataArrayHandle &counts() { return myCounts; }
116  GT_DataArrayHandle &P() { return myP; }
117  GT_DataArrayHandle &Pw() { return myPw; }
118  GT_DataArrayHandle &N() { return myN; }
119  GT_DataArrayHandle &uv() { return myUV; }
120  GT_DataArrayHandle &v() { return myVel; }
121  GT_DataArrayHandle &id() { return myId; }
122  GT_DataArrayHandle &width() { return myWidth; }
123  GT_DataArrayHandle &uknots() { return myUKnots; }
124  GT_DataArrayHandle &vknots() { return myVKnots; }
125 
126  private:
127  bool needWrite(const GT_DataArrayHandle &data,
128  GT_DataArrayHandle &cache);
129  GT_DataArrayHandle myVertexList;
130  GT_DataArrayHandle myCounts;
131  GT_DataArrayHandle myP;
132  GT_DataArrayHandle myPw;
133  GT_DataArrayHandle myN;
134  GT_DataArrayHandle myUV;
135  GT_DataArrayHandle myVel;
136  GT_DataArrayHandle myId;
137  GT_DataArrayHandle myWidth;
138  GT_DataArrayHandle myUKnots;
139  GT_DataArrayHandle myVKnots;
140  };
141 
142  /// Secondary cache is used to cache values for subdivision tags and trim
143  /// curves. This is an optional cache and is only created for some
144  /// primitive types.
146  {
147  public:
149  ~SecondaryCache() { clear(); }
150 
151  /// @{
152  /// Access trim curve information
153  GT_DataArrayHandle &trimNCurves() { return myData[0]; }
154  GT_DataArrayHandle &trimN() { return myData[1]; }
155  GT_DataArrayHandle &trimOrder() { return myData[2]; }
156  GT_DataArrayHandle &trimKnot() { return myData[3]; }
157  GT_DataArrayHandle &trimMin() { return myData[4]; }
158  GT_DataArrayHandle &trimMax() { return myData[5]; }
159  GT_DataArrayHandle &trimU() { return myData[6]; }
160  GT_DataArrayHandle &trimV() { return myData[7]; }
161  GT_DataArrayHandle &trimW() { return myData[8]; }
162  /// @}
163 
164  /// Updates the cache with the current values and returns @c true if
165  /// the values have changed or @c false if the previous values can be
166  /// used. There's no way in the Alembic API to set trim components
167  /// individually.
169  { return needWrite(data, trimNCurves()); }
171  { return needWrite(data, trimN()); }
173  { return needWrite(data, trimOrder()); }
175  { return needWrite(data, trimKnot()); }
177  { return needWrite(data, trimMin()); }
179  { return needWrite(data, trimMax()); }
181  { return needWrite(data, trimU()); }
183  { return needWrite(data, trimV()); }
185  { return needWrite(data, trimW()); }
186 
187  /// @{
188  /// Access to fixed subdivision tags
189  GT_DataArrayHandle &creaseIndices() { return myData[0]; }
190  GT_DataArrayHandle &creaseLengths() { return myData[1]; }
191  GT_DataArrayHandle &creaseSharpnesses() { return myData[2]; }
192  GT_DataArrayHandle &cornerIndices() { return myData[3]; }
193  GT_DataArrayHandle &cornerSharpnesses() { return myData[4]; }
194  GT_DataArrayHandle &holeIndices() { return myData[5]; }
195  /// @}
196 
197  /// @{
198  /// Check whether subdivision tags need to be written
200  { return needWrite(data, creaseIndices()); }
201  //bool needCreaseLengths(const GT_DataArrayHandle &data)
202  //{ return needWrite(data, creaseLengths()); }
204  { return needWrite(data, creaseSharpnesses()); }
206  { return needWrite(data, cornerIndices()); }
208  { return needWrite(data, cornerSharpnesses()); }
210  { return needWrite(data, holeIndices()); }
211  /// @}
212 
213  private:
214  void clear();
215  bool needWrite(const GT_DataArrayHandle &data,
216  GT_DataArrayHandle &cache);
217  GT_DataArrayHandle myData[9];
218  };
219 
220  static const IgnoreList &getDefaultSkip();
221  static const IgnoreList &getLayerSkip();
222 
225  ~GABC_OGTGeometry();
226 
227  /// Return true if the primitive can be processed
228  static bool isPrimitiveSupported(const GT_PrimitiveHandle &prim);
229 
230  // Create the output Alembic object, as well as it's attribute and user
231  // properties (if it has them and they are to be output).
232  bool start(const GT_PrimitiveHandle &prim,
233  const OObject &parent,
234  const GABC_OOptions &ctx,
235  const GABC_LayerOptions &lopt,
236  GABC_OError &err,
238  bool outputViz = true);
239  // Output geometry, attribute, and user property samples to Alembic for the
240  // current frame.
241  bool update(const GT_PrimitiveHandle &prim,
242  const GABC_OOptions &ctx,
243  const GABC_LayerOptions &lopt,
244  GABC_OError &err,
246  // Output samples to Alembic, reusing the samples for the previous frame.
247  bool updateFromPrevious(GABC_OError &err,
249  exint frames = 1);
250 
251  /// Return the OObject for this shape
252  OObject getOObject() const;
253 
254  /// Return the user properties for this shape.
255  OCompoundProperty getUserProperties() const;
256 
257  /// Return the secondary cache (allocating if needed)
258  SecondaryCache &getSecondaryCache();
259 
260  /// Dump information
261  void dump(int indent=0) const;
262 
263 protected:
264  // Make Alembic OFaceSet objects from groups of polygons.
265  void makeFaceSets(const OObject &parent, const GT_PrimitiveHandle &prim,
266  const GABC_OOptions &ctx, const GABC_LayerOptions &lopt);
267 
268  // Make Alembic arbGeomProperties from Houdini attributes.
269  bool makeArbProperties(const GT_PrimitiveHandle &prim,
270  GABC_OError &err,
271  const GABC_OOptions &ctx,
272  const GABC_LayerOptions &lopt);
273  // Output samples of attribute data to Alembic for current frame.
274  bool writeArbProperties(const GT_PrimitiveHandle &prim,
275  GABC_OError &err,
276  const GABC_OOptions &ctx);
277  // Reuse previous samples of attribute data for current frame.
278  void writeArbPropertiesFromPrevious();
279  // Clear out existing data.
280  void clearProperties();
281  void clearArbProperties();
282  void clearFaceSets();
283  void clearShape();
284  void clearCache();
285 
286 private:
287  // Attribute scopes.
288  enum
289  {
290  VERTEX_PROPERTIES,
291  POINT_PROPERTIES,
292  UNIFORM_PROPERTIES,
293  DETAIL_PROPERTIES,
294  MAX_PROPERTIES
295  };
296 
297  union {
303  void *myVoidPtr;
304  } myShape;
305 
306  IntrinsicCache myCache; // Cache for space optimization
307  OVisibilityProperty myVisibility;
308  CollisionResolver myKnownArbCollisionResolver;
309  UT_Set<std::string> myKnownArbProperties;
310  PropertyMap myArbProperties[MAX_PROPERTIES];
311  SecondaryCache *mySecondaryCache;
312  FaceSetMap myFaceSets;
313  std::string myName;
314  exint myElapsedFrames;
315  int myType;
316  GABC_LayerOptions::LayerType myLayerNodeType;
317 };
318 
319 } // GABC_NAMESPACE
320 
321 #endif
Alembic::AbcGeom::OSubD OSubD
GABC_Util::PropertyMap PropertyMap
bool needCreaseIndices(const GT_DataArrayHandle &data)
bool needTrimKnot(const GT_DataArrayHandle &data)
bool needTrimMin(const GT_DataArrayHandle &data)
Unsorted map container.
Definition: UT_Map.h:107
void skip(T &in, int n)
Definition: ImfXdr.h:613
bool needCornerSharpnesses(const GT_DataArrayHandle &data)
GLuint start
Definition: glcorearb.h:475
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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)
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Definition: simd.h:3436
#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)
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)
GLuint const GLchar * name
Definition: glcorearb.h:786
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
bool needTrimU(const GT_DataArrayHandle &data)
bool needCounts(const GT_DataArrayHandle &counts)
Alembic::AbcGeom::ONuPatch ONuPatch
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
Alembic::AbcGeom::OPolyMesh OPolyMesh
std::pair< std::string, GABC_OProperty * > PropertyMapInsert
Definition: GABC_Util.h:70
Alembic::AbcGeom::OCurves OCurves
type
Definition: core.h:1059
GABC_Util::PropertyMapInsert PropertyMapInsert
GLint GLsizei count
Definition: glcorearb.h:405
Definition: format.h:895
GABC_Util::CollisionResolver CollisionResolver
UT_Map< std::string, OFaceSet * > FaceSetMap