Blender  V2.93
lattice_deform_test.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 by Blender Foundation.
17  */
18 #include "testing/testing.h"
19 
20 #include "BKE_idtype.h"
21 #include "BKE_lattice.h"
22 
23 #include "MEM_guardedalloc.h"
24 
25 #include "DNA_lattice_types.h"
26 #include "DNA_mesh_types.h"
27 #include "DNA_object_types.h"
28 
29 #include "BLI_rand.hh"
30 
31 namespace blender::bke::tests {
32 
38  float (*coords)[3];
40 };
41 
44  int32_t num_items)
45 {
46  /* Generate random input data between -5 and 5. */
47  ctx->coords = (float(*)[3])MEM_malloc_arrayN(sizeof(float[3]), num_items, __func__);
48  for (uint32_t index = 0; index < num_items; index++) {
49  ctx->coords[index][0] = (rng->get_float() - 0.5f) * 10;
50  ctx->coords[index][1] = (rng->get_float() - 0.5f) * 10;
51  ctx->coords[index][2] = (rng->get_float() - 0.5f) * 10;
52  }
54  strcpy(ctx->lattice.id.name, "LTLattice");
56  ctx->ob_lattice.type = OB_LATTICE;
57  ctx->ob_lattice.data = &ctx->lattice;
60  ctx->ob_mesh.type = OB_MESH;
61  ctx->ob_mesh.data = &ctx->mesh;
62 
64 }
65 
67 {
68  for (int i = 0; i < num_items; i++) {
69  float *co = &ctx->coords[i][0];
70  BKE_lattice_deform_data_eval_co(ctx->ldd, co, 1.0f);
71  }
72 }
73 
75 {
77  MEM_freeN(ctx->coords);
82 }
83 
84 TEST(lattice_deform_performance, performance_no_dvert_1)
85 {
86  const int32_t num_items = 1;
87  LatticeDeformTestContext ctx = {{{nullptr}}};
89  test_lattice_deform_init(&ctx, &rng, num_items);
90  test_lattice_deform(&ctx, num_items);
92 }
93 TEST(lattice_deform_performance, performance_no_dvert_1000)
94 {
95  const int32_t num_items = 1000;
96  LatticeDeformTestContext ctx = {{{nullptr}}};
98  test_lattice_deform_init(&ctx, &rng, num_items);
99  test_lattice_deform(&ctx, num_items);
101 }
102 TEST(lattice_deform_performance, performance_no_dvert_10000)
103 {
104  const int32_t num_items = 10000;
105  LatticeDeformTestContext ctx = {{{nullptr}}};
107  test_lattice_deform_init(&ctx, &rng, num_items);
108  test_lattice_deform(&ctx, num_items);
110 }
111 TEST(lattice_deform_performance, performance_no_dvert_100000)
112 {
113  const int32_t num_items = 100000;
114  LatticeDeformTestContext ctx = {{{nullptr}}};
116  test_lattice_deform_init(&ctx, &rng, num_items);
117  test_lattice_deform(&ctx, num_items);
119 }
120 TEST(lattice_deform_performance, performance_no_dvert_1000000)
121 {
122  const int32_t num_items = 1000000;
123  LatticeDeformTestContext ctx = {{{nullptr}}};
125  test_lattice_deform_init(&ctx, &rng, num_items);
126  test_lattice_deform(&ctx, num_items);
128 }
129 TEST(lattice_deform_performance, performance_no_dvert_10000000)
130 {
131  const int32_t num_items = 10000000;
132  LatticeDeformTestContext ctx = {{{nullptr}}};
134  test_lattice_deform_init(&ctx, &rng, num_items);
135  test_lattice_deform(&ctx, num_items);
137 }
138 
139 } // namespace blender::bke::tests
typedef float(TangentPoint)[2]
IDTypeInfo IDType_ID_OB
Definition: object.c:1135
IDTypeInfo IDType_ID_ME
Definition: mesh.c:344
IDTypeInfo IDType_ID_LT
Definition: lattice.c:186
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:48
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static void test_lattice_deform_free(LatticeDeformTestContext *ctx)
TEST(mat3_vec_to_roll, UnitMatrix)
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)
unsigned int uint32_t
Definition: stdint.h:83
signed int int32_t
Definition: stdint.h:80
IDTypeInitDataFunction init_data
Definition: BKE_idtype.h:156
IDTypeFreeDataFunction free_data
Definition: BKE_idtype.h:167
char name[66]
Definition: DNA_ID.h:283
void * data