abc_export_test.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "testing/testing.h"
  2. // Keep first since utildefines defines AT which conflicts with STL
  3. #include "intern/abc_util.h"
  4. #include "intern/abc_exporter.h"
  5. extern "C" {
  6. #include "BLI_utildefines.h"
  7. #include "BKE_main.h"
  8. #include "BLI_math.h"
  9. #include "DNA_scene_types.h"
  10. }
  11. #include "DEG_depsgraph.h"
  12. class TestableAbcExporter : public AbcExporter {
  13. public:
  14. TestableAbcExporter(Main *bmain, const char *filename, ExportSettings &settings)
  15. : AbcExporter(bmain, filename, settings)
  16. {
  17. }
  18. void getShutterSamples(unsigned int nr_of_samples,
  19. bool time_relative,
  20. std::vector<double> &samples)
  21. {
  22. AbcExporter::getShutterSamples(nr_of_samples, time_relative, samples);
  23. }
  24. void getFrameSet(unsigned int nr_of_samples, std::set<double> &frames)
  25. {
  26. AbcExporter::getFrameSet(nr_of_samples, frames);
  27. }
  28. };
  29. class AlembicExportTest : public testing::Test {
  30. protected:
  31. ExportSettings settings;
  32. Scene scene;
  33. Depsgraph *depsgraph;
  34. TestableAbcExporter *exporter;
  35. Main *bmain;
  36. virtual void SetUp()
  37. {
  38. settings.frame_start = 31.0;
  39. settings.frame_end = 223.0;
  40. /* Fake a 25 FPS scene with a nonzero base (because that's sometimes forgotten) */
  41. scene.r.frs_sec = 50;
  42. scene.r.frs_sec_base = 2;
  43. bmain = BKE_main_new();
  44. /* TODO(sergey): Pass scene layer somehow? */
  45. ViewLayer *view_layer = (ViewLayer *)scene.view_layers.first;
  46. settings.depsgraph = depsgraph = DEG_graph_new(&scene, view_layer, DAG_EVAL_VIEWPORT);
  47. settings.scene = &scene;
  48. settings.view_layer = view_layer;
  49. exporter = NULL;
  50. }
  51. virtual void TearDown()
  52. {
  53. BKE_main_free(bmain);
  54. DEG_graph_free(depsgraph);
  55. delete exporter;
  56. }
  57. // Call after setting up the settings.
  58. void createExporter()
  59. {
  60. exporter = new TestableAbcExporter(bmain, "somefile.abc", settings);
  61. }
  62. };
  63. TEST_F(AlembicExportTest, TimeSamplesFullShutter)
  64. {
  65. settings.shutter_open = 0.0;
  66. settings.shutter_close = 1.0;
  67. createExporter();
  68. std::vector<double> samples;
  69. /* test 5 samples per frame */
  70. exporter->getShutterSamples(5, true, samples);
  71. EXPECT_EQ(5, samples.size());
  72. EXPECT_NEAR(1.240, samples[0], 1e-5f);
  73. EXPECT_NEAR(1.248, samples[1], 1e-5f);
  74. EXPECT_NEAR(1.256, samples[2], 1e-5f);
  75. EXPECT_NEAR(1.264, samples[3], 1e-5f);
  76. EXPECT_NEAR(1.272, samples[4], 1e-5f);
  77. /* test same, but using frame number offset instead of time */
  78. exporter->getShutterSamples(5, false, samples);
  79. EXPECT_EQ(5, samples.size());
  80. EXPECT_NEAR(0.0, samples[0], 1e-5f);
  81. EXPECT_NEAR(0.2, samples[1], 1e-5f);
  82. EXPECT_NEAR(0.4, samples[2], 1e-5f);
  83. EXPECT_NEAR(0.6, samples[3], 1e-5f);
  84. EXPECT_NEAR(0.8, samples[4], 1e-5f);
  85. /* use the same setup to test getFrameSet() */
  86. std::set<double> frames;
  87. exporter->getFrameSet(5, frames);
  88. EXPECT_EQ(965, frames.size());
  89. EXPECT_EQ(1, frames.count(31.0));
  90. EXPECT_EQ(1, frames.count(31.2));
  91. EXPECT_EQ(1, frames.count(31.4));
  92. EXPECT_EQ(1, frames.count(31.6));
  93. EXPECT_EQ(1, frames.count(31.8));
  94. }
  95. TEST_F(AlembicExportTest, TimeSamples180degShutter)
  96. {
  97. settings.shutter_open = -0.25;
  98. settings.shutter_close = 0.25;
  99. createExporter();
  100. std::vector<double> samples;
  101. /* test 5 samples per frame */
  102. exporter->getShutterSamples(5, true, samples);
  103. EXPECT_EQ(5, samples.size());
  104. EXPECT_NEAR(1.230, samples[0], 1e-5f);
  105. EXPECT_NEAR(1.234, samples[1], 1e-5f);
  106. EXPECT_NEAR(1.238, samples[2], 1e-5f);
  107. EXPECT_NEAR(1.242, samples[3], 1e-5f);
  108. EXPECT_NEAR(1.246, samples[4], 1e-5f);
  109. /* test same, but using frame number offset instead of time */
  110. exporter->getShutterSamples(5, false, samples);
  111. EXPECT_EQ(5, samples.size());
  112. EXPECT_NEAR(-0.25, samples[0], 1e-5f);
  113. EXPECT_NEAR(-0.15, samples[1], 1e-5f);
  114. EXPECT_NEAR(-0.05, samples[2], 1e-5f);
  115. EXPECT_NEAR(0.05, samples[3], 1e-5f);
  116. EXPECT_NEAR(0.15, samples[4], 1e-5f);
  117. /* Use the same setup to test getFrameSet().
  118. * Here only a few numbers are tested, due to rounding issues. */
  119. std::set<double> frames;
  120. exporter->getFrameSet(5, frames);
  121. EXPECT_EQ(965, frames.size());
  122. EXPECT_EQ(1, frames.count(30.75));
  123. EXPECT_EQ(1, frames.count(30.95));
  124. EXPECT_EQ(1, frames.count(31.15));
  125. }