Forums > MaxMSP

cosm.field not clear

November 25, 2011 | 4:44 pm

Hello,

I have worked on chemotaxis tutorial and that’s fine.

The concept of interpolation is clear in the tutorial, but I have been racking my brain to understand what exactly does [cosm.field]. Yet not clear for me about what does it do with the values that come in its inlets.

What does "cosm.field indexes a 2D or 3D matrix of values according to the location of a matrix of ‘agent’ or particle positions" mean with number? Even with cellblocks, jit.print and pwindow it boggles my mind.

Any kind of help, patch, little word would be appreciated.

– Pasted Max Patch, click to expand. –

December 3, 2011 | 4:31 am

HI there,

[cosm.field] basically gives you efficient interpolated lookup of 2D and 3D matrices by another matrix of positions. Typical uses would be visualizing fields with particle systems.

The third inlet should be a matrix which represents the ‘field’ to be sampled; it should be 2D or 3D. It can have any number of planes.

The first inlet specifies spatial coordinates (e.g. agent positions) with which to sample the field. If the field is 2D, the coordinates should be 2-plane (XY); if the field is 3D they should be 3-plane (XYZ). The coordinates range from 0..1, which is mapped to the dimensions of the field matrix. The results of this sampling come out of the first outlet of [cosm.field]. The dimensions of this output will match the dimensions of the first inlet, but the plane-count will match the plane-count of the field itself. That is, if the field has 4 planes, and the sampling positions is a 1D matrix of 32 elements, the result will be a 1D, 4-plane matrix. The nth cell in this matrix contains the four field voxel values for the nth coordinate position that was sent in.

The sampling uses bilinear interpolation (2D fields) or trilinear interpolation (3D fields). That means a sampling point that is somewhere between two pixels/voxels will return a weighted average of them.

It’s important to make sure that the field matrix is sent to [cosm.field] before the sampling positions are sent, and also to remember that the sampling positions are in the 0..1 range (not the scale of the field matrix or of the world). You probably need to scale the agent positions first.

For those cases where you want to do interpolated lookup of a matrix for just a single position, consider using [cosm.field.query] instead.

Hope that helps!

Graham


December 5, 2011 | 12:19 am

Hi Graham, thank you for the explanation.

I am interested by the video.field.hsflow example patch. What I am trying to do is to move a set of particles with gestures.

So I send a matrix to an [jit.expr @expr snorm[0] snorm[1]] to a [jit.gl.mesh] in order to get a equal distribution of particles.

Then I send this matrix in the left inlet of the [cosm.field] (But I understand that it’s not good since it needs values between 0. and 1 not -1. to 1. ??)

In the right inlet I send values that come from [jit.qt.grab] -> [cv.jit.hsflow].

What I am expecting is to get the coordinates from the particles at position where there is movement.

What am missing?

– Pasted Max Patch, click to expand. –

December 18, 2011 | 3:00 pm

Hi there,

Yes, the sampling values should be 0..1, not -1..1; you can use [jit.expr @expr norm[0] norm[1]] for that. It will give you a grid of particles, with a corresponding set of hsflow values for each one; effectively re-sampling the hsflow matrix. It will get more interesting if you make the particles move according to the values they find…

Graham


December 19, 2011 | 12:56 pm

Yes, thanks.
It seems to be an issue since values are between 0..1, the particles always go in the same direction.
I don’t see how can you set the particles in an equal grid through the window AND get the movement according to the hsflow values since cosm.field needs 0..1.
Would it be possible with a map -1. 1. ?

new test

– Pasted Max Patch, click to expand. –

Viewing 5 posts - 1 through 5 (of 5 total)