Mixed type array (spread)

Hello vvvvriends,
there are data sets coming in via mqtt/json.
It contains:

ID (int)
posx (float)
posy (float)
posz (float)
height (int)

Each of such data sets makes up an entity (object).
The data coming in can have a new ID (= new entity) or an existing ID (new values for an existing entity).
I want to store the entity data so that I can add a new data set (= new ID) somehow or update an existing one (ID already exists somehow).
I read the graybook, the forum and many places and didn’t get a working solution. It’s so easy in other languages though.

Thanks in advance.

You can make a new class with these properties. Then you can create new instances of this class and set properties of existing instances of the class.

You can store your instances in a Spread<MyClass>.

can you show an example of how you’d do it an your preferred language?

Hallo tonfilm,
thank you for pointing me to using classes. I didn’t find documentation that helps me understanding the use of classes and instantianting objects as well as manipulating individual objects (instances).
But I found and watched Joreg’s tutorial “Object oriented patching with Joreg” which deals with records.
Now I understand much better how to program object oriented with VL.
Thank you Joreg!

1 Like

@olivernetzt
Also check out these by @tobyk:

Hallo Joreg,
I have no preferred language though so I’ll give you an abstraction of a possible implementation:

particles: array

class Particle is
{
  posX: float
  posY: float
  posZ: float
  age:   int

  update (dataSet)
  {
    # update the members
  }
}

function UpdateParticle (dataSet) is
{
  id = GetFromDataSet (dataSet, "ID")

  try
  {
    particle = particles[id]
  }
  on NoSuchIdException
  {
    particle = new Particle (dataSet)
  }
  particle.update (dataSet)
  particles[id] = particle
}

# main
loop
{
  dataSet = ReadJsonFromMqtt ()
  UpdateParticle (dataSet)
  Render (particles)
}

In other words:

  • receive particle data (e.g. via MQTT)
  • create a particle if value “ID” wasn’t received before
    OR
  • update existing particle if received “ID” was received before
  • render particle

Seems to be a typical scenario but I haven’t discovered a solution and I’m too inexperienced with VL to find one myself.

Thank you bjoern, I’m gonna check 'em out.

Just a shot in the dark, as I have not worked with them myself yet, but did you take a look a dictionaries in VL? Do I understand it right it is mostly about managing collections in your case?

If yes, maybe this helps:

If it is about the transmission of data, maybe the topic of Serialization could help, there is an example of transmitting serialized data via network in this tutorial:

The last link is the last part of a bigger tutorial series containing 6 videos, they might generally help in your case.

Here is a sketch of how this could be realized.

ParticlesFromMqtt.vl (21.8 KB)

note:

  • for the parsing of the json i just made a very trivial assumption. you’ll have to adapt that to you actual json.
  • the SetItem on the dictionary is doing exactly that: add item, if key is new, otherwise replace existing item

Thank you so much everyone!
I watched the suggested videos and learned already a lot from them. Impressive how people share their knowledge (and have time to do so).
Thanks @joreg for your “personal” patch. I adopted it and it works!
Unfortunately I still know so little about VL that I’m troubled with understanding how I can work with the MutableDictionary. It might even be a wrong aproach to get to my goal.
As I described, I want to control the particles meaning that I want to update existing ones with new position data and of course render them and also I want to add color, size ‘n’ stuff and I need to be able to select the particles with the mouse so I can use them for further processing (get values and send them via e.g. MQTT).
I know how to use MQTT and how to render, but how can I do this with selected particles (= key/value pair in the dictionary)? The dottore-videos proposed by @chk might describe what I could use but they are not too easy to understand. He definitely describes something quite complex.
This might be too much to ask but I don’t know better.
Good night!

i think you’ll have to be more precise with your requirements if you want more help.

this is what’s happening in the patch. any particle coming in with the id of an already existing one, will update/overwrite the existing one.

what’s not clear from your descriptions is how you’d want to manipulate particles with the mouse, but then a particle coming in via mqtt with an existing id will override all those manipulations again? so please try to give us more context so we can build a mental model of what you’re looking for.

Well, I didn’t dare to ask so much. I thought getting a hint how to control some objects will lead me to a solution.
Anyway, I’m happy you’re proposing to find a mental model together.

I have a camera based sensor that can detect objects, e.g. people.
The sensor is mounted about 3 m high facing down.
It “looks” down and can detect people (and other objects).
Once a person is detected, it is tracked, meaning the sensor follows that person.
Following the person means updating its track data which contains

  • ID
  • pos X, Y, Z
  • height
  • age (in frames, i.e. the number is incremented with each frame [there are 20 per sec.] where the object is tracked)

For every newly detected object there will be a new ID and the other data.
These tracks (as dots) along with the real scene (my room or where ever the sensor is mounted) can be displayed in the sensor’s user interface.
The track data can be distributed via mqtt.

What I want to do is using these track data in vvvv, i.e. receiving them via mqtt (already works well) and display them in a nice environment, i.e. with a renderer rendering some graphics with the objects of the sensor world as sprites of arbitrary shape.

One of many ideas is a Pac-Man environment:
I am the first entering the room and so I get tracked by the sensor. The sensor assigns ID 1 to “me” = my data object/collection.
Two other people enter the room, are tracked by the sensor and get assigned IDs 2 and 3.
I am Pac-Man and will be rendered as yellow circle and the other two as Blinky and Pinky.

So what needs to happen is that my movement will control Pac-Man and the movements of the other two will control Blinky and Pinky.
That means, whenever vvvv receives the data of track with ID 1, it needs to move Pac-Man. When it receives data with ID 2, it moves Blinky and Pinky with ID 3.

I don’t ask you to write up a Pac-Man game but I very much hope to get some more ideas how I could go further to reach the goal.

I must admit that I am still fascinated by vvvv’s and VL’s concept, the passion you developers show in bringing new updates and infos and keeping the community alive but that on the other hand I am quite overwhelmed by the number of nodes I sometimes need to use (and need to know) to come to small goals.
I’m sure it’ll take only some more practicing hours (or weeks) for me to get on the feet!

Cheers!

1 Like

Hello @joreg,
I’m afraid my latest messages is addressed to you but I forgot to mention you explicitly.
Thanks!

Maybe check out this workshop:

So if i understand correctly, the example i posted is not too far from. you already have particles following the incoming data. now i understand that you want to link the first of those with a PacMan. this should easily be done by letting your PacMan read the data from the first Particle, right? so what exactly are you missing there?

Hallo @Joreg,

yes, exactly. I’m missing that link.
I still don’t know how to “select” e.g. particle 1 and process its data. For example, when particle 1 moves along, something happens (dots get deleted because it’s Pac-Man eating them) or when particle 2 moves to particle 1’s position, Pac-Man changes shape and vanishes.
Pac-Man is just an use case example.

In an abstract code example it could look as easy as this:
particle[1].posx
particle[2].color
etc.

vl doesn’t seem to be my friend yet. :-(
But my heart is beating for it in a way.
((If I told you I’d like to see the particles flying in a beautiful 3D world …))

ok, the following further outlines the idea: assume you have a node that represents pacman, you’d now give it access to the list of particles and tell it to take its position from the partcile with id 0.
ParticlesFromMqtt.vl (36.4 KB)

Wonderful, thank you so much!
I’m traveling without my laptop, but when I’m back next week it’ll be the first thing I’ll try.