visualisatiion of spheres displacements by colour in 3d viewport

Asked by Ehsan Izadi

Hey,

Does anyone knows if it is possible to make a color-based visualisation in 3d viewport of YADE based on the displacement of spheres?
If so, could you help me with the python code?
I guess it may be possible by definition of a conditional loop playing with RGB parameters, but I don't know how to implement it.

Thanks.
Ehsan

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Bruno Chareyre
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Ehsan Izadi (ehsan-izadi) said :
#1

Also it would be nice if possible to invisible the particles which for example its x-direction displacement exceeds from a limited value.
Any idea?

Revision history for this message
Jérôme Duriez (jduriez) said :
#2

Hello Ehsan,

For your first question, you can play with shape.color (defined for each body).

Loop over bodies "b" and write something like
b.shape.color = Vector3(a,b,c) # the a,b,c are in [0,1] , they are RGB parameters you mention (abc = 100 => red, abc=010 => green, ...), and you could compute them according to b.state.pos - some reference Vector3 (the displacement)

For the 2d question, I do not know how to make particles invisible, give maybe a look to OpenGLRenderer (https://www.yade-dem.org/doc/yade.wrapper.html#openglrenderer), that - I guess - is responsible for displaying things. An alternative way would be to let ouput the considered bodies only as "wire" : try b.shape.wire = 1

Jérôme

Revision history for this message
Ehsan Izadi (ehsan-izadi) said :
#3

Thanks jduriez, that solved my question.

Revision history for this message
Václav Šmilauer (eudoxos) said :
#4

Hi, if you don't specifically need Yade for your simulation, you can grab Woo (http://www.launchpad.net/woo), which has particle coloring based on coordinates, velocities and so on built-in (http://woodem.eu/doc/user/running.html#display-control). Cheers, václav

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#5

Elaborating Jerome's suggestion, for future reference:
b.shape.color = scalarOnColorScale( (s.state.refPos - s.state.pos).norm() ,minDisp,maxDisp)

refPos is something you are free to play with, and is (0,0,0) by default. To make the above line display displacement you need to set refPos = pos before starting the erosion.

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#6

>Also it would be nice if possible to invisible the particles

It was a good idea Ehsan. It is now [1] possible:
yade.qt.Renderer().hideBody(id)
yade.qt.Renderer().showBody(id)

[1] https://github.com/yade/trunk/commit/40715e41aa437ecff147d1378992341e27d8876d

Revision history for this message
Ehsan Izadi (ehsan-izadi) said :
#7

Thanks all for the comments.
Now I am working on detecting the accumulative rotations of the spheres.
I've defined such function like:
def colorScaling():
 for b in O.bodies:
  b.shape.color=scalarOnColorScale(b.state.rot().norm(), [min rotation], [max rotation])

But it does not seem to reflect the accumulative rotations.
Does anyone know how to change the code to get the accumulative rotations of the spheres?
I know that the algorithm should be something like defining an array that rotations in every time step to be stored in that. and after each time step the magnitude of rotations should be again set to zero, ... or I am wrong!?

Revision history for this message
Best Bruno Chareyre (bruno-chareyre) said :
#8

You are displaying current orientation. If you want rotation, it is like in #5.
Set b.state.refOri=b.state.ori before the test.
Then rotation will be refOri.conjugate()*ori.
Or (easier) use b.state.rot() which gives exactly this, but don't forget to initialize refOri.

Note that this technique will still give zero if the cumulated rotation reaches 2pi. It is not easy to solve ans probably not very important.

Revision history for this message
Ehsan Izadi (ehsan-izadi) said :
#9

Thanks Bruno Chareyre, that solved my question.

Revision history for this message
Clinton Schramm (clintonschramm) said :
#10

Hi Bruno

Sorry to bring up an old thread. I am trying to understand what you mean in #8.
When you say "(easier) use... what would the line of code be? And what do you mean by initialize refOri?
How would I initialize refOri if it is all the spheres in a simulation.

Cheers