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_Foundation_h
38 #define Alembic_AbcGeom_Foundation_h
39 
40 #include <Alembic/Abc/All.h>
41 
42 #include <ImathMatrixAlgo.h>
43 #include <ImathEuler.h>
44 
45 
46 namespace Alembic {
47 namespace AbcGeom {
48 namespace ALEMBIC_VERSION_NS {
49 
50 namespace Abc = ::Alembic::Abc::ALEMBIC_VERSION_NS;
51 using namespace Abc;
52 
53 //-*****************************************************************************
54 //! Meshes have topology, which can be either unchanging (constant)
55 //! homogeneous, which indicates that the connectivity is unchanging,
56 //! but the positions may change, and finally heterogeneous, which indicates
57 //! that the connectivity and positions may change.
58 enum MeshTopologyVariance
59 {
60     kConstantTopology = 0,
61     kHomogenousTopology = 1,
62     kHomogeneousTopology = 1,
63     kHeterogenousTopology = 2,
64     kHeterogeneousTopology = 2
65 };
66 
67 //-*****************************************************************************
68 //! \brief Enum that indicates the type of transformational operation.
69 //! This enum is used when encoding and decoding the transform operation data.
70 enum XformOperationType
71 {
72     kScaleOperation = 0,
73     kTranslateOperation = 1,
74     kRotateOperation = 2,
75     kMatrixOperation = 3,
76     kRotateXOperation = 4,
77     kRotateYOperation = 5,
78     kRotateZOperation = 6
79 };
80 
81 //-*****************************************************************************
82 //! \brief Enum that indicates the type of 2d operation for cameras.
83 //! This enum is used when encoding and decoding the 2d filmback data for
84 //! cameras.
85 enum FilmBackXformOperationType
86 {
87     kScaleFilmBackOperation = 0,
88     kTranslateFilmBackOperation = 1,
89     kMatrixFilmBackOperation = 2
90 };
91 
92 //-*****************************************************************************
93 //! This utility function sets an array prorperty sample using "set" if
94 //! the sample is non-null, otherwise calls setFromPrevious.
95 template <class PROP, class SAMP>
SetPropUsePrevIfNull(PROP iProp,SAMP iSamp)96 inline void SetPropUsePrevIfNull( PROP iProp, SAMP iSamp )
97 {
98     if ( iProp )
99     {
100         // really only valid with array properties
101         assert( iProp.isArray() );
102 
103         if ( iSamp ) { iProp.set( iSamp ); }
104         else { iProp.setFromPrevious(); }
105     }
106 }
107 
108 template <>
109 inline void SetPropUsePrevIfNull<Abc::OStringProperty, std::string>(
110     Abc::OStringProperty iProp, std::string iSamp )
111 {
112     if ( ! iProp ) { return; }
113     if ( iSamp != "" ) { iProp.set( iSamp ); }
114     else { iProp.setFromPrevious(); }
115 }
116 
117 template <>
118 inline void SetPropUsePrevIfNull<Abc::OWstringProperty, Alembic::Util::wstring>(
119     Abc::OWstringProperty iProp, Alembic::Util::wstring iSamp )
120 {
121     if ( ! iProp ) { return; }
122     if ( iSamp != L"" ) { iProp.set( iSamp ); }
123     else { iProp.setFromPrevious(); }
124 }
125 
126 template <>
127 inline void SetPropUsePrevIfNull<Abc::OBox3dProperty, Abc::Box3d>(
128     Abc::OBox3dProperty iProp, Abc::Box3d iSamp )
129 {
130     if ( ! iProp ) { return; }
131     if ( iSamp.hasVolume() ) { iProp.set( iSamp ); }
132     else { iProp.setFromPrevious(); }
133 }
134 
135 //-*****************************************************************************
136 //! This utility function computes an axis-aligned bounding box from a
137 //! positions sample
138 template <class ARRAYSAMP>
ComputeBoundsFromPositions(const ARRAYSAMP & iSamp)139 static Abc::Box3d ComputeBoundsFromPositions( const ARRAYSAMP &iSamp )
140 {
141     Abc::Box3d ret;
142     size_t size = iSamp.size();
143     for ( size_t i = 0 ; i < size ; ++i )
144     {
145         ret.extendBy( iSamp[i] );
146     }
147 
148     return ret;
149 }
150 
151 //-*****************************************************************************
152 //! used in xform rotation conversion
DegreesToRadians(double iDegrees)153 inline double DegreesToRadians( double iDegrees )
154 {
155     return ( iDegrees * M_PI ) / 180.0;
156 }
157 
RadiansToDegrees(double iRadians)158 inline double RadiansToDegrees( double iRadians )
159 {
160     return iRadians * ( 180.0 / M_PI );
161 }
162 
163 //-*****************************************************************************
164 //! A couple simple tests for if something is a GeomParam
165 
IsGeomParam(const AbcA::PropertyHeader & iHeader)166 inline bool IsGeomParam( const AbcA::PropertyHeader &iHeader )
167 {
168     return iHeader.isArray() || ( iHeader.isCompound() &&
169         iHeader.getMetaData().get( "podName" ) != "" &&
170         iHeader.getMetaData().get( "podExtent" ) != "" );
171 }
172 
173 } // End namespace ALEMBIC_VERSION_NS
174 
175 using namespace ALEMBIC_VERSION_NS;
176 
177 } // End namespace AbcGeom
178 } // End namespace Alembic
179 
180 #endif
181