Blender  V3.3
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 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 *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 (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.c.

Macro Definition Documentation

◆ C_WEIGHT

#define C_WEIGHT   1.0f

Definition at line 366 of file meshlaplacian.c.

◆ DISTANCE_EPSILON

#define DISTANCE_EPSILON   1e-4f

Definition at line 369 of file meshlaplacian.c.

◆ EPSILON

#define EPSILON   0.0001f

Definition at line 839 of file meshlaplacian.c.

◆ MESHDEFORM_LEN_THRESHOLD

#define MESHDEFORM_LEN_THRESHOLD   1e-6f

minimum length for MDefBoundIsect.len

Definition at line 847 of file meshlaplacian.c.

◆ MESHDEFORM_MIN_INFLUENCE

#define MESHDEFORM_MIN_INFLUENCE   0.0005f

Definition at line 849 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_BOUNDARY

#define MESHDEFORM_TAG_BOUNDARY   1

Definition at line 842 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_EXTERIOR

#define MESHDEFORM_TAG_EXTERIOR   3

Definition at line 844 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_INTERIOR

#define MESHDEFORM_TAG_INTERIOR   2

Definition at line 843 of file meshlaplacian.c.

◆ MESHDEFORM_TAG_UNTYPED

#define MESHDEFORM_TAG_UNTYPED   0

Definition at line 841 of file meshlaplacian.c.

◆ WEIGHT_LIMIT_END

#define WEIGHT_LIMIT_END   0.025f

Definition at line 368 of file meshlaplacian.c.

◆ WEIGHT_LIMIT_START

#define WEIGHT_LIMIT_START   0.05f

Definition at line 367 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 ( Object object,
MeshDeformModifierData mmd,
Mesh cagemesh,
float vertexcos,
int  verts_num,
float  cagemat[4][4] 
)

◆ end_progress_bar()

static void end_progress_bar ( void  )
static

Definition at line 48 of file meshlaplacian.c.

Referenced by ED_mesh_deform_bind_callback().

◆ error()

static void error ( const char *  str)
static

Definition at line 51 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(), BlenderSession::check_and_report_session_error(), blender::gpu::shader::ShaderCreateInfo::check_error(), blender::gpu::debug::check_gl_error(), clean_tracks_exec(), blender::compositor::OpenCLDevice::COM_cl_attach_memory_buffer_offset_to_kernel_parameter(), blender::compositor::OpenCLDevice::COM_cl_attach_memory_buffer_to_kernel_parameter(), blender::compositor::OpenCLDevice::COM_cl_attach_output_memory_buffer_to_kernel_parameter(), blender::compositor::OpenCLDevice::COM_cl_attach_size_to_kernel_parameter(), blender::compositor::OpenCLDevice::COM_cl_create_kernel(), blender::compositor::OpenCLDevice::COM_cl_enqueue_range(), copypose_error(), correctivesmooth_modifier_do(), Freestyle::Operators::create(), GHOST_XrContext::dispatchErrorMessage(), dynamicPaint_createUVSurface(), egl_chk(), libmv::euclidean_resection::EuclideanResectionPPnP(), blender::compositor::WriteBufferOperation::execute_opencl_region(), expr_pylike_error_test(), filtcolum(), filtrow(), blender::gpu::shader::ShaderCreateInfo::finalize(), Freestyle::FitCurveWrapper::FitCubic(), Freestyle::FitCurveWrapper::FitCurve(), get_cursor_settings(), 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(), GPU_offscreen_create(), GPU_shader_create_from_info(), GPU_shader_create_info_check_error(), ErrorHandler::handleError(), handleNumInput(), GHOST_ContextEGL::initializeDrawingContext(), GHOST_ContextWGL::initializeDrawingContext(), kernel_adaptive_sampling_convergence_check(), DenoiseImage::load(), DenoiseImage::load_previous(), 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(), 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(), pygpu_shader_create_from_info(), pyop_poll_message_get_fn(), pyrna_enum_bitmap_from_set(), pyrna_func_error_prefix(), 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(), blender::gpu::MTLCommandBufferManager::submit(), 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(), iTaSC::Distance::updateControlOutput(), and wm_xr_error_handler().

◆ harmonic_coordinates_bind()

static void harmonic_coordinates_bind ( MeshDeformModifierData mmd,
MeshDeformBind mdb 
)
static

Definition at line 1569 of file meshlaplacian.c.

References Freestyle::a, usdtokens::b(), MeshDeformModifierData::bindweights, BKE_bvhtree_from_mesh_get(), BKE_mesh_poly_normals_ensure(), 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::cage_verts_num, MeshDeformBind::cagecos, MeshDeformBind::cagemesh, MeshDeformBind::cagemesh_cache, center, copy_v3_v3(), MeshDeformModifierData::dyncellmin, MeshDeformModifierData::dyncellwidth, MeshDeformBind::dyngrid, MeshDeformModifierData::dyngrid, MeshDeformModifierData::dyngridsize, MeshDeformModifierData::dyninfluences, MeshDeformModifierData::dynverts, MeshDeformModifierData::flag, free_bvhtree_from_mesh(), MeshDeformModifierData::gridsize, MeshDeformBind::halfwidth, MDefCell::influences_num, MeshDeformModifierData::influences_num, 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, offset, MDefCell::offset, MeshDeformBind::phi, MeshDeformBind::poly_nors, progress_bar(), MeshDeformBind::semibound, MeshDeformBind::size, MeshDeformBind::size3, MeshDeformBind::tag, MeshDeformBind::totalphi, 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().

◆ 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 621 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 239 of file meshlaplacian.c.

References LaplacianSystem::faces, LaplacianSystem::faces_num, 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 119 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 107 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  verts_num,
int  faces_num,
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 357 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 42 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 45 of file meshlaplacian.c.

Referenced by ED_mesh_deform_bind_callback().

◆ waitcursor()

static void waitcursor ( int   UNUSEDval)
static

Definition at line 39 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 851 of file meshlaplacian.c.

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