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