Blender  V3.3
lattice_deform_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. */
3 #include "testing/testing.h"
4 
5 #include "BKE_idtype.h"
6 #include "BKE_lattice.h"
7 
8 #include "MEM_guardedalloc.h"
9 
10 #include "DNA_lattice_types.h"
11 #include "DNA_mesh_types.h"
12 #include "DNA_object_types.h"
13 
14 #include "BLI_rand.hh"
15 
16 namespace blender::bke::tests {
17 
23  float (*coords)[3];
25 };
26 
29  int32_t num_items)
30 {
31  /* Generate random input data between -5 and 5. */
32  ctx->coords = (float(*)[3])MEM_malloc_arrayN(num_items, sizeof(float[3]), __func__);
33  for (uint32_t index = 0; index < num_items; index++) {
34  ctx->coords[index][0] = (rng->get_float() - 0.5f) * 10;
35  ctx->coords[index][1] = (rng->get_float() - 0.5f) * 10;
36  ctx->coords[index][2] = (rng->get_float() - 0.5f) * 10;
37  }
39  strcpy(ctx->lattice.id.name, "LTLattice");
41  ctx->ob_lattice.type = OB_LATTICE;
42  ctx->ob_lattice.data = &ctx->lattice;
45  ctx->ob_mesh.type = OB_MESH;
46  ctx->ob_mesh.data = &ctx->mesh;
47 
49 }
50 
52 {
53  for (int i = 0; i < num_items; i++) {
54  float *co = &ctx->coords[i][0];
55  BKE_lattice_deform_data_eval_co(ctx->ldd, co, 1.0f);
56  }
57 }
58 
60 {
62  MEM_freeN(ctx->coords);
67 }
68 
69 TEST(lattice_deform_performance, performance_no_dvert_1)
70 {
71  const int32_t num_items = 1;
72  LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
74  test_lattice_deform_init(&ctx, &rng, num_items);
75  test_lattice_deform(&ctx, num_items);
77 }
78 TEST(lattice_deform_performance, performance_no_dvert_1000)
79 {
80  const int32_t num_items = 1000;
81  LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
83  test_lattice_deform_init(&ctx, &rng, num_items);
84  test_lattice_deform(&ctx, num_items);
86 }
87 TEST(lattice_deform_performance, performance_no_dvert_10000)
88 {
89  const int32_t num_items = 10000;
90  LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
92  test_lattice_deform_init(&ctx, &rng, num_items);
93  test_lattice_deform(&ctx, num_items);
95 }
96 TEST(lattice_deform_performance, performance_no_dvert_100000)
97 {
98  const int32_t num_items = 100000;
99  LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
101  test_lattice_deform_init(&ctx, &rng, num_items);
102  test_lattice_deform(&ctx, num_items);
104 }
105 TEST(lattice_deform_performance, performance_no_dvert_1000000)
106 {
107  const int32_t num_items = 1000000;
108  LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
110  test_lattice_deform_init(&ctx, &rng, num_items);
111  test_lattice_deform(&ctx, num_items);
113 }
114 TEST(lattice_deform_performance, performance_no_dvert_10000000)
115 {
116  const int32_t num_items = 10000000;
117  LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
119  test_lattice_deform_init(&ctx, &rng, num_items);
120  test_lattice_deform(&ctx, num_items);
122 }
123 
124 } // namespace blender::bke::tests
typedef float(TangentPoint)[2]
IDTypeInfo IDType_ID_OB
Definition: object.cc:1222
IDTypeInfo IDType_ID_ME
Definition: mesh.cc:364
IDTypeInfo IDType_ID_LT
Definition: lattice.c:175
void BKE_lattice_deform_data_destroy(struct LatticeDeformData *lattice_deform_data)
void BKE_lattice_deform_data_eval_co(struct LatticeDeformData *lattice_deform_data, float co[3], float weight)
struct LatticeDeformData * BKE_lattice_deform_data_create(const struct Object *oblatt, const struct Object *ob) ATTR_WARN_UNUSED_RESULT
Object is a sort of wrapper for general info.
@ OB_LATTICE
@ OB_MESH
Read Guarded memory(de)allocation.
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:34
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
static void test_lattice_deform_free(LatticeDeformTestContext *ctx)
static void test_lattice_deform(LatticeDeformTestContext *ctx, int32_t num_items)
static void test_lattice_deform_init(LatticeDeformTestContext *ctx, RandomNumberGenerator *rng, int32_t num_items)
TEST(action_groups, ReconstructGroupsWithReordering)
Definition: action_test.cc:17
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
IDTypeInitDataFunction init_data
Definition: BKE_idtype.h:151
IDTypeFreeDataFunction free_data
Definition: BKE_idtype.h:162
char name[66]
Definition: DNA_ID.h:378
void * data