Debian Codegraph @

lib/Alembic/AbcCoreHDF5/Tests/ConstantPropsNumSampsTest.cpp

raw
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 //-*****************************************************************************
44 namespace A5 = Alembic::AbcCoreHDF5;
45
46 namespace AbcA = Alembic::AbcCoreAbstract;
47
48 using namespace AbcA;
49
50 //-*****************************************************************************
51 void testProps()
52 {
53 Alembic::Util::int32_t intVal = 15;
54
55 float32_t f0 = 67.3f;
56
57 size_t floatArraySize = 14;
58
59 chrono_t t0 = 0.25;
60
61 chrono_t dt = 1.0 / 24.0;
62
63 DataType floatDT( kFloat32POD, 1 );
64
65 Dimensions dims( floatArraySize );
66
67 std::string archiveName = "constantPropsTest.abc";
68
69 std::vector<float32_t> fvals;
70
71 for ( size_t i = 0 ; i < floatArraySize ; i++ )
72 {
73 fvals.push_back( f0 + i );
74 }
75
76
77 {
78 A5::WriteArchive w;
79 ArchiveWriterPtr a = w(archiveName, AbcA::MetaData());
80 std::vector < chrono_t > samps(1, t0);
81 AbcA::TimeSampling ts(TimeSamplingType(dt), samps);
82 a->addTimeSampling(ts);
83
84 ObjectWriterPtr top = a->getTop();
85 ObjectWriterPtr child = top->createChild(
86 ObjectHeader( "wow", MetaData() ) );
87
88 CompoundPropertyWriterPtr props = child->getProperties();
89
90 ScalarPropertyWriterPtr intProp = props->createScalarProperty("intProp",
91 MetaData(), DataType( kInt32POD, 1 ), 1);
92
93 ArrayPropertyWriterPtr floatArrayProp = props->createArrayProperty(
94 "floatArrayProp", MetaData(), DataType( kFloat32POD, 1 ), 1);
95
96 intProp->setSample( &intVal );
97
98 for ( size_t i = 0 ; i < 500 ; i++ )
99 {
100 floatArrayProp->setSample(ArraySample( &(fvals.front()), floatDT,
101 dims ) );
102 }
103
104 }
105
106 {
107 A5::ReadArchive r;
108 ArchiveReaderPtr a = r( archiveName );
109 ObjectReaderPtr top = a->getTop();
110 TESTING_ASSERT( top->getNumChildren() == 1 );
111
112 AbcA::ObjectReaderPtr child = top->getChild(0);
113 TESTING_ASSERT( child->getName() == "wow" );
114
115 CompoundPropertyReaderPtr props = child->getProperties();
116
117 TESTING_ASSERT( props->getNumProperties() == 2 );
118
119 ScalarPropertyReaderPtr intProp = props->getScalarProperty( "intProp" );
120 TESTING_ASSERT( intProp->isConstant() );
121 TESTING_ASSERT( intProp->getNumSamples() == 1 );
122
123 ArrayPropertyReaderPtr floatArrayProp = \
124 props->getArrayProperty( "floatArrayProp" );
125
126 TESTING_ASSERT( floatArrayProp->getNumSamples() == 500 );
127 TESTING_ASSERT( floatArrayProp->isConstant() );
128
129 }
130 }
131
132 int main ( int argc, char *argv[] )
133 {
134 testProps();
135 return 0;
136 }