简体   繁体   English

简单的箭头mayavi / tvtk在mlab奇怪的行为(看起来像一个bug)

[英]Simple arrow mayavi/tvtk in mlab weird behaviour (looks like a bug)

I am trying to do a simple arrow in mlab to point to different areas on the graph. 我试图在mlab中做一个简单的箭头指向图上的不同区域。 Consider this example: 考虑这个例子:

fig = mlab.figure( bgcolor=(0, 0, 0))
b=visual.Box(x=0, y=10, z=10)
visual.set_viewer(fig)
b=visual.Box(x=0, y=10, z=10)
b2=visual.Box(x=10,y=10,z=10, color=(0,0,1))
a=visual.Arrow(x=10,y=10,z=10, color=(1,0,0))

So in my mind the arrow should appear from the blue box, however it lives it's own misterious life and is located absolutely off. 因此,在我看来,箭头应该出现在蓝色框中,然而它仍然存在于它自己的神秘生活中并且完全位于其中。 That is very strange that boxes are located and bound to the grid (so if I put b to x=10,y=10,z=10 the two boxes will be collocated), however the arrow is not. 非常奇怪的是盒子被定位并绑定到网格上(因此,如果我将b放到x = 10,y = 10,z = 10,则两个盒子将被并置),但箭头不是。 这就是我所看到的 Is this a bug or a feature? 这是一个错误还是一个功能?

Update: 更新:

I was playing around trying to fix the above and found the behaviour of the arrow very weird. 我正在试图解决上面的问题,并发现箭头的行为非常奇怪。 This is what I do (in ipython for interaction): 这就是我所做的(在ipython进行交互):

from mayavi import mlab
from tvtk.tools import visual
fig=mlab.figure( bgcolor=(0, 0, 0))
visual.set_viewer(fig)

First put the box somewhere on canvas as a reference: 首先将框放在画布上的某个位置作为参考:

b=visual.Box(x=10,y=4,z=1)

Then I want an arrow sticking out of the box: 然后我想要一个开箱即用的箭头:

a=visual.Arrow(x=10,y=4,z=1)

Didn't work out (same as the first part of the question): 没有成功(与问题的第一部分相同):

Arrow_error

Now, let's change length of the cone without reason 现在,让我们毫无理由地改变圆锥的长度

a.length_cone

returns 回报

0.35

Let's change it 让我们改变它

a.length_cone=0.5

Now the arrow is sticking out of the box as it should be 现在,箭头应该是开箱即用的 Arrow_error

Change length of the cone back to 0.35 to see if this changes the arrow back to wrong position 将锥体的长度更改回0.35以查看是否将箭头更改回错误的位置

a.length_cone=0.35

No, the arrow stays in the box where it should be. 不,箭头留在它应该的盒子里。 This looks like a bug. 这看起来像一个bug。

Playing around with arrow, I wrote the following function to generate an arrow from x1,y1,z1 to x2,y2,z2 玩箭头,我编写了以下函数来生成从x1,y1,z1x2,y2,z2的箭头

def Arrow_From_A_to_B(x1, y1, z1, x2, y2, z2):
    ar1=visual.arrow(x=x1, y=y1, z=z1)
    ar1.length_cone=0.4

    arrow_length=np.sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2)
    ar1.actor.scale=[arrow_length, arrow_length, arrow_length]
    ar1.pos = ar1.pos/arrow_length
    ar1.axis = [x2-x1, y2-y1, z2-z1]
    return ar1

Seems like ArrowSource doesn't allow for arrows extending beyond a short distance. 看起来像ArrowSource不允许箭头延伸超过短距离。 It doesn't seem very useful at all. 它似乎根本没用。 mlab functions like quiver3d return glyphs based on PolyDataSource instead. mlab函数如quiver3d返回基于PolyDataSource字形。

This will plot two boxes and an arrow between them. 这将绘制两个框和它们之间的箭头。 I'm not sure if there's a simple way to do it with quiver3d which is definitely based off of PolyDataSource but may not have the same structure somehow. 我不确定是否有一种简单的方法可以使用quiver3d,它肯定是基于PolyDataSource,但可能不会以某种方式具有相同的结构。

b1=visual.Box()
b2=visual.Box(x=10)
v=mlab.pipeline.vectors(mlab.pipeline.vector_scatter(0,0,0,10,0,0)) #xyzuvw
v.glyph.glyph.clamping=False

Also, the behavior you encountered with ArrowSource doesn't seem like a bug, it's more like a minor feature that wasn't really developed. 此外,您遇到的ArrowSource行为似乎不是一个错误,它更像是一个未真正开发的次要功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM