Blender V4.3
lattice_deform_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#include "testing/testing.h"
5
6#define DO_PERF_TESTS 0
7
8#if DO_PERF_TESTS
9
10# include "BKE_idtype.hh"
11# include "BKE_lattice.hh"
12
13# include "MEM_guardedalloc.h"
14
15# include "DNA_lattice_types.h"
16# include "DNA_mesh_types.h"
17# include "DNA_object_types.h"
18
19# include "BLI_rand.hh"
20
21namespace blender::bke::tests {
22
23struct LatticeDeformTestContext {
25 Object ob_lattice;
26 Mesh mesh;
27 Object ob_mesh;
28 float (*coords)[3];
30};
31
32static void test_lattice_deform_init(LatticeDeformTestContext *ctx,
33 RandomNumberGenerator *rng,
34 int32_t num_items)
35{
36 /* Generate random input data between -5 and 5. */
37 ctx->coords = (float(*)[3])MEM_malloc_arrayN(num_items, sizeof(float[3]), __func__);
38 for (uint32_t index = 0; index < num_items; index++) {
39 ctx->coords[index][0] = (rng->get_float() - 0.5f) * 10;
40 ctx->coords[index][1] = (rng->get_float() - 0.5f) * 10;
41 ctx->coords[index][2] = (rng->get_float() - 0.5f) * 10;
42 }
43 IDType_ID_LT.init_data(&ctx->lattice.id);
44 STRNCPY(ctx->lattice.id.name, "LTLattice");
45 IDType_ID_OB.init_data(&ctx->ob_lattice.id);
46 ctx->ob_lattice.type = OB_LATTICE;
47 ctx->ob_lattice.data = &ctx->lattice;
48 IDType_ID_OB.init_data(&ctx->ob_mesh.id);
49 IDType_ID_ME.init_data(&ctx->mesh.id);
50 ctx->ob_mesh.type = OB_MESH;
51 ctx->ob_mesh.data = &ctx->mesh;
52
53 ctx->ldd = BKE_lattice_deform_data_create(&ctx->ob_lattice, &ctx->ob_mesh);
54}
55
56static void test_lattice_deform(LatticeDeformTestContext *ctx, int32_t num_items)
57{
58 for (int i = 0; i < num_items; i++) {
59 float *co = &ctx->coords[i][0];
60 BKE_lattice_deform_data_eval_co(ctx->ldd, co, 1.0f);
61 }
62}
63
64static void test_lattice_deform_free(LatticeDeformTestContext *ctx)
65{
67 MEM_freeN(ctx->coords);
68 IDType_ID_LT.free_data(&ctx->lattice.id);
69 IDType_ID_OB.free_data(&ctx->ob_lattice.id);
70 IDType_ID_OB.free_data(&ctx->ob_mesh.id);
71 IDType_ID_ME.free_data(&ctx->mesh.id);
72}
73
74TEST(lattice_deform_performance, performance_no_dvert_1)
75{
76 const int32_t num_items = 1;
77 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
78 RandomNumberGenerator rng;
79 test_lattice_deform_init(&ctx, &rng, num_items);
80 test_lattice_deform(&ctx, num_items);
81 test_lattice_deform_free(&ctx);
82}
83TEST(lattice_deform_performance, performance_no_dvert_1000)
84{
85 const int32_t num_items = 1000;
86 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
87 RandomNumberGenerator rng;
88 test_lattice_deform_init(&ctx, &rng, num_items);
89 test_lattice_deform(&ctx, num_items);
90 test_lattice_deform_free(&ctx);
91}
92TEST(lattice_deform_performance, performance_no_dvert_10000)
93{
94 const int32_t num_items = 10000;
95 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
96 RandomNumberGenerator rng;
97 test_lattice_deform_init(&ctx, &rng, num_items);
98 test_lattice_deform(&ctx, num_items);
99 test_lattice_deform_free(&ctx);
100}
101TEST(lattice_deform_performance, performance_no_dvert_100000)
102{
103 const int32_t num_items = 100000;
104 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
105 RandomNumberGenerator rng;
106 test_lattice_deform_init(&ctx, &rng, num_items);
107 test_lattice_deform(&ctx, num_items);
108 test_lattice_deform_free(&ctx);
109}
110TEST(lattice_deform_performance, performance_no_dvert_1000000)
111{
112 const int32_t num_items = 1000000;
113 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
114 RandomNumberGenerator rng;
115 test_lattice_deform_init(&ctx, &rng, num_items);
116 test_lattice_deform(&ctx, num_items);
117 test_lattice_deform_free(&ctx);
118}
119TEST(lattice_deform_performance, performance_no_dvert_10000000)
120{
121 const int32_t num_items = 10000000;
122 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
123 RandomNumberGenerator rng;
124 test_lattice_deform_init(&ctx, &rng, num_items);
125 test_lattice_deform(&ctx, num_items);
126 test_lattice_deform_free(&ctx);
127}
128
129} // namespace blender::bke::tests
130#endif
IDTypeInfo IDType_ID_OB
IDTypeInfo IDType_ID_ME
IDTypeInfo IDType_ID_LT
Definition lattice.cc:165
LatticeDeformData * BKE_lattice_deform_data_create(const Object *oblatt, const Object *ob) ATTR_WARN_UNUSED_RESULT
void BKE_lattice_deform_data_destroy(LatticeDeformData *lattice_deform_data)
void BKE_lattice_deform_data_eval_co(LatticeDeformData *lattice_deform_data, float co[3], float weight)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
Object is a sort of wrapper for general info.
@ OB_LATTICE
@ OB_MESH
Read Guarded memory(de)allocation.
Lattice lattice
draw_view in_light_buf[] float
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition mallocn.cc:45
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
TEST(action_groups, ReconstructGroupsWithReordering)
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
IDTypeInitDataFunction init_data
IDTypeFreeDataFunction free_data