About the Generating Meshes tutorials

When I’m learning the Generating Meshes in the middle of the tutorials. Cant go through here:

Almost time for lines, lines, lines!
We have a lot of vertices in our mesh. You can check the number using getNumVertices() if you like:

1
cout << mesh.getNumVertices() << endl; // It should be ~64,000
If we were to start looping through those each of those 64,000 vertices to connect them up to the other vertices that are close-by, we could end up spending a fair chunk of time in that loop. A fairly common thing to do to speed up the processing of an image is to shrink it:

1
2
image.loadImage(“stars.png”);
image.resize(200, 200);

Does anyone knows where to put the “cout << mesh.getNumVertices() << endl; // It should be ~64,000” and
"image.loadImage(“stars.png”);
image.resize(200, 200);
"?

I’m not familiar with the tutorial, but you should place the call cout << mesh.getNumVertices() << endl; somewhere after the vertices are added. So if you call addVertex in a for loop, you should probably call it after the for loop to see how many vertices you now have in the mesh.

@Tiffany, like @NickHardeman is saying, printing out the number of vertices should come after you build your mesh. In the context of the tutorial, that would mean that you add that line of code to the end of the setup() function.

As for where you put the line of code about resizing the image, that comes after you load the image in setup(). Attached below is what the setup() function would look like around that point in the tutorial.

I’m the one who wrote the tutorial. If you are finding any parts of the tutorial unclear, I’d love to know so that I can go back and revise it.

void testApp::setup(){
    image.loadImage("stars.png");
    image.resize(200, 200);
    
    // Don't forget to change to lines mode!
    mesh.setMode(OF_PRIMITIVE_LINES);

    float intensityThreshold = 150.0;
    int w = image.getWidth();
    int h = image.getHeight();
    for (int x=0; x<w; ++x) {
        for (int y=0; y<h; ++y) {
            ofColor c = image.getColor(x, y);
            float intensity = c.getLightness();
            if (intensity > intensityThreshold) {
                // We shrunk our image by a factor of 4, so we need to multiply our pixel 
                // locations by 4 in order to have our mesh cover the openFrameworks window
                ofVec3f pos(4*x, 4*y, 0.0);
                mesh.addVertex(pos);
                mesh.addColor(c);
            }
        }
    }
}

Thanks, guys! So for the rest of the things, also add into the setup function?
such as:

if (c.getLightness() > intensityThreshold) {
// We shrunk our image by a factor of 4, so we need to multiply our pixel
// locations by 4 in order to have our mesh cover the openFrameworks window
ofVec3f pos(4x, 4y, 0.0);
mesh.addVertex(pos);
mesh.addColor©;
}
And the next amount of code.

It doesn’t say where to put them???

So for that chunk of code, the preceding instruction says:

And then because our image pixel are no longer one-to-one with our openFrameworks window pixels, we need to adjust the pos variable inside of our loop

You’ve only written one loop so far, and that loop is within setup(). So yup, your intuition was correct - that code goes in setup. See the code that I posted earlier in this thread for what your setup function should look like after adding that code to your loop.

The next code block is directing you as to how you should further change setup() to connect vertices together to form lines.

A general point - it might help to take a step back from the code and think about conceptually what is happening. setup() is being used to create a mesh and draw() is being used to render the mesh to the screen.