2014-01-07 36 views
1

我試圖根據Mayavi的Y值對只有角落已知的曲面着色。原來,我成功地用matplotlib(here)做了同樣的事情,但我把這個規範放回到我的真實數據中,渲染不夠充分,因此我現在正在嘗試與Mayavi。我發現Surface from irregular data example這個例子非常有幫助。但是,當應用於我的案例時,在這個簡單案例中再現了這個問題,如下圖左側所示,三角形會出錯,其中右側表面有兩個下三角形,而不是上三角形和下三角形。Mayavi自動三角網錯誤着色僅着眼於其角落的表面

enter image description here

我弄清楚,它從第二Y型頂點的位置來了,但是我想找到1更通用的解決方案)來避免這種不法行爲三角測量和2)有一個更光滑的表面在每個角之間進行插值,就像在我的previous post中一樣,並儘可能避免在右側表面上看到的摺疊,這是因爲我的表面僅在兩個三角形中分裂。任何關於如何與Mayavi一起做的想法?

這裏是我用來生成這個簡單的例子代碼:

#!/usr/bin/env python 
#-*- coding: utf-8 -*- 
import numpy 
from mayavi import mlab 

X1 = numpy.array([0, 0, 1, 1]) 
Y1 = numpy.array([0.5, 0.75, 1, 0.5]) 
Z1 = numpy.array([0, 1, 0.5,0]) 

X2 = numpy.array([0, 0, 1, 1]) 
Y2 = numpy.array([-0.5, -0.45, -1, -0.5]) 
Z2 = numpy.array([0, 1, 0.5,0]) 

fig = mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5)) 
# Building the working triangulation 
# Define the points in 3D space 
# including color code based on Z coordinate. 
pts = mlab.points3d(X1, Y1, Z1, Y1, colormap='jet') 
# Triangulate based on X, Y with Delaunay 2D algorithm. 
# Save resulting triangulation. 
mesh = mlab.pipeline.delaunay2d(pts) 
# Remove the point representation from the plot 
pts.remove() 
# Draw a surface based on the triangulation 
surf = mlab.pipeline.surface(mesh, colormap='jet') 

# Building the buggus triangulation 
pts = mlab.points3d(X2, Y2, Z2, Y2, colormap='jet') 
# Triangulate based on X, Y with Delaunay 2D algorithm. 
# Save resulting triangulation. 
mesh = mlab.pipeline.delaunay2d(pts) 
# Remove the point representation from the plot 
pts.remove() 
# Draw a surface based on the triangulation 
surf = mlab.pipeline.surface(mesh, colormap='jet') 

# Simple plot. 
mlab.outline(extent=(0,1,-1,1,0,1)) 
mlab.axes(extent=(0,1,-1,1,0,1), nb_labels=3) 
mlab.show() 
+0

你期望第二組點的三角剖分是多少? – lrineau

+0

與鏡子相同......一個下部和一個上部三角形,而不是兩個下部三角形 – TazgerO

+0

上次編輯後,問題以「4I」開始,而不是「I」開始。我無法修改該錯字,因爲修改太短。 – lrineau

回答

1

你相比,你matplotlib例如,使用不同的arrays

matplotlib例如:

z = numpy.array([0, **0.5, 1,** 0]) 

這裏:

Z1 = numpy.array([0, **1, 0.5**,0]) 

有了正確z陣列情節類似於您matplotlib例子,包括插值獲得平滑的色彩過渡。

0

函數mlab.pipeline.delaunay2d計算一組點的Delaunay三角剖分。這意味着創建的三角形只取決於點的X和Y座標,忽略Z.據我所知,兩種不同的三角形是等待的。也許你的第二個數據集中有一個錯字,這就解釋了你爲什麼感到驚訝。你的意思是以下嗎?

X2 = numpy.array([0, 0, 1, 1]) 
Y2 = numpy.array([-0.5, -0.75, -1, -0.5]) 
Z2 = numpy.array([0, 1, 0.5,0]) 

所不同的是的Y2第二座標是-0.75代替-0.45

+0

事實上,Y1有一個錯字錯誤。你應該閱讀0.45 ...我會糾正原來的帖子。隨着0.75一切工作很好,除了摺疊仍然很明顯,我想順利它abit ... – TazgerO

+0

不幸的是,三角測量的形狀僅由點的X和Y座標引導,並且你看到真正取決於在Z座標上。示例[來自不規則數據示例的曲面](http://docs.enthought.com/mayavi/mayavi/auto/example_surface_from_irregular_data.html)使用的數據集很好地展示在2D平面上。 – lrineau

+0

我收回以前的評論與Y1的0.45一樣,都是三角測量。相反,讓看到問題作爲左三角,我想要像兩個漂亮的三角形右邊的東西... – TazgerO