Blender scripts for computing geodesic distance

Overview

GeoDoodle

Geodesic distance computation for Blender meshes

Table of Contents

  1. Overivew
  2. Usage
  3. Implementation

Overview

This addon provides an operator for computing geodesic distances on general meshes (ngons and triangular).

Geodesic distance describes a shortest path from any point on the surface to some boundary, e.g. a selected vertex. It can differ from simple Euclidian distance significantly.

Prerequisites

The addon uses the SciPy math library for efficient sparse matrix computations.

SciPy is not shipped with the Python installation in Blender, so you may need to install the package once. A convenient method is to use the text editor.

Note: You may need to run Blender in administrator mode for permissions to install into the packages folder!

  1. Open Blender.

  2. Open a text editor window and create a new text.

  3. Paste in the following code and execute the script:

    import sys
    import subprocess
    
    py_exec = sys.executable
    py_prefix = sys.exec_prefix
    # ensure pip is installed & update
    subprocess.call([str(py_exec), "-m", "ensurepip", "--user"])
    subprocess.call([str(py_exec), "-m", "pip", "install", "--target={}".format(py_prefix), "--upgrade", "pip"])
    # install dependencies using pip
    # dependencies such as 'numpy' could be added to the end of this command's list
    subprocess.call([str(py_exec),"-m", "pip", "install", "--target={}".format(py_prefix), "scipy"])
    

    Source: https://blender.stackexchange.com/a/153520

Usage

  1. Create a mesh object.

  2. Add a boundary vertex group. The default name should be "Boundary", although the operator can work with arbitrary vertex groups.

    Procedurally generated vertex groups are also supported (e.g. with a proximity modifier). However, topology modifiers such as subdivision are not recommended because the operator will copy the modifier result to the base mesh.

  3. Select the mesh object.

  4. Invoke the Geodesic Distance operator from the dropdown next to the vertex group list.

Implementation

The implementation is based on the Heat Method as described by Crane et al. 1. The Laplacian for polygonal meshes is described in the paper "Polygon laplacian made simple" 2.

1: Crane, Keenan, Clarisse Weischedel, and Max Wardetzky. "Geodesics in heat: A new approach to computing distance based on heat flow." ACM Transactions on Graphics (TOG) 32.5 (2013): 1-11.

2: Bunge, Astrid, et al. "Polygon laplacian made simple." Computer Graphics Forum. Vol. 39. No. 2. 2020.

Comments
  • some error after long thinking

    some error after long thinking

    It is all hanged for some seconds on my four cores (multithreading?) And error:

    location: <unknown location>:-1
    Error: Python: Traceback (most recent call last):
      File "/home/ololo/Downloads/INSTALL/blender-2.92.0-linux64/2.92/scripts/addons/geodoodle/operator.py", line 180, in execute
        heat_map_gen.generate(boundary_reader, obstacle_reader, heat_writer, distance_writer, self.heat_time_scale)
      File "/home/ololo/Downloads/INSTALL/blender-2.92.0-linux64/2.92/scripts/addons/geodoodle/heat_map.py", line 228, in generate
        M, S, G, D = self.compute_laplacian(vertex_stiffness)
      File "/home/ololo/Downloads/INSTALL/blender-2.92.0-linux64/2.92/scripts/addons/geodoodle/heat_map.py", line 123, in compute_laplacian
        A = np.fromiter
    
    (A_values(), dtype=float, count=numverts * numverts).reshape(numverts, numverts)
      File "/home/ololo/Downloads/INSTALL/blender-2.92.0-linux64/2.92/scripts/addons/geodoodle/heat_map.py", line 122, in A_values
        yield 2.0 * sum((np.dot(Cnext[j, k, :] - C[j, k, :], Cnext[i, k, :] - C[i, k, :]) for k in range(numverts)), start=0.0)
    TypeError: sum() takes no keyword arguments
    
    location: <unknown location>:-1
    

    geodoodle.blend.zip

    opened by nortikin 4
  • TypeError: sum() takes no keyword arguments

    TypeError: sum() takes no keyword arguments

    Hi Lukas, I created a boundary vertex groups (with a selection of boundary vertices) and hit 'Geodesic distance' and get the following error.

    Computing Geodesic Distance using scipy
    Python: Traceback (most recent call last):
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\operator.py", line 184, in execute
        heat_map_gen.generate(boundary_reader, obstacle_reader, heat_writer, distance_writer, self.heat_time_scale)
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\heat_map.py", line 304, in generate
        M, S, G, D = self.compute_laplacian(vertex_stiffness)
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\heat_map.py", line 171, in compute_laplacian
        A = np.fromiter(A_values(), dtype=float, count=numverts * numverts).reshape(numverts, numverts)
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\heat_map.py", line 170, in A_values
        yield 2.0 * sum((np.dot(Cnext[j, k, :] - C[j, k, :], Cnext[i, k, :] - C[i, k, :]) for k in range(numverts)), start=0.0)
    TypeError: sum() takes no keyword arguments
    
    location: <unknown location>:-1
    Error: Python: Traceback (most recent call last):
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\operator.py", line 184, in execute
        heat_map_gen.generate(boundary_reader, obstacle_reader, heat_writer, distance_writer, self.heat_time_scale)
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\heat_map.py", line 304, in generate
        M, S, G, D = self.compute_laplacian(vertex_stiffness)
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\heat_map.py", line 171, in compute_laplacian
        A = np.fromiter(A_values(), dtype=float, count=numverts * numverts).reshape(numverts, numverts)
      File "C:\Users\h\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\geodoodle-main\heat_map.py", line 170, in A_values
        yield 2.0 * sum((np.dot(Cnext[j, k, :] - C[j, k, :], Cnext[i, k, :] - C[i, k, :]) for k in range(numverts)), start=0.0)
    TypeError: sum() takes no keyword arguments
    
    location: <unknown location>:-1
    

    No Complains or bug fixing request here, just curios and wanted to play around. Is this on my side?

    duplicate 
    opened by Heinz-Loepmeier 2
  • Replace large dense numpy matrix computations with scipy

    Replace large dense numpy matrix computations with scipy

    This drastically reduces memory requirements and runtime, at the cost of more complexity when constructing matrices.

    Requires scipy packages in the Blender python installation. Instructions have been added in the readme.

    opened by lukas-toenne 0
  • Switch to scipy for sparse matrices

    Switch to scipy for sparse matrices

    While numpy has all necessary solvers to compute the geodesic density, it only supports dense arrays. This quickly becomes a limiting factor for performance and especially memory requirements.

    Switch to using scipy for matrices and solvers, which has support for sparse matrix construction.

    opened by lukas-toenne 0
  • Unit lengths option

    Unit lengths option

    Awesome utility, thank you!

    I was a bit confused about distances originally, my test model is huge and vertex weights are capped at 1.0. I worked out what was happening by looking at the uvs after using the uv writer.

    For my purposes I made the max length 1.0 by adding:

    d /= np.max(d)

    In compute distance here https://github.com/lukas-toenne/geodoodle/blob/main/geometry_math.py#L98

    It would be amazing if that were an option exposed in the ui.

    Thanks again!

    opened by dantreble 0
  • Boundary conditions

    Boundary conditions

    Boundaries conditions currently reflect heat, which distorts the gradient and the geodesic distance field. Crane et al. suggest averaged boundary conditions to mimic a surface without boundaries.

    https://raw.githubusercontent.com/lukas-toenne/geodoodle/main/images/Island.png

    opened by lukas-toenne 1
Owner
null
Tensorflow implementation of the paper "HumanGPS: Geodesic PreServing Feature for Dense Human Correspondences", CVPR 2021.

HumanGPS: Geodesic PreServing Feature for Dense Human Correspondences Tensorflow implementation of the paper "HumanGPS: Geodesic PreServing Feature fo

Google Interns 50 Dec 21, 2022
Implementation of ICCV2021(Oral) paper - VMNet: Voxel-Mesh Network for Geodesic-aware 3D Semantic Segmentation

VMNet: Voxel-Mesh Network for Geodesic-Aware 3D Semantic Segmentation Created by Zeyu HU Introduction This work is based on our paper VMNet: Voxel-Mes

HU Zeyu 82 Dec 27, 2022
Learn about quantum computing and algorithm on quantum computing

quantum_computing this repo contains everything i learn about quantum computing and algorithm on quantum computing what is aquantum computing quantum

arfy slowy 8 Dec 25, 2022
Sky Computing: Accelerating Geo-distributed Computing in Federated Learning

Sky Computing Introduction Sky Computing is a load-balanced framework for federated learning model parallelism. It adaptively allocate model layers to

HPC-AI Tech 72 Dec 27, 2022
Rlmm blender toolkit - A set of tools to streamline level generation in UDK straight from Blender

rlmm_blender_toolkit A set of tools to streamline level generation in UDK straig

Rocket League Mapmaking 0 Jan 15, 2022
Scripts and a shader to get you started on setting up an exported Koikatsu character in Blender.

KK Blender Shader Pack A plugin and a shader to get you started with setting up an exported Koikatsu character in Blender. The plugin is a Blender add

null 166 Jan 1, 2023
3ds-Ghidra-Scripts - Ghidra scripts to help with 3ds reverse engineering

3ds Ghidra Scripts These are ghidra scripts to help with 3ds reverse engineering

Zak 7 May 23, 2022
Omniverse sample scripts - A guide for developing with Python scripts on NVIDIA Ominverse

Omniverse sample scripts ここでは、NVIDIA Omniverse ( https://www.nvidia.com/ja-jp/om

ft-lab (Yutaka Yoshisaka) 37 Nov 17, 2022
Distributional Sliced-Wasserstein distance code

Distributional Sliced Wasserstein distance This is a pytorch implementation of the paper "Distributional Sliced-Wasserstein and Applications to Genera

VinAI Research 39 Jan 1, 2023
Official implementation of "MetaSDF: Meta-learning Signed Distance Functions"

MetaSDF: Meta-learning Signed Distance Functions Project Page | Paper | Data Vincent Sitzmann*, Eric Ryan Chan*, Richard Tucker, Noah Snavely Gordon W

Vincent Sitzmann 100 Jan 1, 2023
Distance Encoding for GNN Design

Distance-encoding for GNN design This repository is the official PyTorch implementation of the DEGNN and DEAGNN framework reported in the paper: Dista

null 172 Nov 8, 2022
This is an official implementation of the paper "Distance-aware Quantization", accepted to ICCV2021.

PyTorch implementation of DAQ This is an official implementation of the paper "Distance-aware Quantization", accepted to ICCV2021. For more informatio

CV Lab @ Yonsei University 36 Nov 4, 2022
Implementation of Neural Distance Embeddings for Biological Sequences (NeuroSEED) in PyTorch

Neural Distance Embeddings for Biological Sequences Official implementation of Neural Distance Embeddings for Biological Sequences (NeuroSEED) in PyTo

Gabriele Corso 56 Dec 23, 2022
Official PyTorch implementation of "Camera Distance-aware Top-down Approach for 3D Multi-person Pose Estimation from a Single RGB Image", ICCV 2019

PoseNet of "Camera Distance-aware Top-down Approach for 3D Multi-person Pose Estimation from a Single RGB Image" Introduction This repo is official Py

Gyeongsik Moon 677 Dec 25, 2022
Real-Time Social Distance Monitoring tool using Computer Vision

Social Distance Detector A Real-Time Social Distance Monitoring Tool Table of Contents Motivation YOLO Theory Detection Output Tech Stack Functionalit

Pranav B 13 Oct 14, 2022
Neural-Pull: Learning Signed Distance Functions from Point Clouds by Learning to Pull Space onto Surfaces(ICML 2021)

Neural-Pull: Learning Signed Distance Functions from Point Clouds by Learning to Pull Space onto Surfaces(ICML 2021) This repository contains the code

null 149 Dec 15, 2022
A-SDF: Learning Disentangled Signed Distance Functions for Articulated Shape Representation (ICCV 2021)

A-SDF: Learning Disentangled Signed Distance Functions for Articulated Shape Representation (ICCV 2021) This repository contains the official implemen

null 81 Dec 14, 2022
Implementation of the Chamfer Distance as a module for pyTorch

Chamfer Distance for pyTorch This is an implementation of the Chamfer Distance as a module for pyTorch. It is written as a custom C++/CUDA extension.

Christian Diller 205 Jan 5, 2023