###### tags: `Paper`、`3D Computer Game`、`Fluid Simulation`
# [**Interactive Localized Liquid Motion Editing**](https://dl.acm.org/doi/10.1145/2508363.2508429)
## 1. Introduction
## 3. Overview
<center>

</center>
上圖為本篇論文的演算法 pipline,主要有分為兩個部分 *keyframe design* 和 *sequence generation*。
在 keyframe design 部分,使用者可以透過拖曳或是 local mesh patch 的方式在修改特定幀的形狀。
在 sequence generation 部分,編輯過的 keyframe 會被傳送到 local subsequence,以 real-time 預覽生成的動畫,這樣的方式可以保留原始動畫,也可以<font color = "orange">透過時間曲線自行控制。</font>
最後,local subsequence 會合併到原始的 sequence,並且以 keyframe 為後續模擬的初始條件,繼續進行模擬。
## 4. Keyframe Designer
本篇論文提供了三種編輯方法:
1. 繪製筆畫以指定流體形狀
2. 拖曳小部分區域,是部分流體形狀改變
3. 提供一個小 mesh patch 作為 constrain
#### Fluid Shape Preprocessing
在使用者選擇的 frame $K$,作者會丟棄一些較小的 features,例如飛濺的小水滴,因為這些細部的 feature 會造成使用者編輯上的困難,同時對於流體整體形狀的影響很小。具體來說,作者運用形態學的開啟 (morphological opening operation),並且設定 erodes 3 grid spacing,dilates 3 grid spacing,因為 opening 可以去除影像雜訊,最終達到移除細微 feature 的結果。
> [Mathematical morphology](https://en.wikipedia.org/wiki/Mathematical_morphology): a theory and technique for the analysis and processing of geometrical structures based on set theory, lattice theory, and random function.
>
> [*Opening*](https://en.wikipedia.org/wiki/Opening_(morphology)): the dilation of the erosion of a set A by a structuring element B.
$$A \circ B = ( A \ominus B) \oplus B$$
> [*dilation*](https://en.wikipedia.org/wiki/Dilation_(morphology)):usually represented by $\ominus$ , uses a structuring element for probling and reducing the shapes contained in the input image.
> [*erosion*](https://en.wikipedia.org/wiki/Erosion_(morphology)):usually represented by $\oplus$ , uses a structuring element for probling and expanding the shapes contained in the input image.
<center>

</center>
下一步,作者將 particles 分成三種:
1. 固體與流體交界處粒子,<font color="Blue">$\mathcal{B}^K$</font>
2. 液體與氣體交界處粒子,<font color="Red">$\mathcal{S}^K$</font>
3. 中間粒子,<font color="Green">$\mathcal{M}^K$</font>
上面這三種粒子的集合為 $\mathcal{P}^K$
<center>

</center>
<center>

</center>
#### From User Sketch to Control Particles
下圖中,綠色線條為 user 指定的形狀,此時,系統會從 camera 位置,延伸出 ray 到所有該線條上的 control particles 以確定深度,沿 ray 方向生出 patch,width 由使用者自訂,以此來確定可影響範圍。
<center>

</center>
### 4.1 Objective Function of Control Particles
$\Theta_0(\mathcal{L}, \mathcal{B}, \sf{D}) = \underset{\mathbf{B}_\mit{i} \ \in \ \mathcal{B}} \sum{\phi^2_{\cal{L}} \ (\sf{D}(\bf{B_\mit{i}}))} \tag{1}$
$\mathcal{L}$ 是 control particles 也是 target shape,$\mathcal{B}$ 是邊緣 particles,$\mathbf{B}$ 是 particle 的 vector,$\phi_\mathcal{L}$ 是與 $\mathcal{L}$ 的距離公式,$\mathsf{D}$ 是變形 operator。<font color="Red">這段公式的意思是將要改變的 particles 透過 $\mathsf{D}$ function 改變形狀,並且與 target shape 做比較。然而,這樣子的算法因為要對所有的邊界 particles 做運算,會造成運算量龐大的問題,而且對於使用者其實只會想要針對要改變的 particle 進行控制,因此作者提出了另外一個公式,如下:</font>
$\Theta(\cal{L}, \cal{B}, \sf{D}) = \underset{\bf{L}_\mit{i} \ \in \ \cal{L}}\sum{\phi^2_\cal{B} \ (\sf{D}^{-1}(\bf{L_\mit{i}}))} \tag{2}$
若以 mesh patch 為 constrain,則公式可以簡化成如下:
$\Theta(t, s, \sf{D}) = ||\sf{D}^{-1}\mathcal{(t) - s}||^{2} \tag{3}$
$t$ 為 target location,$s$ 為 start location。
### 4.2 Optimizing the Deformation Operator
#### Reduced Model of Deformation Operator
在公式 2 中的 $\mathsf{D^{-1}}$ 表示如下:
<center>
$\mathsf{D^{-1}}(\mathbf{P}) = \mathsf{Adv}^{{N_A}}(\mathbf{P}, \mathbf{-V}).$
</center>
現在,我們可以通過優化 $V$ 來最小化 $\Theta$,但因為 $V$ 要 realtime 有困難,因此要透過簡化 $V$ 的模型,來解決此問題,接下來我們要先定義一個任意向量場 $\mathbf{H}$,且 $V = \nabla \times \mathbf{H}$,$$\mathbf{H}_R =
\begin{cases} \mathbf{H} \ \mathbf{R}(\phi / \epsilon) + (1 - \mathbf{R}(\phi/\epsilon)) \mathbf{N}(\mathbf{H} \cdot \mathbf{N}) & \text{for 3D cases,} \\ \mathbf{H} \ \mathbf{R}(\phi / \epsilon) & \text{for 2D cases.}
\end{cases}$$ 上述公式中 $\phi$ 指的是<font color="orange">透過 [level set function](https://en.wikipedia.org/wiki/Level-set_method) 取得的與固體的邊緣形狀</font>,而 $\epsilon$ 則是<font color="orange">邊界漸變層厚度,若從 [boundary layer thickness](https://en.wikipedia.org/wiki/Boundary_layer_thickness) 來想,boundary layer thickness 指的是流體沿固體表面流動所形成的邊界層 ([boundary layer](https://en.wikipedia.org/wiki/Boundary_layer)) 的厚度和形狀的參數,並且這裡的厚度及形狀是一個漸進的數值</font>, $\mathbf{R}$ <font color="orange">是一個用來算漸進率的 function</font>,如下: $$\mathbf{R}(\psi) = \begin{cases} 1 & \psi \geq 1, \\ \frac{15}{8}\psi - \frac{10}{8}\psi^3+\frac{3}{8}\psi^5 & 1 > \psi > -1, \\
-1 & \psi \leq -1.\end{cases} \tag{4}$$ 到此,大概能猜到在 2D 中,<font color="orange">$\mathbf{R}(\phi / \epsilon)$ 的意思是,根據 particle 距離固體邊界的位置,算出其漸進率,並且乘上 $\mathbf{H}$,得出其在該位置的向量,包含法向量及切線向量</font>,然而,論文中並沒有提到 $\mathbf{N}$ 代表的意思,因此也較無法理解在 3D 的狀況下,$\mathbf{H}$ 所代表的物理意義。下方公式表示出了旋度及風力的向量公式 $$\mathbf{H}_C(\mathbf{X}, \mathbf{C}, \mathbf{A}, f, f_0) = \mathbf{A}E, \tag{5}$$ $$\mathbf{H}_W(\mathbf{X}, \mathbf{C}, \mathbf{A}, f, f_0) = \mathbf{A} \times (\mathbf{X} - \mathbf{C})E, \tag{6}$$ $E = \exp(-(f^2 + f_0)|| \mathbf{X} - \mathbf{C}||)$,$\mathbf{C}$ 指的是力的中心,$f$ 和 $f_0$ 是漸變參數,$\mathbf{A}$ 是軸或是力的方向,然而同樣,論文中並沒有給出 $\mathbf{X}$ 的確切意思,故有些推導不出來上面兩個方程式具體要表達的意思。最後,作者給了一個 $\mathbf{H}$ 的最終表示式,如下: $$\mathbf{H} = \sum_{i}^{N} \mathbf{H}^i_{c_i}, \ c_i \in \{ C, W \}, \tag{7}$$
在這裡,$C$ 指的是旋度 (curl force),$W$ 指的是風力 (wind force)。總向量場 $\mathbf{H}$,就是所有向量場的總和。所以最終,$V = \nabla \times \mathbf{H}$ 可以用上面公式取代,而若要取得公式 2 裡,$\Theta$ 的最小值,就是要解決這些變數。
#### Regularization of Objective Function
<font color="orange">為了獲得穩定的結果並避免過度擬合</font>,作者在這裡給了兩個額外的正規化項 $$\mathbf{E}_{reg} = \sum_{\mathbf{L}_i\in\mathcal{L}} ||\delta\mathbf{L_\mit{i}}||^2 \tag{8}$$ 其中 $\delta \mathbf{L} = \mathsf{D^{-1}}(\mathbf{L}) - \mathbf{L}$,<font color="orange">帶回之前的公式考慮,可以知道這裡是在把目前的形狀與 backward 的做比較</font>,而第二項為 $\mathbf{E}_{lap}$ <font color="orange">是應用於 $\mathcal{L}$ 的拉普拉斯正則化</font>。即$$\mathbf{E}_{lap} = \sum_{\mathbf{L}_i \in \mathcal{L}} || \sum_{\mathbf{L}_j \in \mathcal{N}(\mathbf{L}_i)} w_{ij}(\delta\mathbf{L}_j - \delta\mathbf{L}_i)||^2 \tag{9}$$ <font color="orange">這裡可以猜測是將現在的 particle 與相鄰的 control particle 做比較</font>,最後的 function 可以寫成,$$\mathbf{E}_{final} = \Theta + w_r\mathbf{E}_{reg} + w_l\mathbf{E}_{lap} \tag{10}$$ 而 $w_r$ 及 $w_l$ 為 user 控制的參數,$w_r$ 控制穩定量,$w_l$ 控制對應的液體部分。
<center>

</center>
## 5 Sequence Generator
### 5.1 Update of Local Subsequence
$\mathbb{S}^K = \{ \mathcal{P}^{K-i}|0 < i < w\}$,$w$ 指的是 local window size ($w = 50$),作者的計劃是在 $\mathbb{S}^K$ 中對每個幀進行變形,以便在 K 幀處變形量平滑地增加到完全變形 D
### 5.2 Generation of Final Animation
## 6. Implementation Details
## 7. Results
<center>

</center>
<center>

</center>
## 8. Conclusion
----
## 參考資料
- [影像處理的形態學(Morphology)應用](https://medium.com/%E9%9B%BB%E8%85%A6%E8%A6%96%E8%A6%BA/%E5%BD%A2%E6%85%8B%E5%AD%B8-morphology-%E6%87%89%E7%94%A8-3a3c03b33e2b)