26#define SMOOTH_LAPLACIAN_MAX_EDGE_PERCENTAGE 1.8f
27#define SMOOTH_LAPLACIAN_MIN_EDGE_PERCENTAGE 0.15f
58 LaplacianSystem *sys,
int usex,
int usey,
int usez,
int preserve_volume);
60 BMOperator *op,
float vini,
float vend,
int usex,
int usey,
int usez);
87 memset(sys->eweights, val,
sizeof(
float) * sys->numEdges);
88 memset(sys->
fweights, val,
sizeof(
float[3]) * sys->numLoops);
89 memset(sys->ring_areas, val,
sizeof(
float) * sys->numVerts);
90 memset(sys->vlengths, val,
sizeof(
float) * sys->numVerts);
91 memset(sys->vweights, val,
sizeof(
float) * sys->numVerts);
92 memset(sys->zerola, val,
sizeof(
bool) * sys->numVerts);
99 sys->numEdges = a_numEdges;
100 sys->numLoops = a_numLoops;
101 sys->numVerts = a_numVerts;
104 if (!sys->eweights) {
116 if (!sys->ring_areas) {
122 if (!sys->vlengths) {
128 if (!sys->vweights) {
171 const float *v1 =
e->v1->
co;
172 const float *
v2 =
e->v2->
co;
177 if (w1 > sys->min_area) {
179 sys->eweights[i] = w1;
180 sys->vlengths[idv1] += w1;
181 sys->vlengths[idv2] += w1;
184 sys->zerola[idv1] =
true;
185 sys->zerola[idv2] =
true;
189 uint l_curr_index = 0;
193 l_curr_index += f->
len;
206 const float *co_prev = l_iter->
prev->
v->
co;
207 const float *co_curr = l_iter->
v->
co;
208 const float *co_next = l_iter->
next->
v->
co;
210 const float areaf =
area_tri_v3(co_prev, co_curr, co_next);
212 if (areaf < sys->min_area) {
213 sys->zerola[vi_curr] =
true;
216 sys->ring_areas[vi_prev] += areaf;
217 sys->ring_areas[vi_curr] += areaf;
218 sys->ring_areas[vi_next] += areaf;
224 sys->
fweights[l_curr_index][0] += w1;
225 sys->
fweights[l_curr_index][1] += w2;
226 sys->
fweights[l_curr_index][2] += w3;
228 sys->vweights[vi_prev] += w1 + w2;
229 sys->vweights[vi_curr] += w2 + w3;
230 sys->vweights[vi_next] += w1 + w3;
231 }
while ((
void)(l_curr_index += 1), (l_iter = l_iter->
next) != l_first);
243 uint l_curr_index = 0;
247 l_curr_index += f->
len;
268 sys->
fweights[l_curr_index][1] * sys->vweights[vi_prev]);
272 sys->
fweights[l_curr_index][0] * sys->vweights[vi_prev]);
278 sys->
fweights[l_curr_index][2] * sys->vweights[vi_curr]);
282 sys->
fweights[l_curr_index][1] * sys->vweights[vi_curr]);
288 sys->
fweights[l_curr_index][2] * sys->vweights[vi_next]);
292 sys->
fweights[l_curr_index][0] * sys->vweights[vi_next]);
301 }
while ((
void)(l_curr_index += 1), (l_iter = l_iter->
next) != l_first);
309 if (sys->zerola[idv1] ==
false && sys->zerola[idv2] ==
false) {
311 sys->
context, idv1, idv2, sys->eweights[i] * sys->vlengths[idv1]);
313 sys->
context, idv2, idv1, sys->eweights[i] * sys->vlengths[idv2]);
338 BMOperator *op,
float vini,
float vend,
int usex,
int usey,
int usez)
345 beta =
pow(vini / vend, 1.0f / 3.0f);
361 LaplacianSystem *sys,
int usex,
int usey,
int usez,
int preserve_volume)
366 float *vi1, *vi2, ve1[3], ve2[3];
389 sys->zerola[idv1] =
true;
390 sys->zerola[idv2] =
true;
394 if (preserve_volume) {
399 if (sys->zerola[m_vertex_id] ==
false) {
411 if (preserve_volume) {
421 bool usex, usey, usez, preserve_volume;
422 float lambda_factor, lambda_border;
443 sys->min_area = 0.00001f;
469 if ((sys->zerola[i] ==
false) &&
472 (sys->ring_areas[i] != 0.0f))
474 w = sys->vweights[i] * sys->ring_areas[i];
475 sys->vweights[i] = (
w == 0.0f) ? 0.0f : -lambda_factor / (4.0f *
w);
476 w = sys->vlengths[i];
477 sys->vlengths[i] = (
w == 0.0f) ? 0.0f : -lambda_border * 2.0f /
w;
481 sys->
context, i, i, 1.0f + lambda_factor / (4.0f * sys->ring_areas[i]));
Read Blender memory allocation and freeing.
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_index_get(ele)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
#define SMOOTH_LAPLACIAN_MAX_EDGE_PERCENTAGE
#define SMOOTH_LAPLACIAN_MIN_EDGE_PERCENTAGE
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void EIG_linear_solver_variable_set(LinearSolver *solver, int rhs, int index, double value)
void EIG_linear_solver_right_hand_side_add(LinearSolver *solver, int rhs, int index, double value)
void EIG_linear_solver_variable_unlock(LinearSolver *solver, int index)
LinearSolver * EIG_linear_least_squares_solver_new(int num_rows, int num_columns, int num_right_hand_sides)
void EIG_linear_solver_delete(LinearSolver *solver)
double EIG_linear_solver_variable_get(LinearSolver *solver, int rhs, int index)
void EIG_linear_solver_matrix_add(LinearSolver *solver, int row, int col, double value)
bool EIG_linear_solver_solve(LinearSolver *solver)
void EIG_linear_solver_variable_lock(LinearSolver *solver, int index)
ccl_device_inline float beta(const float x, const float y)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
static void memset_laplacian_system(LaplacianSystem *sys, int val)
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
static void init_laplacian_matrix(LaplacianSystem *sys)
static LaplacianSystem * init_laplacian_system(int a_numEdges, int a_numLoops, int a_numVerts)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void volume_preservation(BMOperator *op, float vini, float vend, int usex, int usey, int usez)
void MEM_delete_void(void *vmemh)
static void delete_laplacian_system(LaplacianSystem *sys)
double BM_mesh_calc_volume(BMesh *bm, bool is_signed)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BMesh const char void * data
void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op)
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static void delete_void_pointer(void *data)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float v3[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
float area_tri_v3(const float v1[3], const float v2[3], const float v3[3])
static void fill_laplacian_matrix(LaplacianSystem *sys)
static bool vert_is_boundary(BMVert *v)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void validate_solution(LaplacianSystem *sys, int usex, int usey, int usez, int preserve_volume)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]