Blender  V2.93
Classes | Macros | Typedefs | Functions | Variables
meshlaplacian.c File Reference
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_alloca.h"
#include "BLI_edgehash.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_string.h"
#include "BLT_translation.h"
#include "BKE_bvhutils.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_mesh_wrapper.h"
#include "BKE_modifier.h"
#include "ED_armature.h"
#include "ED_mesh.h"
#include "DEG_depsgraph.h"
#include "eigen_capi.h"
#include "meshlaplacian.h"

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
 

Typedefs

typedef struct BVHCallbackUserData BVHCallbackUserData
 
typedef struct MDefBoundIsect MDefBoundIsect
 
typedef struct MDefBindInfluence MDefBindInfluence
 
typedef struct MeshDeformBind MeshDeformBind
 
typedef struct MeshDeformIsect MeshDeformIsect
 

Functions

static void waitcursor (int UNUSED(val))
 
static void progress_bar (int UNUSED(dummy_val), const char *UNUSED(dummy))
 
static void start_progress_bar (void)
 
static void end_progress_bar (void)
 
static void error (const char *str)
 
static void laplacian_increase_edge_count (EdgeHash *edgehash, int v1, int v2)
 
static int laplacian_edge_count (EdgeHash *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 totvert, int totface, 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 *me, float(*verts)[3], int numbones, bDeformGroup **dgrouplist, bDeformGroup **dgroupflip, float(*root)[3], float(*tip)[3], const int *selected, const char **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 *UNUSED(vec), int UNUSED(cagevert))
 
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 UNUSED(cagevert))
 
static void meshdeform_matrix_solve (MeshDeformModifierData *mmd, MeshDeformBind *mdb)
 
static void harmonic_coordinates_bind (MeshDeformModifierData *mmd, MeshDeformBind *mdb)
 
void ED_mesh_deform_bind_callback (MeshDeformModifierData *mmd, Mesh *cagemesh, float *vertexcos, int totvert, float cagemat[4][4])
 

Variables

static const int MESHDEFORM_OFFSET [7][3]
 

Macro Definition Documentation

◆ C_WEIGHT

#define C_WEIGHT   1.0f

Definition at line 382 of file meshlaplacian.c.

◆ DISTANCE_EPSILON

#define DISTANCE_EPSILON   1e-4f

Definition at line 385 of file meshlaplacian.c.

◆ EPSILON

#define EPSILON   0.0001f

Definition at line 855 of file meshlaplacian.c.

◆ MESHDEFORM_LEN_THRESHOLD

#define MESHDEFORM_LEN_THRESHOLD   1e-6f

minimum length for MDefBoundIsect.len

Definition at line 863 of file meshlaplacian.c.

◆ MESHDEFORM_MIN_INFLUENCE

#define MESHDEFORM_MIN_INFLUENCE   0.0005f

Definition at line 865 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_BOUNDARY

#define MESHDEFORM_TAG_BOUNDARY   1

Definition at line 858 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_EXTERIOR

#define MESHDEFORM_TAG_EXTERIOR   3

Definition at line 860 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_INTERIOR

#define MESHDEFORM_TAG_INTERIOR   2

Definition at line 859 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_UNTYPED

#define MESHDEFORM_TAG_UNTYPED   0

Definition at line 857 of file meshlaplacian.c.

◆ WEIGHT_LIMIT_END

#define WEIGHT_LIMIT_END   0.025f

Definition at line 384 of file meshlaplacian.c.

◆ WEIGHT_LIMIT_START

#define WEIGHT_LIMIT_START   0.05f

Definition at line 383 of file meshlaplacian.c.

Typedef Documentation

◆ BVHCallbackUserData

◆ MDefBindInfluence

◆ MDefBoundIsect

◆ MeshDeformBind

◆ MeshDeformIsect

Function Documentation

◆ bvh_callback()

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

◆ ED_mesh_deform_bind_callback()

void ED_mesh_deform_bind_callback ( MeshDeformModifierData mmd,
Mesh cagemesh,
float vertexcos,
int  totvert,
float  cagemat[4][4] 
)

◆ end_progress_bar()

static void end_progress_bar ( void  )
static

Definition at line 62 of file meshlaplacian.c.

Referenced by ED_mesh_deform_bind_callback().

◆ error()

static void error ( const char *  str)
static

Definition at line 65 of file meshlaplacian.c.

References str.

Referenced by add_verts_to_dgroups(), ANIM_apply_keyingset(), AVI_print_error(), Freestyle::BezierCurve::BezierCurve(), Freestyle::StrokeShaders::BezierCurveShader::BezierCurveShader(), Freestyle::Operators::bidirectionalChain(), BKE_ptcache_write(), BKE_tracking_reconstruction_solve(), BLI_bitmap_draw_2d_line_v2v2i(), BLI_file_alias_target(), BLI_file_attributes(), blo_do_versions_280(), bm_edges_sort_winding(), BM_faces_join(), bmo_join_triangles_exec(), BMO_op_vinitf(), bpy_batch_remove(), bpy_user_map(), Freestyle::Operators::chain(), blender::gpu::debug::check_gl_error(), clean_tracks_exec(), blender::compositor::OpenCLDevice::COM_clAttachMemoryBufferOffsetToKernelParameter(), blender::compositor::OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(), blender::compositor::OpenCLDevice::COM_clAttachOutputMemoryBufferToKernelParameter(), blender::compositor::OpenCLDevice::COM_clAttachSizeToKernelParameter(), blender::compositor::OpenCLDevice::COM_clCreateKernel(), blender::compositor::OpenCLDevice::COM_clEnqueueRange(), copypose_error(), correctivesmooth_modifier_do(), Freestyle::Operators::create(), GHOST_XrContext::dispatchErrorMessage(), dynamicPaint_createUVSurface(), egl_chk(), libmv::euclidean_resection::EuclideanResectionPPnP(), blender::compositor::WriteBufferOperation::executeOpenCLRegion(), expr_pylike_error_test(), filtcolum(), filtrow(), Freestyle::FitCurveWrapper::FitCubic(), Freestyle::FitCurveWrapper::FitCurve(), get_egl_error_enum_string(), get_egl_error_message_string(), get_glew_error_enum_string(), get_limit_motor_info2(), GHOST_NDOFManagerCocoa::GHOST_NDOFManagerCocoa(), glew_chk(), ErrorHandler::handleError(), handleNumInput(), GHOST_ContextCGL::initializeDrawingContext(), GHOST_ContextEGL::initializeDrawingContext(), GHOST_ContextWGL::initializeDrawingContext(), kernel_do_adaptive_stopping(), DenoiseImage::load(), DenoiseImage::load_neighbors(), make_renderinfo_string(), MemorY_ErroR(), merge_pixels(), meshdeform_matrix_solve(), libmv::Dogleg< Function, Jacobian, Solver >::minimize(), libmv::LevenbergMarquardt< Function, Jacobian, Solver >::minimize(), modifyMesh(), open_images(), blender::compositor::opencl_initialize(), blender::compositor::OpenCLDevice::OpenCLDevice(), DenoiseImage::parse_channels(), parse_channels(), pose_proxy_sync(), blender::gpu::Shader::print_log(), ptcache_basic_header_read(), ptcache_disk_frame_to_mem(), ptcache_file_header_begin_read(), ptcache_mem_frame_to_disk(), ptcache_read_stream(), ptcache_write(), ptcache_write_stream(), pyrna_set_to_enum_bitmap(), quad_calc_error(), reconstruct_retrieve_libmv_tracks(), rna_def_function(), RNA_def_property(), RNA_def_property_srna(), RNA_def_struct_ptr(), rna_validate_identifier(), save_output(), DenoiseImage::save_output(), Freestyle::Operators::sequentialSplit(), Device::set_error(), solve_camera_freejob(), surfaceGenerateGrid(), mv::TEST(), btDeformableLagrangianForce::testDerivative(), btDeformableLagrangianForce::testHessian(), ui_number_from_string_units(), UI_ThemeGetColorPtr(), libmv::Dogleg< Function, Jacobian, Solver >::Update(), libmv::LevenbergMarquardt< Function, Jacobian, Solver >::Update(), BlenderSession::update_status_progress(), iTaSC::Distance::updateControlOutput(), and wm_xr_error_handler().

◆ harmonic_coordinates_bind()

static void harmonic_coordinates_bind ( MeshDeformModifierData mmd,
MeshDeformBind mdb 
)
static

Definition at line 1582 of file meshlaplacian.c.

References Freestyle::a, MeshDeformModifierData::bindweights, BKE_bvhtree_from_mesh_get(), BKE_mesh_runtime_looptri_ensure(), BLI_memarena_free(), BLI_memarena_new(), BLI_MEMARENA_STD_BUFSIZE, BLI_memarena_use_calloc(), MeshDeformBind::boundisect, MeshDeformBind::bvhdata, MeshDeformBind::bvhtree, BVHTREE_FROM_LOOPTRI, MeshDeformBind::cagecos, MeshDeformBind::cagemesh, MeshDeformBind::cagemesh_cache, CD_NORMAL, center, copy_v3_v3(), CustomData_get_layer(), MeshDeformModifierData::dyncellmin, MeshDeformModifierData::dyncellwidth, MeshDeformBind::dyngrid, MeshDeformModifierData::dyngrid, MeshDeformModifierData::dyngridsize, MeshDeformModifierData::dyninfluences, MeshDeformModifierData::dynverts, MeshDeformModifierData::flag, free_bvhtree_from_mesh(), MeshDeformModifierData::gridsize, MeshDeformBind::halfwidth, INIT_MINMAX, MeshDeformBind::inside, MeshDeformBind::looptri, MeshDeformBind::max, MeshRayCallbackData::mdb, 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(), MeshDeformBind::mloop, Mesh::mloop, MOD_MDEF_DYNAMIC_BIND, MeshDeformBind::mpoly, Mesh::mpoly, MDefBindInfluence::next, MDefCell::offset, MeshDeformBind::phi, MeshDeformBind::poly_nors, progress_bar(), MeshDeformBind::semibound, MeshDeformBind::size, MeshDeformBind::size3, MeshDeformBind::tag, MeshDeformBind::totalphi, MeshDeformBind::totcagevert, MDefCell::totinfluence, MeshDeformModifierData::totinfluence, MeshDeformBind::totvert, MDefBindInfluence::vertex, MDefInfluence::vertex, MeshDeformBind::vertexcos, MDefBindInfluence::weight, MDefInfluence::weight, MeshDeformBind::weights, MeshDeformBind::width, x, y, and z.

Referenced by ED_mesh_deform_bind_callback().

◆ harmonic_ray_callback()

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

◆ heat_bone_weighting()

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

◆ heat_calc_vnormals()

static void heat_calc_vnormals ( LaplacianSystem sys)
static

◆ heat_laplacian_create()

static void heat_laplacian_create ( LaplacianSystem sys)
static

◆ heat_limit_weight()

static float heat_limit_weight ( float  weight)
static

Definition at line 637 of file meshlaplacian.c.

References t, WEIGHT_LIMIT_END, and WEIGHT_LIMIT_START.

Referenced by heat_bone_weighting().

◆ heat_ray_source_visible()

static int heat_ray_source_visible ( LaplacianSystem sys,
int  vertex,
int  source 
)
static

◆ heat_ray_tree_create()

static void heat_ray_tree_create ( LaplacianSystem sys)
static

◆ heat_set_H()

static void heat_set_H ( LaplacianSystem sys,
int  vertex 
)
static

◆ heat_source_closest()

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

◆ heat_source_distance()

static float heat_source_distance ( LaplacianSystem sys,
int  vertex,
int  source 
)
static

◆ heat_system_free()

static void heat_system_free ( LaplacianSystem sys)
static

◆ 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 
)

Definition at line 253 of file meshlaplacian.c.

References LaplacianSystem::faces, LaplacianSystem::totface, v1, and v2.

Referenced by heat_laplacian_create().

◆ laplacian_add_vertex()

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

◆ laplacian_begin_solve()

void laplacian_begin_solve ( LaplacianSystem sys,
int  index 
)

◆ laplacian_edge_count()

static int laplacian_edge_count ( EdgeHash edgehash,
int  v1,
int  v2 
)
static

Definition at line 133 of file meshlaplacian.c.

References BLI_edgehash_lookup(), v1, and v2.

Referenced by laplacian_triangle_weights().

◆ laplacian_increase_edge_count()

static void laplacian_increase_edge_count ( EdgeHash edgehash,
int  v1,
int  v2 
)
static

Definition at line 121 of file meshlaplacian.c.

References BLI_edgehash_ensure_p(), v1, and v2.

Referenced by laplacian_system_construct_end().

◆ laplacian_system_construct_begin()

static LaplacianSystem* laplacian_system_construct_begin ( int  totvert,
int  totface,
int  lsq 
)
static

◆ laplacian_system_construct_end()

static void laplacian_system_construct_end ( LaplacianSystem sys)
static

◆ laplacian_system_delete()

static void laplacian_system_delete ( LaplacianSystem sys)
static

◆ laplacian_system_get_solution()

float laplacian_system_get_solution ( LaplacianSystem sys,
int  v 
)

Definition at line 373 of file meshlaplacian.c.

References LaplacianSystem::context, EIG_linear_solver_variable_get(), and v.

Referenced by heat_bone_weighting().

◆ laplacian_system_solve()

int laplacian_system_solve ( LaplacianSystem sys)

◆ laplacian_triangle_area()

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

◆ laplacian_triangle_weights()

static void laplacian_triangle_weights ( LaplacianSystem sys,
int  f,
int  i1,
int  i2,
int  i3 
)
static

◆ meshdeform_add_intersections()

static void meshdeform_add_intersections ( MeshDeformBind mdb,
int  x,
int  y,
int  z 
)
static

◆ meshdeform_bind_floodfill()

static void meshdeform_bind_floodfill ( MeshDeformBind mdb)
static

◆ meshdeform_boundary_phi()

static float meshdeform_boundary_phi ( const MeshDeformBind mdb,
const MDefBoundIsect isect,
int  cagevert 
)
static

◆ meshdeform_boundary_total_weight()

static float meshdeform_boundary_total_weight ( MeshDeformBind mdb,
int  x,
int  y,
int  z 
)
static

◆ meshdeform_cell_center()

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

◆ meshdeform_check_semibound()

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

◆ meshdeform_index()

BLI_INLINE int meshdeform_index ( MeshDeformBind mdb,
int  x,
int  y,
int  z,
int  n 
)

◆ meshdeform_inside_cage()

static int meshdeform_inside_cage ( MeshDeformBind mdb,
float co 
)
static

◆ meshdeform_interp_w()

static float meshdeform_interp_w ( MeshDeformBind mdb,
const float gridvec,
float UNUSEDvec,
int   UNUSEDcagevert 
)
static

◆ meshdeform_matrix_add_cell()

static void meshdeform_matrix_add_cell ( MeshDeformBind mdb,
LinearSolver context,
int  x,
int  y,
int  z 
)
static

◆ meshdeform_matrix_add_exterior_phi()

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

◆ meshdeform_matrix_add_rhs()

static void meshdeform_matrix_add_rhs ( MeshDeformBind mdb,
LinearSolver context,
int  x,
int  y,
int  z,
int  cagevert 
)
static

◆ meshdeform_matrix_add_semibound_phi()

static void meshdeform_matrix_add_semibound_phi ( MeshDeformBind mdb,
int  x,
int  y,
int  z,
int  cagevert 
)
static

◆ meshdeform_matrix_solve()

static void meshdeform_matrix_solve ( MeshDeformModifierData mmd,
MeshDeformBind mdb 
)
static

◆ meshdeform_ray_tree_intersect()

static MDefBoundIsect* meshdeform_ray_tree_intersect ( MeshDeformBind mdb,
const float  co1[3],
const float  co2[3] 
)
static

◆ progress_bar()

static void progress_bar ( int   UNUSEDdummy_val,
const char *  UNUSEDdummy 
)
static

Definition at line 56 of file meshlaplacian.c.

Referenced by harmonic_coordinates_bind(), and meshdeform_matrix_solve().

◆ start_progress_bar()

static void start_progress_bar ( void  )
static

Definition at line 59 of file meshlaplacian.c.

Referenced by ED_mesh_deform_bind_callback().

◆ waitcursor()

static void waitcursor ( int   UNUSEDval)
static

Definition at line 53 of file meshlaplacian.c.

Referenced by ED_mesh_deform_bind_callback().

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 867 of file meshlaplacian.c.

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