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/AbcGeom/All.h>
38 #include <Alembic/AbcCoreOgawa/All.h>
39 #include <Alembic/AbcCoreFactory/IFactory.h>
40 #include <Alembic/AbcCoreAbstract/Tests/Assert.h>
41
42 using namespace Alembic::AbcGeom; // Contains Abc, AbcCoreAbstract
43
44 //-*****************************************************************************
cameraTest()45 void cameraTest()
46 {
47 std::string fileName = "camera1.abc";
48 {
49 OArchive archive( Alembic::AbcCoreOgawa::WriteArchive(), fileName );
50 CameraSample samp;
51 OCamera simpleCamObj( OObject( archive, kTop ), "simpleCam" );
52 simpleCamObj.getSchema().set( samp );
53
54 OCamera camObj( OObject( archive, kTop ), "cam" );
55 OCameraSchema camSchema = camObj.getSchema();
56 samp.addOp( FilmBackXformOp( kScaleFilmBackOperation, "scale" ) );
57 samp.addOp( FilmBackXformOp( kTranslateFilmBackOperation, "offset" ) );
58 camSchema.set( samp );
59
60 samp[0].setScale( V2d( 2.0, 3.0 ) );
61 samp[1].setChannelValue( 0, 4.0 );
62 samp[1].setChannelValue( 1, 5.0 );
63 samp.setLensSqueezeRatio( 2.0 );
64 samp.setHorizontalAperture( 4.8 );
65 samp.setVerticalFilmOffset( 3.0 );
66 camSchema.set( samp );
67 }
68
69 {
70 M33d identity;
71 identity.makeIdentity();
72
73 CameraSample samp;
74
75 IArchive archive( Alembic::AbcCoreOgawa::ReadArchive(), fileName );
76 ICamera simpleCam( IObject( archive, kTop ), "simpleCam" );
77 ICamera cam( IObject( archive, kTop ), "cam" );
78
79 // all default data
80 simpleCam.getSchema().get( samp );
81 TESTING_ASSERT( simpleCam.getSchema().getNumSamples() == 1 );
82 TESTING_ASSERT( almostEqual( samp.getFocalLength(), 35.0 ) );
83 TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(), 3.6 ) );
84 TESTING_ASSERT( almostEqual( samp.getVerticalAperture(), 2.4 ) );
85 TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(), 0.0 ) );
86 TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(), 0.0 ) );
87 TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(), 1.0 ) );
88 TESTING_ASSERT( almostEqual( samp.getOverScanLeft(), 0.0 ) );
89 TESTING_ASSERT( almostEqual( samp.getOverScanRight(), 0.0 ) );
90 TESTING_ASSERT( almostEqual( samp.getOverScanTop(), 0.0 ) );
91 TESTING_ASSERT( almostEqual( samp.getOverScanBottom(), 0.0 ) );
92 TESTING_ASSERT( almostEqual( samp.getFStop(), 5.6 ) );
93 TESTING_ASSERT( almostEqual( samp.getFocusDistance(), 5.0 ) );
94 TESTING_ASSERT( almostEqual( samp.getShutterOpen(), 0.0 ) );
95 TESTING_ASSERT( almostEqual( samp.getShutterClose(),
96 0.020833333333333332 ) );
97 TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(), 0.1 ) );
98 TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(), 100000.0 ) );
99 TESTING_ASSERT( samp.getNumOps() == 0 );
100 TESTING_ASSERT( samp.getNumOpChannels() == 0 );
101 TESTING_ASSERT( samp.getFilmBackMatrix() == identity );
102
103 TESTING_ASSERT( cam.getSchema().getNumSamples() == 2 );
104
105 cam.getSchema().get( samp );
106 TESTING_ASSERT( almostEqual( samp.getFocalLength(), 35.0 ) );
107 TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(), 3.6 ) );
108 TESTING_ASSERT( almostEqual( samp.getVerticalAperture(), 2.4 ) );
109 TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(), 0.0 ) );
110 TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(), 0.0 ) );
111 TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(), 1.0 ) );
112 TESTING_ASSERT( almostEqual( samp.getOverScanLeft(), 0.0 ) );
113 TESTING_ASSERT( almostEqual( samp.getOverScanRight(), 0.0 ) );
114 TESTING_ASSERT( almostEqual( samp.getOverScanTop(), 0.0 ) );
115 TESTING_ASSERT( almostEqual( samp.getOverScanBottom(), 0.0 ) );
116 TESTING_ASSERT( almostEqual( samp.getFStop(), 5.6 ) );
117 TESTING_ASSERT( almostEqual( samp.getFocusDistance(), 5.0 ) );
118 TESTING_ASSERT( almostEqual( samp.getShutterOpen(), 0.0 ) );
119 TESTING_ASSERT( almostEqual( samp.getShutterClose(),
120 0.020833333333333332 ) );
121 TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(), 0.1 ) );
122 TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(), 100000.0 ) );
123 TESTING_ASSERT( samp.getNumOps() == 2 );
124 TESTING_ASSERT( samp.getNumOpChannels() == 4 );
125 TESTING_ASSERT( samp[0].getHint() == "scale" );
126 TESTING_ASSERT( samp[0].getType() == kScaleFilmBackOperation );
127 TESTING_ASSERT( samp[0].getNumChannels() == 2 );
128 TESTING_ASSERT( almostEqual( samp[0].getChannelValue(0), 1.0 ) );
129 TESTING_ASSERT( almostEqual( samp[0].getChannelValue(1), 1.0 ) );
130 TESTING_ASSERT( samp[1].getHint() == "offset" );
131 TESTING_ASSERT( samp[1].getType() == kTranslateFilmBackOperation );
132 TESTING_ASSERT( samp[1].getNumChannels() == 2 );
133 TESTING_ASSERT( almostEqual( samp[1].getChannelValue(0), 0.0 ) );
134 TESTING_ASSERT( almostEqual( samp[1].getChannelValue(1), 0.0 ) );
135 TESTING_ASSERT( samp.getFilmBackMatrix() == identity );
136
137 cam.getSchema().get( samp, 1 );
138 TESTING_ASSERT( almostEqual( samp.getFocalLength(), 35.0 ) );
139 TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(), 4.8 ) );
140 TESTING_ASSERT( almostEqual( samp.getVerticalAperture(), 2.4 ) );
141 TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(), 0.0 ) );
142 TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(), 3.0 ) );
143 TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(), 2.0 ) );
144 TESTING_ASSERT( almostEqual( samp.getOverScanLeft(), 0.0 ) );
145 TESTING_ASSERT( almostEqual( samp.getOverScanRight(), 0.0 ) );
146 TESTING_ASSERT( almostEqual( samp.getOverScanTop(), 0.0 ) );
147 TESTING_ASSERT( almostEqual( samp.getOverScanBottom(), 0.0 ) );
148 TESTING_ASSERT( almostEqual( samp.getFStop(), 5.6 ) );
149 TESTING_ASSERT( almostEqual( samp.getFocusDistance(), 5.0 ) );
150 TESTING_ASSERT( almostEqual( samp.getShutterOpen(), 0.0 ) );
151 TESTING_ASSERT( almostEqual( samp.getShutterClose(),
152 0.020833333333333332) );
153 TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(), 0.1 ) );
154 TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(), 100000.0 ) );
155 TESTING_ASSERT( samp.getNumOps() == 2 );
156 TESTING_ASSERT( samp.getNumOpChannels() == 4 );
157 TESTING_ASSERT( samp[0].getHint() == "scale" );
158 TESTING_ASSERT( samp[0].getType() == kScaleFilmBackOperation );
159 TESTING_ASSERT( samp[0].getNumChannels() == 2 );
160 TESTING_ASSERT( almostEqual( samp[0].getChannelValue(0), 2.0 ) );
161 TESTING_ASSERT( almostEqual( samp[0].getChannelValue(1), 3.0 ) );
162 TESTING_ASSERT( samp[0].getScale().equalWithAbsError( V2d( 2.0, 3.0 ),
163 VAL_EPSILON ) );
164 TESTING_ASSERT( samp[1].getHint() == "offset" );
165 TESTING_ASSERT( samp[1].getType() == kTranslateFilmBackOperation );
166 TESTING_ASSERT( samp[1].getNumChannels() == 2 );
167 TESTING_ASSERT( almostEqual( samp[1].getChannelValue(0), 4.0 ) );
168 TESTING_ASSERT( almostEqual( samp[1].getChannelValue(1), 5.0 ) );
169 TESTING_ASSERT( samp[1].getTranslate().equalWithAbsError(
170 V2d( 4.0, 5.0 ), VAL_EPSILON ) );
171
172 M33d m;
173 m.makeIdentity();
174 m.scale( V2d( 2.0, 3.0 ) );
175 m.translate( V2d( 4.0, 5.0 ) );
176 TESTING_ASSERT( samp.getFilmBackMatrix().equalWithAbsError( m,
177 VAL_EPSILON ) );
178 }
179 }
180
181 //-*****************************************************************************
corePropertiesTest()182 void corePropertiesTest()
183 {
184 std::string fileName = "camera2.abc";
185 {
186 OArchive archive( Alembic::AbcCoreOgawa::WriteArchive(), fileName );
187 CameraSample samp;
188
189 OCamera camObj( OObject( archive, kTop ), "cam" );
190 OCameraSchema camSchema = camObj.getSchema();
191
192 // set some nonsense values just to test reading/writing
193 for ( std::size_t i = 0; i < 10; ++i )
194 {
195 samp.setFocalLength( i * 1000.0 + 1.0 );
196 samp.setHorizontalAperture( i * 1000.0 + 2.0 );
197 samp.setVerticalAperture( i * 1000.0 + 3.0 );
198 samp.setHorizontalFilmOffset( i * 1000.0 + 4.0 );
199 samp.setVerticalFilmOffset( i * 1000.0 + 5.0 );
200 samp.setLensSqueezeRatio( i * 1000.0 + 6.0 );
201 samp.setOverScanLeft( i * 1000.0 + 7.0 );
202 samp.setOverScanRight( i * 1000.0 + 8.0 );
203 samp.setOverScanTop( i * 1000.0 + 9.0 );
204 samp.setOverScanBottom( i * 1000.0 + 10.0 );
205 samp.setFStop( i * 1000.0 + 11.0 );
206 samp.setFocusDistance( i * 1000.0 + 12.0 );
207 samp.setShutterOpen( i * 1000.0 + 13.0 );
208 samp.setShutterClose( i * 1000.0 + 14.0 );
209 samp.setNearClippingPlane( i * 1000.0 + 15.0 );
210 samp.setFarClippingPlane( i * 1000.0 + 16.0 );
211 camSchema.set( samp );
212 }
213 }
214
215 {
216 M33d identity;
217 identity.makeIdentity();
218
219 CameraSample samp;
220
221 IArchive archive( Alembic::AbcCoreOgawa::ReadArchive(), fileName );
222 ICamera cam( IObject( archive, kTop ), "cam" );
223
224 TESTING_ASSERT( cam.getSchema().getNumSamples() == 10 );
225
226 for ( std::size_t i = 0; i < 10; ++i )
227 {
228 cam.getSchema().get( samp, i );
229 TESTING_ASSERT( almostEqual( samp.getFocalLength(),
230 1000.0 * i + 1.0 ) );
231 TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(),
232 1000.0 * i + 2.0 ) );
233 TESTING_ASSERT( almostEqual( samp.getVerticalAperture(),
234 1000.0 * i + 3.0 ) );
235 TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(),
236 1000.0 * i + 4.0 ) );
237 TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(),
238 1000.0 * i + 5.0 ) );
239 TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(),
240 1000.0 * i + 6.0 ) );
241 TESTING_ASSERT( almostEqual( samp.getOverScanLeft(),
242 1000.0 * i + 7.0 ) );
243 TESTING_ASSERT( almostEqual( samp.getOverScanRight(),
244 1000.0 * i + 8.0 ) );
245 TESTING_ASSERT( almostEqual( samp.getOverScanTop(),
246 1000.0 * i + 9.0 ) );
247 TESTING_ASSERT( almostEqual( samp.getOverScanBottom(),
248 1000.0 * i + 10.0 ) );
249 TESTING_ASSERT( almostEqual( samp.getFStop(),
250 1000.0 * i + 11.0 ) );
251 TESTING_ASSERT( almostEqual( samp.getFocusDistance(),
252 1000.0 * i + 12.0 ) );
253 TESTING_ASSERT( almostEqual( samp.getShutterOpen(),
254 1000.0 * i + 13.0 ) );
255 TESTING_ASSERT( almostEqual( samp.getShutterClose(),
256 1000.0 * i + 14.0 ) );
257 TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(),
258 1000.0 * i + 15.0 ) );
259 TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(),
260 1000.0 * i + 16.0 ) );
261 TESTING_ASSERT( samp.getNumOps() == 0 );
262 TESTING_ASSERT( samp.getNumOpChannels() == 0 );
263 }
264 }
265 }
266
267 //-*****************************************************************************
sparseTest()268 void sparseTest()
269 {
270 std::string fileA = "sparseCameraA.abc";
271 {
272 OArchive archive( Alembic::AbcCoreOgawa::WriteArchive(), fileA );
273 CameraSample samp;
274 OCamera simpleCamObj( OObject( archive, kTop ), "simpleCam" );
275 simpleCamObj.getSchema().set( samp );
276
277 OCamera camObj( OObject( archive, kTop ), "staticCam" );
278 OCameraSchema camSchema = camObj.getSchema();
279 samp.addOp( FilmBackXformOp( kScaleFilmBackOperation, "scale" ) );
280 samp.addOp( FilmBackXformOp( kTranslateFilmBackOperation, "offset" ) );
281 camSchema.set( samp );
282
283 OCamera animCamObj( OObject( archive, kTop ), "animCam" );
284 OCameraSchema animCamSchema = animCamObj.getSchema();
285 animCamSchema.set( samp );
286
287 samp[0].setScale( V2d( 2.0, 3.0 ) );
288 samp[1].setChannelValue( 0, 4.0 );
289 samp[1].setChannelValue( 1, 5.0 );
290 samp.setLensSqueezeRatio( 2.0 );
291 samp.setHorizontalAperture( 4.8 );
292 samp.setVerticalFilmOffset( 3.0 );
293 animCamSchema.set( samp );
294 }
295
296 std::string fileB = "sparseCameraB.abc";
297 {
298 OArchive archive( Alembic::AbcCoreOgawa::WriteArchive(), fileB );
299
300 CameraSample samp;
301 samp.addOp( FilmBackXformOp( kTranslateFilmBackOperation, "test" ) );
302 samp.setLensSqueezeRatio( 5.0 );
303 samp.setHorizontalAperture( 4.0 );
304 samp.setVerticalFilmOffset( 3.0 );
305 samp[0].setChannelValue( 0, 2.0 );
306 samp[0].setChannelValue( 1, 1.0 );
307
308 OCamera simpleCamObj( OObject( archive ), "simpleCam", kSparse );
309 simpleCamObj.getSchema().set( samp );
310
311 OCamera camObj( OObject( archive ), "staticCam", kSparse );
312 OCameraSchema camSchema = camObj.getSchema();
313 camSchema.set( samp );
314 samp.setLensSqueezeRatio( 10.0 );
315 samp.setHorizontalAperture( 9.0 );
316 samp.setVerticalFilmOffset( 8.0 );
317 samp[0].setChannelValue( 0, 7.0 );
318 samp[0].setChannelValue( 1, 6.0 );
319 camSchema.set( samp );
320
321 OCamera animCamObj( OObject( archive ), "animCam", kSparse );
322 OCameraSchema animCamSchema = animCamObj.getSchema();
323 CameraSample simpleSamp;
324 animCamSchema.set( simpleSamp );
325 }
326
327 {
328 std::vector< std::string > names;
329 names.push_back( fileB );
330 names.push_back( fileA );
331 Alembic::AbcCoreFactory::IFactory factory;
332 IArchive archive = factory.getArchive( names );
333
334 ICamera simpleCamObj( IObject( archive ), "simpleCam" );
335 CameraSample samp;
336 ICameraSchema schema = simpleCamObj.getSchema();
337 TESTING_ASSERT( schema.getNumSamples() == 1 );
338 schema.get( samp );
339 TESTING_ASSERT( samp.getNumOps() == 1 &&
340 samp.getOp(0).getHint() == "test" );
341
342 ICamera staticCamObj( IObject( archive ), "staticCam" );
343 schema = staticCamObj.getSchema();
344 TESTING_ASSERT( schema.getNumSamples() == 2 );
345 schema.get( samp );
346 TESTING_ASSERT( samp.getLensSqueezeRatio() == 5.0 &&
347 samp.getHorizontalAperture() == 4.0 &&
348 samp.getVerticalFilmOffset() == 3.0 &&
349 samp[0].getChannelValue( 0 ) == 2.0 &&
350 samp[0].getChannelValue( 1 ) == 1.0 );
351
352 schema.get( samp, 1 );
353 TESTING_ASSERT( samp.getLensSqueezeRatio() == 10.0 &&
354 samp.getHorizontalAperture() == 9.0 &&
355 samp.getVerticalFilmOffset() == 8.0 &&
356 samp[0].getChannelValue( 0 ) == 7.0 &&
357 samp[0].getChannelValue( 1 ) == 6.0 );
358
359 ICamera animCamObj( IObject( archive ), "animCam" );
360 schema = animCamObj.getSchema();
361 schema.get( samp );
362 TESTING_ASSERT( schema.getNumSamples() == 1 && samp.getNumOps() == 0 );
363 }
364 }
365
366 //-*****************************************************************************
main(int argc,char * argv[])367 int main( int argc, char *argv[] )
368 {
369 cameraTest();
370 corePropertiesTest();
371 sparseTest();
372 return 0;
373 }
374