| 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 |
#include <Alembic/AbcCoreAbstract/All.h> |
| 38 |
#include <Alembic/AbcCoreHDF5/All.h> |
| 39 |
#include <Alembic/Util/All.h> |
| 40 |
|
| 41 |
#include <Alembic/AbcCoreAbstract/Tests/Assert.h> |
| 42 |
|
| 43 |
#include <iostream> |
| 44 |
#include <vector> |
| 45 |
|
| 46 |
#include <hdf5.h> |
| 47 |
|
| 48 |
//-***************************************************************************** |
| 49 |
namespace A5 = Alembic::AbcCoreHDF5; |
| 50 |
|
| 51 |
namespace AbcA = Alembic::AbcCoreAbstract; |
| 52 |
|
| 53 |
//-***************************************************************************** |
| 54 |
void testTimeSamplingScalar() |
| 55 |
{ |
| 56 |
std::string archiveName = "timeSamplingScalar.abc"; |
| 57 |
{ |
| 58 |
A5::WriteArchive w; |
| 59 |
AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); |
| 60 |
AbcA::ObjectWriterPtr archive = a->getTop(); |
| 61 |
|
| 62 |
AbcA::CompoundPropertyWriterPtr parent = archive->getProperties(); |
| 63 |
|
| 64 |
// illegal time value |
| 65 |
TESTING_ASSERT_THROW(parent->createScalarProperty("uniform", |
| 66 |
AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt32POD, 1), 42), |
| 67 |
Alembic::Util::Exception); |
| 68 |
|
| 69 |
std::vector < double > timeSamps(1,-4.0); |
| 70 |
AbcA::TimeSamplingType tst(3.0); |
| 71 |
AbcA::TimeSampling ts(tst, timeSamps); |
| 72 |
uint32_t tsid = a->addTimeSampling(ts); |
| 73 |
|
| 74 |
AbcA::ScalarPropertyWriterPtr swp = |
| 75 |
parent->createScalarProperty("uniform", AbcA::MetaData(), |
| 76 |
AbcA::DataType(Alembic::Util::kInt32POD, 1), tsid); |
| 77 |
|
| 78 |
Alembic::Util::int32_t i = 0; |
| 79 |
|
| 80 |
swp->setSample(&i); |
| 81 |
|
| 82 |
i+=3; |
| 83 |
swp->setSample(&i); |
| 84 |
|
| 85 |
i+=3; |
| 86 |
swp->setSample(&i); |
| 87 |
|
| 88 |
timeSamps.clear(); |
| 89 |
timeSamps.push_back(4.0); |
| 90 |
timeSamps.push_back(4.25); |
| 91 |
timeSamps.push_back(4.5); |
| 92 |
tst = AbcA::TimeSamplingType(3, 2.0); |
| 93 |
ts = AbcA::TimeSampling(tst, timeSamps); |
| 94 |
tsid = a->addTimeSampling(ts); |
| 95 |
|
| 96 |
AbcA::ScalarPropertyWriterPtr swp2 = |
| 97 |
parent->createScalarProperty("cyclic", AbcA::MetaData(), |
| 98 |
AbcA::DataType(Alembic::Util::kUint32POD, 1), tsid); |
| 99 |
|
| 100 |
Alembic::Util::uint32_t ui = 0; |
| 101 |
|
| 102 |
swp2->setSample(&ui); |
| 103 |
|
| 104 |
ui++; |
| 105 |
swp2->setSample(&ui); |
| 106 |
|
| 107 |
ui++; |
| 108 |
swp2->setSample(&ui); |
| 109 |
|
| 110 |
ui++; |
| 111 |
swp2->setSample(&ui); |
| 112 |
|
| 113 |
ui++; |
| 114 |
swp2->setSample(&ui); |
| 115 |
|
| 116 |
ui++; |
| 117 |
swp2->setSample(&ui); |
| 118 |
|
| 119 |
timeSamps.clear(); |
| 120 |
timeSamps.push_back(-17.0); |
| 121 |
timeSamps.push_back(32.0); |
| 122 |
timeSamps.push_back(50.0); |
| 123 |
timeSamps.push_back(60.2); |
| 124 |
timeSamps.push_back(101.1); |
| 125 |
timeSamps.push_back(700.0); |
| 126 |
timeSamps.push_back(747.0); |
| 127 |
|
| 128 |
tst = AbcA::TimeSamplingType(AbcA::TimeSamplingType::kAcyclic); |
| 129 |
ts = AbcA::TimeSampling(tst, timeSamps); |
| 130 |
tsid = a->addTimeSampling(ts); |
| 131 |
|
| 132 |
AbcA::ScalarPropertyWriterPtr swp3 = |
| 133 |
parent->createScalarProperty("acyclic", AbcA::MetaData(), |
| 134 |
AbcA::DataType(Alembic::Util::kUint16POD, 1), tsid); |
| 135 |
|
| 136 |
Alembic::Util::uint16_t s = 0; |
| 137 |
swp3->setSample(&s); |
| 138 |
|
| 139 |
s++; |
| 140 |
swp3->setSample(&s); |
| 141 |
|
| 142 |
s++; |
| 143 |
|
| 144 |
swp3->setSample(&s); |
| 145 |
|
| 146 |
|
| 147 |
s++; |
| 148 |
swp3->setSample(&s); |
| 149 |
|
| 150 |
s++; |
| 151 |
swp3->setSample(&s); |
| 152 |
|
| 153 |
s++; |
| 154 |
swp3->setSample(&s); |
| 155 |
|
| 156 |
s++; |
| 157 |
swp3->setSample(&s); |
| 158 |
|
| 159 |
// Setting more than what we have acyclic samples for |
| 160 |
TESTING_ASSERT_THROW(swp3->setSample(&s), |
| 161 |
Alembic::Util::Exception); |
| 162 |
|
| 163 |
swp3->setTimeSamplingIndex(tsid); |
| 164 |
|
| 165 |
AbcA::ScalarPropertyWriterPtr swp4 = |
| 166 |
parent->createScalarProperty("identity", AbcA::MetaData(), |
| 167 |
AbcA::DataType(Alembic::Util::kInt16POD, 1), 0); |
| 168 |
|
| 169 |
Alembic::Util::int16_t ss = 35; |
| 170 |
|
| 171 |
|
| 172 |
swp4->setSample(&ss); |
| 173 |
|
| 174 |
ss = 37; |
| 175 |
swp4->setSample(&ss); |
| 176 |
|
| 177 |
ss = 1000; |
| 178 |
swp4->setSample(&ss); |
| 179 |
|
| 180 |
timeSamps.clear(); |
| 181 |
timeSamps.push_back(0.0); |
| 182 |
tst = AbcA::TimeSamplingType(1.0); |
| 183 |
ts = AbcA::TimeSampling(tst, timeSamps); |
| 184 |
tsid = a->addTimeSampling(ts); |
| 185 |
|
| 186 |
AbcA::ScalarPropertyWriterPtr swp5 = |
| 187 |
parent->createScalarProperty("defaultUniform", AbcA::MetaData(), |
| 188 |
AbcA::DataType(Alembic::Util::kFloat32POD, 1), tsid); |
| 189 |
|
| 190 |
Alembic::Util::float32_t f = 0; |
| 191 |
|
| 192 |
swp5->setSample(&f); |
| 193 |
|
| 194 |
f+=1.1; |
| 195 |
swp5->setSample(&f); |
| 196 |
|
| 197 |
f+=1.1; |
| 198 |
swp5->setSample(&f); |
| 199 |
|
| 200 |
f+=1.1; |
| 201 |
swp5->setSample(&f); |
| 202 |
} |
| 203 |
|
| 204 |
{ |
| 205 |
A5::ReadArchive r; |
| 206 |
AbcA::ArchiveReaderPtr a = r( archiveName ); |
| 207 |
AbcA::ObjectReaderPtr archive = a->getTop(); |
| 208 |
AbcA::CompoundPropertyReaderPtr parent = archive->getProperties(); |
| 209 |
TESTING_ASSERT(parent->getNumProperties() == 5); |
| 210 |
|
| 211 |
for ( size_t i = 0; i < parent->getNumProperties(); ++i) |
| 212 |
{ |
| 213 |
AbcA::BasePropertyReaderPtr bp = parent->getProperty( i ); |
| 214 |
AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); |
| 215 |
const AbcA::TimeSamplingPtr t = sp->getTimeSampling(); |
| 216 |
|
| 217 |
switch (sp->getDataType().getPod()) |
| 218 |
{ |
| 219 |
case Alembic::Util::kInt16POD: |
| 220 |
{ |
| 221 |
// identity |
| 222 |
TESTING_ASSERT( t->getTimeSamplingType().isUniform() ); |
| 223 |
} |
| 224 |
break; |
| 225 |
|
| 226 |
case Alembic::Util::kUint16POD: |
| 227 |
{ |
| 228 |
// acylic |
| 229 |
TESTING_ASSERT( t->getSampleTime(0) == -17.0 ); |
| 230 |
TESTING_ASSERT( sp->getNumSamples() == 7); |
| 231 |
TESTING_ASSERT( t->getTimeSamplingType().isAcyclic() ); |
| 232 |
TESTING_ASSERT( t->getSampleTime(1) == 32.0 ); |
| 233 |
TESTING_ASSERT( t->getSampleTime(2) == 50.0 ); |
| 234 |
TESTING_ASSERT( t->getSampleTime(3) == 60.2 ); |
| 235 |
TESTING_ASSERT( t->getSampleTime(4) == 101.1 ); |
| 236 |
TESTING_ASSERT( t->getSampleTime(5) == 700.0 ); |
| 237 |
TESTING_ASSERT( t->getSampleTime(6) == 747.0 ); |
| 238 |
TESTING_ASSERT_THROW( t->getSampleTime(7), |
| 239 |
Alembic::Util::Exception); |
| 240 |
} |
| 241 |
break; |
| 242 |
|
| 243 |
case Alembic::Util::kFloat32POD: |
| 244 |
{ |
| 245 |
TESTING_ASSERT( sp->getNumSamples() == 4); |
| 246 |
TESTING_ASSERT( t->getTimeSamplingType().isUniform() ); |
| 247 |
TESTING_ASSERT( t->getSampleTime(0) == 0.0 ); |
| 248 |
TESTING_ASSERT( t->getSampleTime(1) == 1.0 ); |
| 249 |
TESTING_ASSERT( t->getSampleTime(2) == 2.0 ); |
| 250 |
TESTING_ASSERT( t->getSampleTime(3) == 3.0 ); |
| 251 |
} |
| 252 |
break; |
| 253 |
|
| 254 |
case Alembic::Util::kInt32POD: |
| 255 |
{ |
| 256 |
// uniform |
| 257 |
TESTING_ASSERT( sp->getNumSamples() == 3); |
| 258 |
TESTING_ASSERT( t->getTimeSamplingType().isUniform() ); |
| 259 |
TESTING_ASSERT( t->getSampleTime(0) == -4.0 ); |
| 260 |
TESTING_ASSERT( t->getSampleTime(1) == -1.0 ); |
| 261 |
TESTING_ASSERT( t->getSampleTime(2) == 2.0 ); |
| 262 |
} |
| 263 |
break; |
| 264 |
|
| 265 |
case Alembic::Util::kUint32POD: |
| 266 |
{ |
| 267 |
// cyclic |
| 268 |
TESTING_ASSERT( sp->getNumSamples() == 6); |
| 269 |
TESTING_ASSERT( t->getTimeSamplingType().isCyclic() ); |
| 270 |
TESTING_ASSERT( t->getSampleTime(0) == 4.0 ); |
| 271 |
TESTING_ASSERT( t->getSampleTime(1) == 4.25 ); |
| 272 |
TESTING_ASSERT( t->getSampleTime(2) == 4.5 ); |
| 273 |
TESTING_ASSERT( t->getSampleTime(3) == 6.0 ); |
| 274 |
TESTING_ASSERT( t->getSampleTime(4) == 6.25 ); |
| 275 |
TESTING_ASSERT( t->getSampleTime(5) == 6.5 ); |
| 276 |
} |
| 277 |
break; |
| 278 |
|
| 279 |
default: |
| 280 |
TESTING_ASSERT(false); |
| 281 |
break; |
| 282 |
} |
| 283 |
} // for |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
int main ( int argc, char *argv[] ) |
| 288 |
{ |
| 289 |
testTimeSamplingScalar(); |
| 290 |
return 0; |
| 291 |
} |