Juliaセットデシメーションの例

Julia集合は削除されますが,メッシュはデシメートされています.初期グリッドとジュリア集合のジオメトリが一致しないため,不要な三角形が削除されます.

まず,warp_scalarフィルタを配列2d_sourceに適用してメッシュを構築し,Julia集合をz方向にワープします.

次に, decimate_pro フィルタを適用するために,メッシュ内の長方形を三角形に変換する必要がある場合.このフィルタはデシメーションを行い,表面モジュールを用いて結果を表現できます.

三角形生成フィルタは警告を生成します.グリッドがJulia集合の平坦な部分を細分割しているため,一部のポリゴンが縮退しています.

デシメート処理されたメッシュは白で,デシメート処理されていないメッシュは黒で表示されています.ビューがジュリアセットの中心にズームされます.ワイヤフレームをオフにしてズームアウトすると,デシメーションの品質を確認できます.

2次元データからワープしたサーフェスをデシメートする特定のケースでは,greedy-terrain-decimatorを使用する方が効率的です. キャニオンデシメーションの例 を参照してください.

../_images/example_julia_set_decimation.jpg

Pythonソースコード: julia_set_decimation.py


# Author: Gael Varoquaux <gael.varoquaux@normalesup.org>
# Copyright (c) 2008, Enthought, Inc.
# License: BSD Style.


from mayavi import mlab
import numpy as np

# Calculate the Julia set on a grid
x, y = np.ogrid[-1.5:0.5:500j, -1:1:500j]
z = x + 1j * y

julia = np.zeros(z.shape)

for i in range(50):
    z = z ** 2 - 0.70176 - 0.3842j
    julia += 1 / float(2 + i) * (z * np.conj(z) > 4)


mlab.figure(size=(400, 300))

# Create the mesh
mesh = mlab.pipeline.warp_scalar(mlab.pipeline.array2d_source(julia),
                                 warp_scale=100)

# The decimate_pro filter works only on triangles. We need to apply the
# triangle_filter before applying decimate_pro.
dec = mlab.pipeline.decimate_pro(mlab.pipeline.triangle_filter(mesh))
# Set a very low feature_angle, so that the decimate_pro detects
dec.filter.feature_angle = 1
dec.filter.target_reduction = 0.5

# We display the lines of decimated mesh in white
mlab.pipeline.surface(dec, representation='wireframe', line_width=3,
                           color=(1, 1, 1))
# The decimated mesh itself.
mlab.pipeline.surface(dec, colormap='gist_earth', vmin=-0.1, vmax=0.4)

# The lines of the non-decimated mesh, in black, for comparisation.
mlab.pipeline.surface(mesh, representation='wireframe',  color=(0, 0, 0))

mlab.view(-66, 25, 9.7, [-5.8, -54.5,  18.4])

mlab.show()