1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
4 //  Sony Pictures Imageworks, Inc. and
5 //  Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // *       Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // *       Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // *       Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36 
37 #ifndef Alembic_AbcGeom_GeometryScope_h
38 #define Alembic_AbcGeom_GeometryScope_h
39 
40 #include <Alembic/Util/Export.h>
41 #include <Alembic/AbcGeom/Foundation.h>
42 
43 namespace Alembic {
44 namespace AbcGeom {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
48 //! "GeometryScope" is the name we use for what is called Primitive Variable
49 //! Class in the Renderman Interface. "Primitive Variable Class" is a bit
50 //! non-descriptive in a geometry caching context, so we use the somewhat
51 //! more meaningful (but still admittedly vague) "GeometryScope".
52 //! Below is a table reproduced from PRMan Application Note #22
53 //! describing what each of these labels means for different types
54 //! of geometry.
55 //-*****************************************************************************
56 
57 //-*****************************************************************************
58 //! From Prman Application Note #22 (and Prman Application Note #19)
59 //! For every geometric prim, there is 1 value for "constant" geometry scope.
60 //! To save space in my little table here, I'll leave out the "constant" column
61 //! but just imagine it with a big happy column of '1's.
62 //!
63 //!-----------------------------------------------------------------------------
64 //! QUADRIC & POLYGON SURFACE PRIMITIVES                                       |
65 //! Surface Primitive     | Uniform | Varying | Vertex  | Facevarying          |
66 //!-----------------------|---------|---------|---------|----------------------|
67 //! Quadrics              | 1       | 4       | 4       | 4                    |
68 //! Polygon               | 1       | nverts  | nverts  | nverts               |
69 //! GeneralPolygon        | 1       | nverts  | nverts  | nverts               |
70 //! PointsPolygons        | npolys  | nverts  | nverts  | sum(nvertices_i)     |
71 //! PointsGeneralPolygons | npolys  | nverts  | nverts  | sum(nvertices_i)     |
72 //! Points                | 1       | npoints | npoints | npoints              |
73 //! SubdivisionMesh       | nfaces  | nverts  | nverts  | sum(nvertices_i)     |
74 //!-----------------------------------------------------------------------------
75 //!
76 //!-----------------------------------------------------------------------------
77 //! PARAMETRIC SURFACE PRIMITIVES                                              |
78 //! Surface Primitive  | Uniform         | Varying and      | Vertex           |
79 //!                    |                 |  Facevarying     |                  |
80 //!--------------------|-----------------|------------------|------------------|
81 //! Patch bilinear     | 1               | 4                | 4                |
82 //! Patch bicubic      | 1               | 4                | 16               |
83 //! PatchMesh bilinear | (nu-unowrap)*   | nu*nv            | nu*nv            |
84 //!                    |   (nv-vnowrap)  |                  |                  |
85 //! PatchMesh bicubic  | usegs * vsegs   | (usegs+unowrap)* | nu*nv            |
86 //!                    |                 |  (vsegs+vnowrap) |                  |
87 //! NuPatch            | (nu-uorder+1)*  | (nu-uorder+2)*   | nu*nv            |
88 //!                    |   (nv-vorder+1) |  (nv-vorder+2)   |                  |
89 //! Curves linear      | ncurves         | sum(nvertices_i) | sum(nvertices_i) |
90 //! Curves cubic       | ncurves         | sum(nsegs_i      | sum(nvertices_i) |
91 //!                    |                 |     +nowrap)     |                  |
92 //! Blobby             |  1              | nleaf            | nleaf            |
93 //!-----------------------------------------------------------------------------
94 
95 //-*****************************************************************************
96 enum GeometryScope
97 {
98     kConstantScope = 0,
99     kUniformScope = 1,
100     kVaryingScope = 2,
101     kVertexScope = 3,
102     kFacevaryingScope = 4,
103 
104     kUnknownScope = 127
105 };
106 
107 //-*****************************************************************************
108 //! These functions will set or get the GeometryScope out of
109 //! an object, by looking at its metadata.
110 //-*****************************************************************************
111 
112 //-*****************************************************************************
SetGeometryScope(AbcA::MetaData & ioMetaData,GeometryScope iScope)113 inline void SetGeometryScope( AbcA::MetaData &ioMetaData, GeometryScope iScope )
114 {
115     switch ( iScope )
116     {
117     case kConstantScope: ioMetaData.set( "geoScope", "con" ); return;
118     case kUniformScope: ioMetaData.set( "geoScope", "uni" ); return;
119     case kVaryingScope: ioMetaData.set( "geoScope", "var" ); return;
120     case kVertexScope: ioMetaData.set( "geoScope", "vtx" ); return;
121     case kFacevaryingScope: ioMetaData.set( "geoScope", "fvr" ); return;
122     case kUnknownScope: return;
123     default: return;
124     }
125 }
126 
127 //-*****************************************************************************
GetGeometryScope(const AbcA::MetaData & iMetaData)128 inline GeometryScope GetGeometryScope( const AbcA::MetaData &iMetaData )
129 {
130     const std::string val = iMetaData.get( "geoScope" );
131     if ( val == "con" || val == "" ) { return kConstantScope; }
132     else if ( val == "uni" ) { return kUniformScope; }
133     else if ( val == "var" ) { return kVaryingScope; }
134     else if ( val == "vtx" ) { return kVertexScope; }
135     else if ( val == "fvr" ) { return kFacevaryingScope; }
136     else { return kUnknownScope; }
137 }
138 
139 //-*****************************************************************************
140 //! These functions below are just implementations of the statements
141 //! in the table above.
142 //-*****************************************************************************
143 
144 //! Works for any quadric.
145 //! ....
146 ALEMBIC_EXPORT size_t
147 GeometryScopeNumValuesQuadrics( GeometryScope iScope );
148 
149 //! Works for GeneralPolygon & Polygon
150 //! ...
151 ALEMBIC_EXPORT size_t
152 GeometryScopeNumValuesPolygon( GeometryScope iScope, size_t iNumVerts );
153 
154 //! Works for PointsPolygons & PointsGeneralPolygons
155 //! ...
156 ALEMBIC_EXPORT size_t
157 GeometryScopeNumValuesPointsPolygons( GeometryScope iScope,
158                                       size_t iNumPolys,
159                                       size_t iNumVerts,
160                                       size_t iSumOfCounts );
161 
162 //! Works for Points
163 //! ...
164 ALEMBIC_EXPORT size_t
165 GeometryScopeNumValuesPoints( GeometryScope iScope,
166                               size_t iNumPoints );
167 
168 //! Works for Subds, but not hierarchical.
169 //! ...
170 ALEMBIC_EXPORT size_t
171 GeometryScopeNumValuesSubdivisionMesh( GeometryScope iScope,
172                                        size_t iNumFaces,
173                                        size_t iNumVerts,
174                                        size_t iSumOfCounts );
175 
176 //! Works for Bilinear Patch
177 //! ...
178 ALEMBIC_EXPORT size_t
179 GeometryScopeNumValuesBilinearPatch( GeometryScope iScope );
180 
181 //! Works for Bicubic Patch
182 //! ...
183 ALEMBIC_EXPORT size_t
184 GeometryScopeNumValuesBicubicPatch( GeometryScope iScope );
185 
186 //! Works for BilinearPatchMesh
187 //! ...
188 ALEMBIC_EXPORT size_t
189 GeometryScopeNumValuesBilinearPatchMesh( GeometryScope iScope,
190                                          size_t iNu, bool iUNoWrap,
191                                          size_t iNv, bool iVNoWrap );
192 
193 //! Works for BicubicPatchMesh
194 //! Usegs = Nu-3.
195 //! Vsegs = Nv-3.
196 ALEMBIC_EXPORT size_t
197 GeometryScopeNumValuesBicubicPatchMesh( GeometryScope iScope,
198                                         size_t iNu, bool iUNoWrap,
199                                         size_t iNv, bool iVNoWrap );
200 
201 //! Works for Nurbs patch
202 //! ...
203 ALEMBIC_EXPORT size_t
204 GeometryScopeNumValuesNuPatch( GeometryScope iScope,
205                                size_t iNu, size_t iUorder,
206                                size_t iNv, size_t iVorder );
207 
208 //! Works for Linear Curves
209 //! ...
210 ALEMBIC_EXPORT size_t
211 GeometryScopeNumValuesLinearCurves( GeometryScope iScope,
212                                     size_t iNumCurves, bool iNoWrap,
213                                     size_t iSumOfCounts );
214 //! Works for Bicubic Curves
215 //! ...
216 ALEMBIC_EXPORT size_t
217 GeometryScopeNumValuesCubicCurves( GeometryScope iScope,
218                                    size_t iNumCurves, bool iNoWrap,
219                                    size_t iSumOfCounts );
220 
221 //-*****************************************************************************
222 //! These functions below are convenience functions for identifying UVs.
223 //! ...
224 //-*****************************************************************************
225 
226 ALEMBIC_EXPORT void SetIsUV( AbcA::MetaData &ioMetaData, bool isUV );
227 
228 ALEMBIC_EXPORT bool isUV( const AbcA::PropertyHeader & iHeader );
229 
230 } // End namespace ALEMBIC_VERSION_NS
231 
232 using namespace ALEMBIC_VERSION_NS;
233 
234 } // End namespace AbcGeom
235 } // End namespace Alembic
236 
237 
238 
239 #endif
240