[Bf-blender-cvs] [e56df831a95] gpencil-new-data-proposal: Add copy big grease pencil data test
Falk David
noreply at git.blender.org
Thu May 12 15:48:29 CEST 2022
Commit: e56df831a951b50cdd29d0da88c0799cfdf2f8f0
Author: Falk David
Date: Thu May 12 14:29:14 2022 +0200
Branches: gpencil-new-data-proposal
https://developer.blender.org/rBe56df831a951b50cdd29d0da88c0799cfdf2f8f0
Add copy big grease pencil data test
===================================================================
M source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc b/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
index 4bff452b076..7b64f5b437c 100644
--- a/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
+++ b/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
@@ -16,6 +16,8 @@
#include "testing/testing.h"
+#include "PIL_time_utildefines.h"
+
namespace blender::bke {
class GPLayerGroup : ::GPLayerGroup {
@@ -212,6 +214,14 @@ class GPFrame : public ::GPFrame {
return this->strokes->curve_num;
}
+ int points_num() const
+ {
+ if (this->strokes == nullptr) {
+ return 0;
+ }
+ return this->strokes->point_num;
+ }
+
GPStroke add_new_stroke(int new_points_num)
{
if (this->strokes == nullptr) {
@@ -428,6 +438,13 @@ class GPData : public ::GPData {
return this->layers_size - 1;
}
+ void add_layers(Array<StringRefNull> names)
+ {
+ for (StringRefNull name : names) {
+ this->add_layer(name);
+ }
+ }
+
int add_frame_on_layer(int layer_index, int frame_start)
{
/* TODO: Check for collisions. */
@@ -461,6 +478,13 @@ class GPData : public ::GPData {
return add_frame_on_layer(index, frame_start);
}
+ void add_frames_on_layer(int layer_index, Array<int> start_frames)
+ {
+ for (int start_frame : start_frames) {
+ add_frame_on_layer(layer_index, start_frame);
+ }
+ }
+
int strokes_num() const
{
/* TODO: could be done with parallel_for */
@@ -471,6 +495,16 @@ class GPData : public ::GPData {
return count;
}
+ int points_num() const
+ {
+ /* TODO: could be done with parallel_for */
+ int count = 0;
+ for (const GPFrame &gpf : this->frames()) {
+ count += gpf.points_num();
+ }
+ return count;
+ }
+
void set_active_layer(int layer_index)
{
if (layer_index < 0 || layer_index >= this->layers_size) {
@@ -600,6 +634,37 @@ class GPData : public ::GPData {
namespace blender::bke::gpencil::tests {
+static GPData build_gpencil_data(int num_layers,
+ int frames_per_layer,
+ int strokes_per_layer,
+ int points_per_stroke)
+{
+ GPData gpd;
+
+ Vector<StringRefNull> test_names;
+ for (const int i : IndexRange(num_layers)) {
+ test_names.append("GPLayer" + i);
+ }
+ gpd.add_layers(test_names.as_span());
+
+ Array<int> test_start_frames(IndexRange(frames_per_layer).as_span());
+ for (const int i : gpd.layers().index_range()) {
+ gpd.add_frames_on_layer(i, test_start_frames);
+ }
+
+ for (const int i : gpd.frames().index_range()) {
+ for (const int j : IndexRange(strokes_per_layer)) {
+ GPStroke stroke = gpd.frames_for_write(i).add_new_stroke(points_per_stroke);
+ for (const int k : stroke.points_positions_for_write().index_range()) {
+ stroke.points_positions_for_write()[k] = {
+ float(k), float((k * j) % stroke.points_num()), float(k + j)};
+ }
+ }
+ }
+
+ return gpd;
+}
+
TEST(gpencil_proposal, EmptyGPData)
{
GPData data;
@@ -788,11 +853,25 @@ TEST(gpencil_proposal, ChangeStrokePoints)
}
}
+TEST(gpencil_proposal, BigGPData)
+{
+ GPData data = build_gpencil_data(5, 500, 100, 100);
+
+ EXPECT_EQ(data.strokes_num(), 250e3);
+ EXPECT_EQ(data.points_num(), 25e6);
+}
+
+TEST(gpencil_proposal, BigGPDataCopy)
+{
+ GPData data = build_gpencil_data(5, 500, 100, 100);
+ GPData data_copy;
-/* 50 Layers. */
-/* 500 Frames. */
-/* 100 Strokes. */
-/* 100 Points. */
+ TIMEIT_START(BigGPDataCopy);
+ data_copy = data;
+ TIMEIT_END(BigGPDataCopy);
+ EXPECT_EQ(data_copy.strokes_num(), 250e3);
+ EXPECT_EQ(data_copy.points_num(), 25e6);
+}
} // namespace blender::bke::gpencil::tests
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list