Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting face color for triangular mesh doesn't always work #688

Closed
aliounis opened this issue Jul 27, 2018 · 4 comments
Closed

Setting face color for triangular mesh doesn't always work #688

aliounis opened this issue Jul 27, 2018 · 4 comments

Comments

@aliounis
Copy link

I am trying to implement the solution in #253 to color a triangular mesh by face color. Some of the time, the solution as is works great, but some of the time the coloring returns to the default with no change to the code. using

import numpy as np 
from mayavi import mlab 

import time

# Create cone 
n = 8 
t = np.linspace(-np.pi, np.pi, n) 
z = np.exp(1j*t) 
x = z.real.copy() 
y = z.imag.copy() 
z = np.zeros_like(x) 
triangles = [(0, i, i+1) for i in range(n)] 
x = np.r_[0, x] 
y = np.r_[0, y] 
z = np.r_[1, z] 
t = np.r_[0, t] 

# These are the scalar values for each triangle 
f = np.mean(t[np.array(triangles)], axis=1) 

# Plot it 
mesh = mlab.triangular_mesh(x, y, z, triangles, 
                                    representation='wireframe', 
                                                                opacity=0) 
mesh.mlab_source.dataset.cell_data.scalars = f 
mesh.mlab_source.dataset.cell_data.scalars.name = 'Cell data' 
mesh.mlab_source.update() 
mesh.parent.update()

mesh2 = mlab.pipeline.set_active_attribute(mesh, 
                cell_scalars='Cell data') 
s2 = mlab.pipeline.surface(mesh2) 


mlab.show()
 

as my script and simply running "python /path/to/script.py" multiple times produces different results. This is on OSX using qt 5.6.2 as the backend and python 3.5.4

@prabhuramachandran
Copy link
Member

Thanks for the example. On mayavi master I am unable to reproduce this and each time I run the script I get the same result. Can you please try with master or a recent release and let me know how it goes.

@aliounis
Copy link
Author

aliounis commented Sep 7, 2018

Hi, I just pulled master and reinstalled with the same results. Sometimes when I run the default shading is used as if no colors have been specified. Sometimes I run and it shows the correct shading. This is really odd... Also sorry about the delay. For some reason I never got a notification someone had responded.

@aliounis
Copy link
Author

aliounis commented Sep 7, 2018

Never mind, it seems to be working now. I had to create an entirely new environment but it seems to produce the same results every time now. I guess there was something funky in one of the dependencies in the environment I was using.

@prabhuramachandran
Copy link
Member

Alright, am closing this for now. Thanks for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants