Best way to dinamically set Indices with ofMesh

Hi guys, hope to write in the correct section.

I need to dinamically set indices with ofMesh, because points are in motion and I need to “connect” them only when they are at a certain distance.

I am re-using openFrameworks since a couple of weeks to port some of my projects from Processing.

In Processing I do something like

for (int i = 0; i < points.size(); i++) {
  PVector p = points.get(i);
  for (int j = 0; j < points.size(); j++) {
    PVector pp = points.get(j);
    if (p.dist(pp) < 50 && i != j) {
    stroke(255, 25);
    like(p.x, p.y, pp.x, pp.y);
  }
}

In ofx now I clean indices and set up they again:

myMesh.clearIndices();
for (int i = 0; i < myMesh.getNumVertices(); i++) {
  ofxVec2f p = myMesh.getVertex(i);
  for (int j = 0; j < mymesh.getNumVertices(); j++)  {
    ofVec2f pp = myMsh.getVertex(j);
    if (p.distance(pp) < 50 && i != j) {
      myMesh.addIndex(i);
      myMesh.addndex(j);
    }
  }
}

but it is too slow (I think it is CPU intensive this way).

I tried to port entire the code from Processing, in the same way, but it is still slower than Processing in terms of FPS:

for (int i = 0; i < myMesh.getNumVertices(); i++) {
  ofVec2f p = myMesh.getVertex(i);
  for (int j = 0; j < myMesh.getNumVertices(); j++) {
    ofVec2f pp = myMesh.getVertex(j);
    if (p.distance(pp) < 50 && i != j) {
    ofNoFill();
    ofSetColor(255, 255, 255, 25);
    ofDrawLine(p.x, p.y, pp.x, pp.y);
  }
}

I am using openframeworks 0.9.3 on Ubuntu 14.04.

Hope to resolve this since I want to port my Processing apps on ofx for performance improvementes when I go live, it might help someone else.

Thanks in advance

I do not think is a problem of indexing, as you said ofMesh works in CPU so that when you turn on update I think there is a job [RAM -> CPU -> Render] I have something similar.
Perhaps in this case it may be useful to use a ofVbo who works on the memory of GPU and quickly passes the data to render state.

a good example to look at to understand this may be:
/examples/gl/billboardExample/