Blender V4.5
meshlaplacian.cc File Reference
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "BLI_map.hh"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_memarena.h"
#include "BLI_ordered_edge.hh"
#include "BLI_string.h"
#include "BLT_translation.hh"
#include "BKE_attribute.hh"
#include "BKE_bvhutils.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_wrapper.hh"
#include "BKE_modifier.hh"
#include "ED_armature.hh"
#include "ED_mesh.hh"
#include "ED_object_vgroup.hh"
#include "eigen_capi.h"
#include "meshlaplacian.h"
#include <algorithm>

Go to the source code of this file.

Classes

struct  LaplacianSystem
struct  LaplacianSystem::HeatWeighting
struct  BVHCallbackUserData
struct  MDefBoundIsect
struct  MDefBindInfluence
struct  MeshDeformBind
struct  MeshDeformIsect
struct  MeshRayCallbackData

Macros

#define C_WEIGHT   1.0f
#define WEIGHT_LIMIT_START   0.05f
#define WEIGHT_LIMIT_END   0.025f
#define DISTANCE_EPSILON   1e-4f
#define EPSILON   0.0001f
#define MESHDEFORM_TAG_UNTYPED   0
#define MESHDEFORM_TAG_BOUNDARY   1
#define MESHDEFORM_TAG_INTERIOR   2
#define MESHDEFORM_TAG_EXTERIOR   3
#define MESHDEFORM_LEN_THRESHOLD   1e-6f
#define MESHDEFORM_MIN_INFLUENCE   0.0005f

Functions

static void waitcursor (int)
static void progress_bar (int, const char *)
static void start_progress_bar ()
static void end_progress_bar ()
static void error (const char *str)
static void laplacian_increase_edge_count (blender::Map< blender::OrderedEdge, int > &edgehash, int v1, int v2)
static int laplacian_edge_count (const blender::Map< blender::OrderedEdge, int > &edgehash, int v1, int v2)
static void laplacian_triangle_area (LaplacianSystem *sys, int i1, int i2, int i3)
static void laplacian_triangle_weights (LaplacianSystem *sys, int f, int i1, int i2, int i3)
static LaplacianSystemlaplacian_system_construct_begin (int verts_num, int faces_num, int lsq)
void laplacian_add_vertex (LaplacianSystem *sys, float *co, int pinned)
void laplacian_add_triangle (LaplacianSystem *sys, int v1, int v2, int v3)
static void laplacian_system_construct_end (LaplacianSystem *sys)
static void laplacian_system_delete (LaplacianSystem *sys)
void laplacian_begin_solve (LaplacianSystem *sys, int index)
void laplacian_add_right_hand_side (LaplacianSystem *sys, int v, float value)
int laplacian_system_solve (LaplacianSystem *sys)
float laplacian_system_get_solution (LaplacianSystem *sys, int v)
static void bvh_callback (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static void heat_ray_tree_create (LaplacianSystem *sys)
static int heat_ray_source_visible (LaplacianSystem *sys, int vertex, int source)
static float heat_source_distance (LaplacianSystem *sys, int vertex, int source)
static int heat_source_closest (LaplacianSystem *sys, int vertex, int source)
static void heat_set_H (LaplacianSystem *sys, int vertex)
static void heat_calc_vnormals (LaplacianSystem *sys)
static void heat_laplacian_create (LaplacianSystem *sys)
static void heat_system_free (LaplacianSystem *sys)
static float heat_limit_weight (float weight)
void heat_bone_weighting (Object *ob, Mesh *mesh, float(*verts)[3], int numbones, bDeformGroup **dgrouplist, bDeformGroup **dgroupflip, float(*root)[3], float(*tip)[3], const bool *selected, const char **r_error_str)
static void harmonic_ray_callback (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static MDefBoundIsectmeshdeform_ray_tree_intersect (MeshDeformBind *mdb, const float co1[3], const float co2[3])
static int meshdeform_inside_cage (MeshDeformBind *mdb, float *co)
BLI_INLINE int meshdeform_index (MeshDeformBind *mdb, int x, int y, int z, int n)
BLI_INLINE void meshdeform_cell_center (MeshDeformBind *mdb, int x, int y, int z, int n, float *center)
static void meshdeform_add_intersections (MeshDeformBind *mdb, int x, int y, int z)
static void meshdeform_bind_floodfill (MeshDeformBind *mdb)
static float meshdeform_boundary_phi (const MeshDeformBind *mdb, const MDefBoundIsect *isect, int cagevert)
static float meshdeform_interp_w (MeshDeformBind *mdb, const float *gridvec, float *, int)
static void meshdeform_check_semibound (MeshDeformBind *mdb, int x, int y, int z)
static float meshdeform_boundary_total_weight (MeshDeformBind *mdb, int x, int y, int z)
static void meshdeform_matrix_add_cell (MeshDeformBind *mdb, LinearSolver *context, int x, int y, int z)
static void meshdeform_matrix_add_rhs (MeshDeformBind *mdb, LinearSolver *context, int x, int y, int z, int cagevert)
static void meshdeform_matrix_add_semibound_phi (MeshDeformBind *mdb, int x, int y, int z, int cagevert)
static void meshdeform_matrix_add_exterior_phi (MeshDeformBind *mdb, int x, int y, int z, int)
static void meshdeform_matrix_solve (MeshDeformModifierData *mmd, MeshDeformBind *mdb)
static void harmonic_coordinates_bind (MeshDeformModifierData *mmd, MeshDeformBind *mdb)
void ED_mesh_deform_bind_callback (Object *object, MeshDeformModifierData *mmd, Mesh *cagemesh, float *vertexcos, int verts_num, float cagemat[4][4])

Variables

static const int MESHDEFORM_OFFSET [7][3]

Detailed Description

Algorithms using the mesh laplacian.

Definition in file meshlaplacian.cc.

Macro Definition Documentation

◆ C_WEIGHT

#define C_WEIGHT   1.0f

Definition at line 358 of file meshlaplacian.cc.

Referenced by heat_set_H().

◆ DISTANCE_EPSILON

#define DISTANCE_EPSILON   1e-4f

Definition at line 361 of file meshlaplacian.cc.

Referenced by heat_source_closest().

◆ EPSILON

#define EPSILON   0.0001f

Definition at line 845 of file meshlaplacian.cc.

◆ MESHDEFORM_LEN_THRESHOLD

#define MESHDEFORM_LEN_THRESHOLD   1e-6f

minimum length for MDefBoundIsect.len

Definition at line 853 of file meshlaplacian.cc.

Referenced by meshdeform_ray_tree_intersect().

◆ MESHDEFORM_MIN_INFLUENCE

#define MESHDEFORM_MIN_INFLUENCE   0.0005f

◆ MESHDEFORM_TAG_BOUNDARY

#define MESHDEFORM_TAG_BOUNDARY   1

Definition at line 848 of file meshlaplacian.cc.

Referenced by meshdeform_add_intersections(), and meshdeform_bind_floodfill().

◆ MESHDEFORM_TAG_EXTERIOR

◆ MESHDEFORM_TAG_INTERIOR

#define MESHDEFORM_TAG_INTERIOR   2

Definition at line 849 of file meshlaplacian.cc.

Referenced by meshdeform_bind_floodfill(), and meshdeform_matrix_solve().

◆ MESHDEFORM_TAG_UNTYPED

#define MESHDEFORM_TAG_UNTYPED   0

Definition at line 847 of file meshlaplacian.cc.

Referenced by harmonic_coordinates_bind(), and meshdeform_bind_floodfill().

◆ WEIGHT_LIMIT_END

#define WEIGHT_LIMIT_END   0.025f

Definition at line 360 of file meshlaplacian.cc.

Referenced by heat_limit_weight().

◆ WEIGHT_LIMIT_START

#define WEIGHT_LIMIT_START   0.05f

Definition at line 359 of file meshlaplacian.cc.

Referenced by heat_limit_weight().

Function Documentation

◆ bvh_callback()

void bvh_callback ( void * userdata,
int index,
const BVHTreeRay * ray,
BVHTreeRayHit * hit )
static

◆ ED_mesh_deform_bind_callback()

◆ end_progress_bar()

void end_progress_bar ( )
static

Definition at line 46 of file meshlaplacian.cc.

References end_progress_bar().

Referenced by ED_mesh_deform_bind_callback(), and end_progress_bar().

◆ error()

void error ( const char * str)
static

Definition at line 47 of file meshlaplacian.cc.

References printf, and str.

Referenced by meshdeform_matrix_solve().

◆ harmonic_coordinates_bind()

void harmonic_coordinates_bind ( MeshDeformModifierData * mmd,
MeshDeformBind * mdb )
static

Definition at line 1578 of file meshlaplacian.cc.

References b, MeshDeformModifierData::bindweights, BLI_memarena_free(), BLI_memarena_new(), BLI_MEMARENA_STD_BUFSIZE, BLI_memarena_use_calloc(), MeshDeformBind::boundisect, MeshDeformBind::bvhdata, MeshDeformBind::bvhtree, MeshDeformBind::cage_verts_num, MeshDeformBind::cagecos, MeshDeformBind::cagemesh, MeshDeformBind::cagemesh_cache, copy_v3_v3(), MeshDeformModifierData::dyncellmin, MeshDeformModifierData::dyncellwidth, MeshDeformBind::dyngrid, MeshDeformModifierData::dyngrid, MeshDeformModifierData::dyngridsize, MeshDeformModifierData::dyninfluences, MeshDeformModifierData::dynverts, MeshDeformModifierData::flag, MeshDeformModifierData::gridsize, MeshDeformBind::halfwidth, harmonic_coordinates_bind(), MDefCell::influences_num, MeshDeformModifierData::influences_num, INIT_MINMAX, MeshDeformBind::inside, MeshDeformBind::max, MEM_calloc_arrayN(), MEM_callocN(), MEM_freeN(), MeshDeformBind::memarena, meshdeform_add_intersections(), meshdeform_bind_floodfill(), meshdeform_check_semibound(), meshdeform_inside_cage(), meshdeform_matrix_solve(), MESHDEFORM_TAG_UNTYPED, MeshDeformBind::min, minmax_v3v3_v3(), MOD_MDEF_DYNAMIC_BIND, MDefBindInfluence::next, MDefCell::offset, MeshDeformBind::phi, progress_bar(), MeshDeformBind::semibound, MeshDeformBind::size, MeshDeformBind::size3, MeshDeformBind::tag, MeshDeformBind::totalphi, blender::bke::BVHTreeFromMesh::tree, MDefBindInfluence::vertex, MDefInfluence::vertex, MeshDeformBind::vertexcos, MeshDeformBind::verts_num, MDefBindInfluence::weight, MDefInfluence::weight, MeshDeformBind::weights, MeshDeformBind::width, x, y, and z().

Referenced by ED_mesh_deform_bind_callback(), and harmonic_coordinates_bind().

◆ harmonic_ray_callback()

◆ heat_bone_weighting()

void heat_bone_weighting ( Object * ob,
Mesh * mesh,
float(*) verts[3],
int numbones,
bDeformGroup ** dgrouplist,
bDeformGroup ** dgroupflip,
float(*) root[3],
float(*) tip[3],
const bool * selected,
const char ** r_error_str )

Definition at line 627 of file meshlaplacian.cc.

References Geometry::attributes, LaplacianSystem::HeatWeighting::corner_tris, blender::bke::mesh::corner_tris_calc(), LaplacianSystem::HeatWeighting::corner_verts, Mesh::corners_num, Mesh::editflag, blender::bke::Face, Mesh::faces_num, LaplacianSystem::HeatWeighting::H, LaplacianSystem::heat, heat_bone_weighting(), heat_laplacian_create(), heat_limit_weight(), heat_ray_tree_create(), heat_source_closest(), heat_system_free(), i, blender::offset_indices::OffsetIndices< T >::index_range(), laplacian_add_right_hand_side(), laplacian_begin_solve(), laplacian_system_construct_begin(), laplacian_system_construct_end(), laplacian_system_delete(), laplacian_system_get_solution(), laplacian_system_solve(), blender::bke::AttributeAccessor::lookup_or_default(), mask(), ME_EDIT_MIRROR_TOPO, ME_EDIT_PAINT_FACE_SEL, ME_EDIT_PAINT_VERT_SEL, MEM_calloc_arrayN(), MEM_freeN(), MEM_mallocN(), mesh_get_x_mirror_vert(), Object::mode, N_, LaplacianSystem::HeatWeighting::numsource, OB_MODE_WEIGHT_PAINT, LaplacianSystem::HeatWeighting::p, blender::bke::Point, poly_to_tri_count(), LaplacianSystem::HeatWeighting::root, blender::Span< T >::slice(), LaplacianSystem::HeatWeighting::tip, LaplacianSystem::HeatWeighting::tris_num, LaplacianSystem::HeatWeighting::verts, LaplacianSystem::HeatWeighting::verts_num, Mesh::verts_num, blender::ed::object::vgroup_vert_add(), blender::ed::object::vgroup_vert_remove(), blender::ed::object::vgroup_vert_weight(), WEIGHT_ADD, and WEIGHT_REPLACE.

Referenced by add_verts_to_dgroups(), and heat_bone_weighting().

◆ heat_calc_vnormals()

◆ heat_laplacian_create()

◆ heat_limit_weight()

float heat_limit_weight ( float weight)
static

◆ heat_ray_source_visible()

◆ heat_ray_tree_create()

◆ heat_set_H()

◆ heat_source_closest()

int heat_source_closest ( LaplacianSystem * sys,
int vertex,
int source )
static

◆ heat_source_distance()

◆ heat_system_free()

◆ laplacian_add_right_hand_side()

void laplacian_add_right_hand_side ( LaplacianSystem * sys,
int v,
float value )

◆ laplacian_add_triangle()

void laplacian_add_triangle ( LaplacianSystem * sys,
int v1,
int v2,
int v3 )

◆ laplacian_add_vertex()

void laplacian_add_vertex ( LaplacianSystem * sys,
float * co,
int pinned )

◆ laplacian_begin_solve()

◆ laplacian_edge_count()

◆ laplacian_increase_edge_count()

◆ laplacian_system_construct_begin()

◆ laplacian_system_construct_end()

◆ laplacian_system_delete()

◆ laplacian_system_get_solution()

float laplacian_system_get_solution ( LaplacianSystem * sys,
int v )

◆ laplacian_system_solve()

◆ laplacian_triangle_area()

void laplacian_triangle_area ( LaplacianSystem * sys,
int i1,
int i2,
int i3 )
static

◆ laplacian_triangle_weights()

◆ meshdeform_add_intersections()

◆ meshdeform_bind_floodfill()

◆ meshdeform_boundary_phi()

◆ meshdeform_boundary_total_weight()

◆ meshdeform_cell_center()

BLI_INLINE void meshdeform_cell_center ( MeshDeformBind * mdb,
int x,
int y,
int z,
int n,
float * center )

◆ meshdeform_check_semibound()

void meshdeform_check_semibound ( MeshDeformBind * mdb,
int x,
int y,
int z )
static

◆ meshdeform_index()

◆ meshdeform_inside_cage()

◆ meshdeform_interp_w()

float meshdeform_interp_w ( MeshDeformBind * mdb,
const float * gridvec,
float * ,
int  )
static

◆ meshdeform_matrix_add_cell()

◆ meshdeform_matrix_add_exterior_phi()

void meshdeform_matrix_add_exterior_phi ( MeshDeformBind * mdb,
int x,
int y,
int z,
int  )
static

◆ meshdeform_matrix_add_rhs()

◆ meshdeform_matrix_add_semibound_phi()

◆ meshdeform_matrix_solve()

◆ meshdeform_ray_tree_intersect()

◆ progress_bar()

void progress_bar ( int ,
const char *  )
static

Definition at line 44 of file meshlaplacian.cc.

References progress_bar().

Referenced by harmonic_coordinates_bind(), meshdeform_matrix_solve(), and progress_bar().

◆ start_progress_bar()

void start_progress_bar ( )
static

Definition at line 45 of file meshlaplacian.cc.

References start_progress_bar().

Referenced by ED_mesh_deform_bind_callback(), and start_progress_bar().

◆ waitcursor()

void waitcursor ( int )
static

Definition at line 43 of file meshlaplacian.cc.

References waitcursor().

Referenced by ED_mesh_deform_bind_callback(), and waitcursor().

Variable Documentation

◆ MESHDEFORM_OFFSET

const int MESHDEFORM_OFFSET[7][3]
static
Initial value:
= {
{0, 0, 0},
{1, 0, 0},
{-1, 0, 0},
{0, 1, 0},
{0, -1, 0},
{0, 0, 1},
{0, 0, -1},
}

Definition at line 857 of file meshlaplacian.cc.

Referenced by meshdeform_cell_center(), meshdeform_index(), and meshdeform_inside_cage().