Signed distance fields (SDFs) and Truncated Signed Distance Field(TSDF)

2024-09-02 06:36

本文主要是介绍Signed distance fields (SDFs) and Truncated Signed Distance Field(TSDF),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. Signed distance fields (SDFs)

笔记来源:
[1] Signed distance fields (SDFs)
[2] Signed Distance Function (SDF): Implicit curves or surfaces
[3] Ray Marching and Signed Distance Functions
[4] Truncated Signed Distance Function
[5] Wiki/Signed distance function

1.1 What is SDF?

SDF是一种物体表面或形状的隐式表示方法

Signed distance functions, or SDFs for short, when passed the coordinates of a point in space, return the shortest distance between that point and some surface. The sign of the return value indicates whether the point is inside that surface or outside (hence signed distance function).

SDF输入:平面/空间点的位置
SDF输出:该点到最近的物体表面的距离
例1:平面内2D圆的SDF表示

圆心: ( a , b ) 、半径: r = 1 圆的表达式: ( x − a ) 2 + ( y − b ) 2 − 1 = 0 d ( x , y ) = ( x − a ) 2 + ( x − b ) 2 − 1 \text{圆心:}(a,b)、\text{半径:}r=1\\ ~\\ \text{圆的表达式}:(x-a)^2+(y-b)^2-1=0\\ ~\\ d(x,y)=\sqrt{(x-a)^2+(x-b)^2 }-1 圆心:(a,b)半径:r=1 圆的表达式(xa)2+(yb)21=0 d(x,y)=(xa)2+(xb)2 1
平面内各个点到圆的最近距离,若该点在圆外则距离为正( d ( x , y ) > 0 d(x,y)\gt 0 d(x,y)>0),若该点刚好在圆上则距离为0( d ( x , y ) = 0 d(x,y)=0 d(x,y)=0),若该点在圆内则距离为负( d ( x , y ) < 0 d(x,y)\lt 0 d(x,y)<0

例2:点到线段的距离
一点P到线段AB的距离等价于线段QP的长度,其中Q为线段AB上离点P最近的点

于是线段AB的SDF表示:
S A B ( x , y ) = λ A + ( 1 − λ ) B S_{AB}(x,y)=\lambda A+(1-\lambda)B SAB(x,y)=λA+(1λ)B
其中 λ \lambda λ
w ⃗ = P − A 、 v ⃗ = B − A λ = < w ⃗ , v ⃗ > ∣ ∣ v ⃗ ∣ ∣ 2 \vec{w}=P-A、\vec{v}=B-A\\ ~\\ \lambda=\frac{<\vec{w},\vec{v}>}{||\vec{v}||^2} w =PAv =BA λ=∣∣v 2<w ,v >
如果 0 ≤ λ ≤ 1 0\leq \lambda\leq 1 0λ1,则点在线段AB上,若 λ < 0 \lambda\lt 0 λ<0或者 λ > 1 \lambda\gt1 λ>1,则点在直线AB上但不在线段AB上

类似的,在3D空间中,我们也可以通过单个SDF表示物体表面
下图来自:Inigo Quilez/articles/distance functions



我们也可以通过各个简单物体的SDF进行布尔运算表示任何复杂物体表面




Constructive Solid Geometry(CSG)
Constructive solid geometry, or CSG for short, is a method of creating complex geometric shapes from simple ones via boolean operations. CSG is built on 3 primitive operations: intersection ( ∩ ), union ( ∪ ), and difference ( − )

1.2 Ray Marching

Ray Tracing 和 Ray Marching 的区别
In raytracing, the scene is typically defined in terms of explicit geometry: triangles, spheres, etc. To find the intersection between the view ray and the scene, we do a series of geometric intersection tests: where does this ray intersect with this triangle, if at all? What about this one? What about this sphere?

In raymarching, the entire scene is defined in terms of a signed distance function. To find the intersection between the view ray and the scene, we start at the camera, and move a point along the view ray, bit by bit. At each step, we ask “Is this point inside the scene surface?”, or alternately phrased, “Does the SDF evaluate to a negative number at this point?“. If it does, we’re done! We hit something. If it’s not, we keep going up to some maximum number of steps along the ray.

We could just step along a very small increment of the view ray every time, but we can do much better than this (both in terms of speed and in terms of accuracy) using “sphere tracing”. Instead of taking a tiny step, we take the maximum step we know is safe without going through the surface: we step by the distance to the surface, which the SDF provides us!
In this diagram, p 0 p_0 p0​​ is the camera. The blue line lies along the ray direction cast from the camera through the view plane. The first step taken is quite large: it steps by the shortest distance to the surface. Since the point on the surface closest to p 0 p_0 p0​​ doesn’t lie along the view ray, we keep stepping until we eventually get to the surface, at p 4 p_4 p4

在1.1小节中我们表示完了物体表面,接下来我们考虑如何画出SDF的结果,即渲染

物体表面最终呈现的颜色是由光线反射角度、材质等等决定的
我们需要回答两个问题:
(1)Does the ray hit the surface?
(2)If so,where,at what angle is the surface?
If the ray doesn’t hit the surface, we just colour in the pixel white (or transparent).
If it does, we need to know what angle the surface is at to know how to shade it.
先来看看第一个问题ray是否击中了物体表面?
我们沿着ray向前进,计算ray上一些点离最近物体表面的距离,如果距离为0表明ray与物体相交,若沿着ray前进时计算的距离没有为0的情况,意味着这条ray与物体并没有相交,通常在这种情况下,我们会在前进一定步数后截断,不再对该条ray上的点计算距离

在计算机图形学中大多数 lighting model 使用表面法向量来计算某种材质表面上某个点的颜色,当scene由显式几何定义时,如三角面元,法向量在三角面元的三个顶点指定,其他点的法向量由插值计算得到。当scene由SDF定义时,我们使用梯度来计算法向量

如果ray击中了物体表面,那么我们如何计算表面的法向量?
方案一:可以由深度图计算梯度进而得到每个点的法向量
方案二:直接对SDF计算梯度

有了物体表面法向量,之后就可以计算该物体在具体场景中的颜色了,本篇仅聚焦于SDF,故不再展开

2.Truncated Signed Distance Field(TSDF)

Truncated Signed Distance Function (TSDF) is a simplified way to represent 3D shapes or surfaces, which stores the distance information for points near the surface up to a certain threshold. It is used in applications like 3D reconstruction and surface rendering to create accurate and efficient representations of 3D scenes.

Truncation: In a Truncated Signed Distance Function, we limit or “truncate” the range of distances that we care about. This means that we only consider distances up to a certain threshold, and ignore any distances beyond that. Truncation is useful because it simplifies the representation of the 3D shape and reduces the amount of data we need to store.
This trunction is essential to limit the influence of voxels far from the surface, ensuring more accurate integration close to the surface.

The main purpose of TSDF is to represent and reconstruct 3D surfaces or shapes from different measurements or observations, like depth images from a 3D camera or point clouds from a LiDAR sensor. By combining these measurements using TSDF, we can create a more accurate and complete representation of the 3D surface.

下图来自:截断符号距离 | TSDF, Truncated Signed Distance Function

这篇关于Signed distance fields (SDFs) and Truncated Signed Distance Field(TSDF)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1129267

相关文章

MonoHuman: Animatable Human Neural Field from Monocular Video 翻译

MonoHuman:来自单目视频的可动画人类神经场 摘要。利用自由视图控制来动画化虚拟化身对于诸如虚拟现实和数字娱乐之类的各种应用来说是至关重要的。已有的研究试图利用神经辐射场(NeRF)的表征能力从单目视频中重建人体。最近的工作提出将变形网络移植到NeRF中,以进一步模拟人类神经场的动力学,从而动画化逼真的人类运动。然而,这种流水线要么依赖于姿态相关的表示,要么由于帧无关的优化而缺乏运动一致性

【spring】does not have member field ‘com.sun.tools.javac.tree.JCTree qualid

spring-in-action-6-samples 的JDK版本 最小是11,我使用 了22: jdk21 jdk22 都与lombok 不兼容,必须使用兼容版本, 否则报错: thingsboard 的大神解释了: java: java.lang.NoSuchFieldError: Class com

[LeetCode] 863. All Nodes Distance K in Binary Tree

题:https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/ 题目大意 求给树中,距给定 结点 指定长度的 所有结点的val 思路 tree -> graph 、 bfs 先遍历树,并用map记录每个结点的父结点 ,将树变为图,然后 bfs。 /*** Definition for a binary tree

git提交自动带上 Signed-off-by信息

为了确保在使用 Signed-off-by 签名的同时保留你的提交消息,你需要修改 prepare-commit-msg 钩子脚本,以便它不会丢失原始的提交信息。 增加prepare-commit-msg 钩子以保留提交消息 prepare-commit-msg 钩子的目的是在提交信息文件中插入额外的内容,而不是替换或丢失原始消息。我们可以修改钩子脚本来确保原始的提交消息保持不变。 以下是一

【HDU】5102 The K-th Distance bfs

传送门:【HDU】5102 The K-th Distance 题目分析:思路秒出,5101写完不到20分钟这题就AC了。。将所有点扔进队列中,记录前驱,步数,每次扩展的时候不走前驱,这样就相当于n棵树同时在扩展。注意到一条路径会被重复走两次,所以k*2,ans/2。注意姿势不对就会MLE。 代码如下: #include <map>#include <vector>

【codechef】 Prime Distance On Tree【求树上路经长度为i的路径条数】【点分治+FFT】

传送门:【codechef】 Prime Distance On Tree 点分治+FFT水题……竟然n*n爆int没发现…… 而且NTT TLE,FFT跑的超级快…… my  code: my~~code: #include <bits/stdc++.h>using namespace std ;typedef long long LL ;#define clr( a , x ) m

【Get深一度】谐振腔中的电场(E Field[V_per_m])与磁场(H field[A_per_m])分布

1.模式1[TM010模]的电场和磁场分布                  模式1在腔体横截面(XY)上的电磁场分布

Shortest Distance to a Character

Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Example 1: Input: S = "loveleetcode", C = 'e'Output: [3, 2, 1,

A Tutorial on Near-Field XL-MIMO Communications Towards 6G【论文阅读笔记】

此系列是本人阅读论文过程中的简单笔记,比较随意且具有严重的偏向性(偏向自己研究方向和感兴趣的),随缘分享,共同进步~ 论文主要内容: 建立XL-MIMO模型,考虑NUSW信道和非平稳性; 基于近场信道模型,分析性能(SNR scaling laws,波束聚焦、速率、DoF) XL-MIMO设计问题:信道估计、波束码本、波束训练、DAM XL-MIMO信道特性变化: UPW ➡ NU

Truncated incorrect max_connections value: ‘999999‘

MySQL 的最大连接数(max_connections)可以设置的上限值在不同的资料中有所不同。以下是一些关键信息: 默认值和默认范围: MySQL 的默认最大连接数通常为 100 。一些资料提到默认值为 151 。 最大允许值: MySQL 的最大连接数上限通常为 16384 。有些情况下,最大连接数可以设置为 10000 。 设置方法: 可以通过命令行临时设置,例如 set gl