00001
00002
00003
00005
00007
00008 #if !defined(MAKEFILE) || ( defined(LIVE_TEST) )
00009
00010 #include "unit-tests-common.h"
00011
00012 TEST_CASE( "Device metadata enumerates correctly", "[live]" )
00013 {
00014
00015 safe_context ctx;
00016 const int device_count = rs_get_device_count(ctx, require_no_error());
00017 REQUIRE(device_count > 0);
00018
00019
00020 for(int i=0; i<device_count; ++i)
00021 {
00022 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00023 REQUIRE(dev != nullptr);
00024
00025 SECTION( "device metadata strings are nonempty" )
00026 {
00027 REQUIRE( rs_get_device_name(dev, require_no_error()) != nullptr );
00028 REQUIRE( rs_get_device_serial(dev, require_no_error()) != nullptr );
00029 REQUIRE( rs_get_device_firmware_version(dev, require_no_error()) != nullptr );
00030 }
00031
00032 SECTION( "device supports standard picture options" )
00033 {
00034 for(int i=RS_OPTION_COLOR_BACKLIGHT_COMPENSATION; i<=RS_OPTION_COLOR_WHITE_BALANCE; ++i)
00035 {
00036 REQUIRE(rs_device_supports_option(dev, (rs_option)i, require_no_error()) == 1);
00037 }
00038 }
00039 }
00040 }
00041
00043
00045 TEST_CASE("Start-Stop stream sequence", "[live]")
00046 {
00047
00048 safe_context ctx;
00049 const int device_count = rs_get_device_count(ctx, require_no_error());
00050 REQUIRE(device_count > 0);
00051
00052 std::vector<rs_stream> supported_streams;
00053
00054
00055 for(int i=0; i<device_count; ++i)
00056 {
00057 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00058 REQUIRE(dev != nullptr);
00059
00060 for (int i = (int)rs_capabilities::RS_CAPABILITIES_DEPTH; i <= (int)rs_capabilities::RS_CAPABILITIES_FISH_EYE; i++)
00061 if (rs_supports(dev,(rs_capabilities)i, require_no_error()))
00062 supported_streams.push_back((rs_stream)i);
00063
00064
00065 for (auto & stream : supported_streams)
00066 rs_enable_stream_preset(dev, stream, rs_preset::RS_PRESET_BEST_QUALITY, require_no_error());
00067
00068 for (int i = 0; i< 5; i++)
00069 {
00070
00071 rs_start_device(dev, require_no_error());
00072 rs_stop_device(dev, require_no_error());
00073 }
00074
00075 for (auto & stream : supported_streams)
00076 rs_disable_stream(dev,stream,require_no_error());
00077 }
00078 }
00079
00081
00083
00084 TEST_CASE( "no extrinsic transformation between a stream and itself", "[live]" )
00085 {
00086
00087 safe_context ctx;
00088 const int device_count = rs_get_device_count(ctx, require_no_error());
00089 REQUIRE(device_count > 0);
00090
00091
00092 for(int i=0; i<device_count; ++i)
00093 {
00094 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00095 REQUIRE(dev != nullptr);
00096
00097 for(int j=0; j<RS_STREAM_COUNT; ++j)
00098 {
00099 rs_extrinsics extrin = {};
00100 rs_error * e = nullptr;
00101 rs_get_device_extrinsics(dev, (rs_stream)j, (rs_stream)j, &extrin, &e);
00102 if (!e)
00103 {
00104 require_identity_matrix(extrin.rotation);
00105 require_zero_vector(extrin.translation);
00106 }
00107 }
00108 }
00109 }
00110
00111 TEST_CASE( "extrinsic transformation between two streams is a rigid transform", "[live]" )
00112 {
00113
00114 safe_context ctx;
00115 const int device_count = rs_get_device_count(ctx, require_no_error());
00116 REQUIRE(device_count > 0);
00117
00118
00119 for(int i=0; i<device_count; ++i)
00120 {
00121 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00122 REQUIRE(dev != nullptr);
00123
00124
00125 for(int j=0; j<RS_STREAM_COUNT; ++j)
00126 {
00127 const rs_stream stream_a = (rs_stream)j;
00128
00129 for(int k=j+1; k<RS_STREAM_COUNT; ++k)
00130 {
00131 const rs_stream stream_b = (rs_stream)k;
00132
00133
00134 rs_extrinsics a_to_b = {};
00135
00136 rs_error * e = nullptr;
00137
00138 rs_get_device_extrinsics(dev, stream_a, stream_b, &a_to_b, &e);
00139
00140 if (!e)
00141 {
00142 require_rotation_matrix(a_to_b.rotation);
00143 REQUIRE( vector_length(a_to_b.translation) < 0.1f );
00144
00145
00146 rs_extrinsics b_to_a = {};
00147 rs_get_device_extrinsics(dev, stream_b, stream_a, &b_to_a, require_no_error());
00148 require_transposed(a_to_b.rotation, b_to_a.rotation);
00149 REQUIRE( b_to_a.rotation[0] * a_to_b.translation[0] + b_to_a.rotation[3] * a_to_b.translation[1] + b_to_a.rotation[6] * a_to_b.translation[2] == Approx(-b_to_a.translation[0]) );
00150 REQUIRE( b_to_a.rotation[1] * a_to_b.translation[0] + b_to_a.rotation[4] * a_to_b.translation[1] + b_to_a.rotation[7] * a_to_b.translation[2] == Approx(-b_to_a.translation[1]) );
00151 REQUIRE( b_to_a.rotation[2] * a_to_b.translation[0] + b_to_a.rotation[5] * a_to_b.translation[1] + b_to_a.rotation[8] * a_to_b.translation[2] == Approx(-b_to_a.translation[2]) );
00152 }
00153 }
00154 }
00155 }
00156 }
00157
00158 TEST_CASE( "extrinsic transformations are transitive", "[live]" )
00159 {
00160
00161 safe_context ctx;
00162 const int device_count = rs_get_device_count(ctx, require_no_error());
00163 REQUIRE(device_count > 0);
00164
00165
00166 for(int i=0; i<device_count; ++i)
00167 {
00168 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00169 REQUIRE(dev != nullptr);
00170
00171
00172 for(int a=0; a<RS_STREAM_COUNT; ++a)
00173 {
00174 for(int b=0; b<RS_STREAM_COUNT; ++b)
00175 {
00176 for(int c=0; c<RS_STREAM_COUNT; ++c)
00177 {
00178
00179 rs_extrinsics a_to_b, b_to_c, a_to_c;
00180 rs_error * a_to_b_e = nullptr,* a_to_c_e = nullptr, * b_to_c_e = nullptr;
00181
00182 rs_get_device_extrinsics(dev, (rs_stream)a, (rs_stream)b, &a_to_b, &a_to_b_e);
00183 rs_get_device_extrinsics(dev, (rs_stream)b, (rs_stream)c, &b_to_c, &b_to_c_e);
00184 rs_get_device_extrinsics(dev, (rs_stream)a, (rs_stream)c, &a_to_c, &a_to_c_e);
00185
00186 if ((!a_to_b_e) && (!b_to_c_e) && (!a_to_c_e))
00187 {
00188
00189 REQUIRE( a_to_c.rotation[0] == Approx(a_to_b.rotation[0] * b_to_c.rotation[0] + a_to_b.rotation[3] * b_to_c.rotation[1] + a_to_b.rotation[6] * b_to_c.rotation[2]) );
00190 REQUIRE( a_to_c.rotation[2] == Approx(a_to_b.rotation[2] * b_to_c.rotation[0] + a_to_b.rotation[5] * b_to_c.rotation[1] + a_to_b.rotation[8] * b_to_c.rotation[2]) );
00191 REQUIRE( a_to_c.rotation[1] == Approx(a_to_b.rotation[1] * b_to_c.rotation[0] + a_to_b.rotation[4] * b_to_c.rotation[1] + a_to_b.rotation[7] * b_to_c.rotation[2]) );
00192 REQUIRE( a_to_c.rotation[3] == Approx(a_to_b.rotation[0] * b_to_c.rotation[3] + a_to_b.rotation[3] * b_to_c.rotation[4] + a_to_b.rotation[6] * b_to_c.rotation[5]) );
00193 REQUIRE( a_to_c.rotation[4] == Approx(a_to_b.rotation[1] * b_to_c.rotation[3] + a_to_b.rotation[4] * b_to_c.rotation[4] + a_to_b.rotation[7] * b_to_c.rotation[5]) );
00194 REQUIRE( a_to_c.rotation[5] == Approx(a_to_b.rotation[2] * b_to_c.rotation[3] + a_to_b.rotation[5] * b_to_c.rotation[4] + a_to_b.rotation[8] * b_to_c.rotation[5]) );
00195 REQUIRE( a_to_c.rotation[6] == Approx(a_to_b.rotation[0] * b_to_c.rotation[6] + a_to_b.rotation[3] * b_to_c.rotation[7] + a_to_b.rotation[6] * b_to_c.rotation[8]) );
00196 REQUIRE( a_to_c.rotation[7] == Approx(a_to_b.rotation[1] * b_to_c.rotation[6] + a_to_b.rotation[4] * b_to_c.rotation[7] + a_to_b.rotation[7] * b_to_c.rotation[8]) );
00197 REQUIRE( a_to_c.rotation[8] == Approx(a_to_b.rotation[2] * b_to_c.rotation[6] + a_to_b.rotation[5] * b_to_c.rotation[7] + a_to_b.rotation[8] * b_to_c.rotation[8]) );
00198
00199
00200 REQUIRE( a_to_c.translation[0] == Approx(a_to_b.rotation[0] * b_to_c.translation[0] + a_to_b.rotation[3] * b_to_c.translation[1] + a_to_b.rotation[6] * b_to_c.translation[2] + a_to_b.translation[0]) );
00201 REQUIRE( a_to_c.translation[1] == Approx(a_to_b.rotation[1] * b_to_c.translation[0] + a_to_b.rotation[4] * b_to_c.translation[1] + a_to_b.rotation[7] * b_to_c.translation[2] + a_to_b.translation[1]) );
00202 REQUIRE( a_to_c.translation[2] == Approx(a_to_b.rotation[2] * b_to_c.translation[0] + a_to_b.rotation[5] * b_to_c.translation[1] + a_to_b.rotation[8] * b_to_c.translation[2] + a_to_b.translation[2]) );
00203 }
00204 }
00205 }
00206 }
00207 }
00208 }
00209
00210 TEST_CASE( "aligned images have no extrinsic transformation from the image they are aligned to", "[live]" )
00211 {
00212
00213 safe_context ctx;
00214 const int device_count = rs_get_device_count(ctx, require_no_error());
00215 REQUIRE(device_count > 0);
00216
00217
00218 for(int i=0; i<device_count; ++i)
00219 {
00220 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00221 REQUIRE(dev != nullptr);
00222
00223
00224 rs_extrinsics extrin = {};
00225 rs_get_device_extrinsics(dev, RS_STREAM_RECTIFIED_COLOR, RS_STREAM_COLOR, &extrin, require_no_error());
00226 require_zero_vector(extrin.translation);
00227
00228
00229 rs_get_device_extrinsics(dev, RS_STREAM_COLOR_ALIGNED_TO_DEPTH, RS_STREAM_DEPTH, &extrin, require_no_error());
00230 require_identity_matrix(extrin.rotation);
00231 require_zero_vector(extrin.translation);
00232
00233
00234 rs_get_device_extrinsics(dev, RS_STREAM_DEPTH_ALIGNED_TO_COLOR, RS_STREAM_COLOR, &extrin, require_no_error());
00235 require_identity_matrix(extrin.rotation);
00236 require_zero_vector(extrin.translation);
00237
00238
00239 rs_get_device_extrinsics(dev, RS_STREAM_DEPTH_ALIGNED_TO_RECTIFIED_COLOR, RS_STREAM_RECTIFIED_COLOR, &extrin, require_no_error());
00240 require_identity_matrix(extrin.rotation);
00241 require_zero_vector(extrin.translation);
00242 }
00243 }
00244
00245 TEST_CASE( "streaming mode intrinsics are sane", "[live]" )
00246 {
00247
00248 safe_context ctx;
00249 const int device_count = rs_get_device_count(ctx, require_no_error());
00250 REQUIRE(device_count > 0);
00251
00252
00253 for(int i=0; i<device_count; ++i)
00254 {
00255 rs_device * dev = rs_get_device(ctx, 0, require_no_error());
00256 REQUIRE(dev != nullptr);
00257
00258
00259 for(auto stream : {RS_STREAM_DEPTH, RS_STREAM_COLOR, RS_STREAM_INFRARED})
00260 {
00261
00262 const int stream_mode_count = rs_get_stream_mode_count(dev, stream, require_no_error());
00263 REQUIRE(stream_mode_count > 0);
00264
00265
00266 for(int j=0; j<stream_mode_count; ++j)
00267 {
00268
00269 int width = 0, height = 0, framerate = 0;
00270 rs_format format = RS_FORMAT_ANY;
00271 rs_get_stream_mode(dev, stream, j, &width, &height, &format, &framerate, require_no_error());
00272
00273
00274 REQUIRE( width >= 320 );
00275 REQUIRE( width <= 1920 );
00276 REQUIRE( height >= 180 );
00277 REQUIRE( height <= 1080 );
00278 REQUIRE( format > RS_FORMAT_ANY );
00279 REQUIRE( format < RS_FORMAT_COUNT );
00280 REQUIRE( framerate >= 2 );
00281 REQUIRE( framerate <= 300 );
00282
00283
00284 rs_enable_stream(dev, stream, width, height, format, framerate, require_no_error());
00285 REQUIRE(rs_is_stream_enabled(dev, stream, require_no_error()) == 1);
00286 REQUIRE(rs_get_stream_format(dev, stream, require_no_error()) == format);
00287 REQUIRE(rs_get_stream_framerate(dev, stream, require_no_error()) == framerate);
00288
00289
00290 rs_intrinsics intrin;
00291 rs_get_stream_intrinsics(dev, stream, &intrin, require_no_error());
00292 REQUIRE( intrin.width == width );
00293 REQUIRE( intrin.height == height );
00294
00295
00296 REQUIRE( intrin.ppx > width * 0.4f );
00297 REQUIRE( intrin.ppx < width * 0.6f );
00298 REQUIRE( intrin.ppy > height * 0.4f );
00299 REQUIRE( intrin.ppy < height * 0.6f );
00300
00301
00302 REQUIRE( intrin.fx > 0.0f );
00303 REQUIRE( intrin.fy > 0.0f );
00304
00305
00306 rs_disable_stream(dev, stream, require_no_error());
00307 REQUIRE(rs_is_stream_enabled(dev, stream, require_no_error()) == 0);
00308 }
00309
00310
00311 REQUIRE(rs_is_stream_enabled(dev, stream, require_no_error()) == 0);
00312 rs_intrinsics intrin;
00313 rs_get_stream_intrinsics(dev, stream, &intrin, require_error(std::string("stream not enabled: ") + rs_stream_to_string(stream)));
00314 rs_get_stream_format(dev, stream, require_error(std::string("stream not enabled: ") + rs_stream_to_string(stream)));
00315 rs_get_stream_framerate(dev, stream, require_error(std::string("stream not enabled: ") + rs_stream_to_string(stream)));
00316 }
00317 }
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 #endif