HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeSamplingType.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2013,
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_AbcCoreAbstract_TimeSamplingType_h
38 #define Alembic_AbcCoreAbstract_TimeSamplingType_h
39 
40 #include <Alembic/Util/Export.h>
42 
43 namespace Alembic {
44 namespace AbcCoreAbstract {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
48 //! The TimeSamplingType class controls how properties in Alembic relate
49 //! time values to their sample indices.
50 //!
51 //! The default behavior is where there is a time value associated with sample
52 //! zero, and a uniform time amount between each subsequent sample.
53 //! This is called "Uniform" time sampling, and would correspond to sampling
54 //! every frame at 1/24 per second, or similar.
55 //!
56 //! The second behavior is where there is a period of time over which a fixed
57 //! number of samples are distributed unevenly - imagine a render scene sampled
58 //! across a shutter period at shutter-begin-open, shutter-full-open,
59 //! shutter-begin-close, shutter-full-close. This is (perhaps confusingly)
60 //! called "Cyclic" time sampling.
61 //!
62 //! The final behavior is where the time samples are totally uneven. We
63 //! make a restriction that they must be strictly increasing,
64 //! as the indices are increasing. This is so we can bisection search to find
65 //! the lower or upper bounds when searching for floor, ceiling, or nearest
66 //! samples by comparing time. This is called "Acyclic" time sampling.
67 
69 {
70 public:
71  static uint32_t AcyclicNumSamples();
72  static chrono_t AcyclicTimePerCycle();
73 
74 public:
75 
76  //! Uniform default
78  : m_numSamplesPerCycle( 1 ),
79  m_timePerCycle( 1.0 ) {}
80 
81  //! UNIFORM
82  //! ...
83  explicit TimeSamplingType( chrono_t iTimePerCycle )
84  : m_numSamplesPerCycle( 1 )
85  , m_timePerCycle( iTimePerCycle )
86  {
87  ABCA_ASSERT( m_timePerCycle > 0.0 &&
88  m_timePerCycle < AcyclicTimePerCycle(),
89  "Time per cycle must be greater than 0 " <<
90  "and can not be ACYCLIC_TIME_PER_CYCLE." );
91  }
92 
93  //! CYCLIC
94  //! ...
95  TimeSamplingType( uint32_t iNumSamplesPerCycle,
96  chrono_t iTimePerCycle )
97  : m_numSamplesPerCycle( iNumSamplesPerCycle )
98  , m_timePerCycle( iTimePerCycle )
99  {
100  ABCA_ASSERT(
101 
102  // Acyclic
103  ( m_timePerCycle == AcyclicTimePerCycle() &&
104  m_numSamplesPerCycle == AcyclicNumSamples() ) ||
105 
106  // valid time per cycle
107  ( m_timePerCycle > 0.0 &&
108  m_timePerCycle < AcyclicTimePerCycle() &&
109 
110  // and valid samples per cycle
111  m_numSamplesPerCycle > 0 &&
112  m_numSamplesPerCycle < AcyclicNumSamples() ),
113  "Invalid Time Sampling Type, time per cycle: "
114  << m_timePerCycle << " samples per cycle: "
115  << m_numSamplesPerCycle );
116 
117  }
118 
119  //! ACYCLIC
120  //! This enum exists solely as a way of distinguishing between
121  //! the argument-less static time sampling, and
122  //! the argument-less acyclic time sampling.
123  enum AcyclicFlag { kAcyclic };
124  explicit TimeSamplingType( AcyclicFlag /*iAF*/ )
125  {
126  m_numSamplesPerCycle = AcyclicNumSamples();
127  m_timePerCycle = AcyclicTimePerCycle();
128  }
129 
130  //! Using Default Copy Constructor
131  //! Using Default Assignment Operator
132 
133  bool operator==( const TimeSamplingType & iRhs ) const;
134 
135  //! Asks if the sampling is:
136  //! Uniform (1 sample per cycle)
137  //! Cyclic (N>1 samples per cycle)
138  //! Acyclic (INF samples per cycle - acyclic!)
139  bool isUniform() const { return m_numSamplesPerCycle == 1; }
140  bool isCyclic() const
141  {
142  return ( ( m_numSamplesPerCycle > 1 ) &&
143  ( m_numSamplesPerCycle < AcyclicNumSamples() ) );
144  }
145  bool isAcyclic() const
146  { return m_numSamplesPerCycle == AcyclicNumSamples(); }
147 
148  uint32_t getNumSamplesPerCycle() const { return m_numSamplesPerCycle; }
149 
150  chrono_t getTimePerCycle() const { return m_timePerCycle; }
151 
152 private:
153  uint32_t m_numSamplesPerCycle;
154  chrono_t m_timePerCycle;
155 
156 public:
157  ALEMBIC_EXPORT friend std::ostream
158  &operator<<( std::ostream &ostr, const TimeSamplingType &tst );
159 };
160 
161 } // End namespace ALEMBIC_VERSION_NS
162 
163 using namespace ALEMBIC_VERSION_NS;
164 
165 } // End namespace AbcCoreAbstract
166 } // End namespace Alembic
167 
168 #endif
#define ALEMBIC_EXPORT
Definition: Export.h:51
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
Definition: DataType.h:133
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
TimeSamplingType(uint32_t iNumSamplesPerCycle, chrono_t iTimePerCycle)