Svg image to Ilda Laser - normalisation of the polyline?

Hi !

I’m currently trying to convert a Svg image to an ilda Laser.
I’ve succeeded to convert the image into several ofPolyline (in order to draw differents shape with no lines between them).
The problem is that I can draw the vector of polylines but with real dimensions (like a 500*500 px), but no in (0-1).
I tried to normalise the polyline but it returns a weird thing (see the image).

I tried to make an ofmap to map values to 0-1, but It doesn’t work too.

Here is some code and pictures :

In Setup :

svg.load("batman.svg");
for (int i = 0; i < svg.getNumPath(); i++){
    ofPath p = svg.getPathAt(i);
    
    // svg defaults to non zero winding which doesn't look so good as contours
    p.setPolyWindingMode(OF_POLY_WINDING_ODD);
    
    for(int j = 0; j < p.getOutline().size(); j++) {
    ofPolyline lineTest = p.getOutline().at(j);
    outlines.push_back(lineTest.getResampledBySpacing(1)); //outlines is a vector of ofPolyline
        // Here I have a vector of ofPolylines with all the coordinates
        }           
    }

//Normal way to add Vertices with the normal coordinates, then normalise 
    for (int i = 0; i < (int)outlines.size(); i++){
    ofPolyline lineTest2;
    lineVectored.push_back(outlines[i]);
    lineVectored[i] = outlines[i];
    lineShared = shared_ptr<ofxIlda::Poly>(new ofxIlda::Poly);

    for (int j = 0; j < lineVectored.size(); j++){
       lineShared.get()->addVertices(lineVectored[i].getVertices());
       lineSharedOk.push_back(lineShared); 
       lineSharedOk[i]->normalise();  
    }
}

But It returns me :

I tried with the OfMap Function and it returns me :

 for (int i = 0; i < (int)outlines.size(); i++){
    
    
    ofPolyline lineTest2;
    lineVectored.push_back(outlines[i]);
    lineVectored[i] = outlines[i];
    lineShared = shared_ptr<ofxIlda::Poly>(new ofxIlda::Poly);
   
    for (int j = 0; j < lineVectored.size(); j++){
        lineShared.get()->addVertex(ofMap(lineVectored[i][j].x, 0, svg.getWidth(), 0, 1), 
                                    ofMap(lineVectored[i][j].y, 0, svg.getHeight(), 0, 1), 0 );
        lineSharedOk.push_back(lineShared);
    }
}

Here is the result :

The original image drawn with Polyline is ok (not passed through Etherdream) :

So my problem isn’t to draw an svg image to a vector of polylines, but it’s to map originals coordinates (0-ofGetWidth) to Ilda coordinates (0-1), in order to send them to the laser.

Someone knows how I can do it ? Maybe @memo ?

Thanks !

Cyril

We did some processing similar to yours in a (VERY!) unoptimised way, like this, mostly because we need access to the original polyline later on.

       ofPolyline simpleContour = normBlob.contour;
        vector<ofPoint> currentPoints = simpleContour.getVertices();
        for (int j = 0; j < currentPoints.size(); j++) {
            currentPoints[j].x = ofMap(currentPoints[j].x,0,640,0,1);
            currentPoints[j].y = ofMap(currentPoints[j].y,0,480,0,1);
        }
        ofPolyline normalizedContour = ofPolyline(currentPoints);

    currentIldaFrame.addPoly(normalizedContour);
    currentIldaFrame.getLastPoly().setClosed(true);

Hi Drakko !

Thank, Does normblob.contour come from ofxBlobTracker ?

Cyril

@drakko :

I can get 60 fps with this one, but as you can see, there is no distinction between shapes :

    svg.load("batman.svg");
for (int i = 0; i < svg.getNumPath(); i++){
    ofPath p = svg.getPathAt(i);
    p.setPolyWindingMode(OF_POLY_WINDING_ODD);
    vector<ofPolyline>& lines = p.getOutline();
    for(int j=0;j<(int)lines.size();j++){
        outlines.push_back(lines[j].getResampledBySpacing(1));
    }
}
for (int i = 0; i < (int)outlines.size(); i++){
    line = outlines[i];
    ofBeginShape();
    for (int j = 0; j < line.size(); j++){
        line2.addVertex(ofMap(line[j].x, 0, svg.getWidth(), 0, 1),ofMap(line[j].y, 0, svg.getHeight(), 0, 1) ,0);
    }
    ofEndShape();
    
}

The path is a contour from ofxOpenCv, I heavily simplified first to match the laser capabilities.

In the code that you are showing, you are adding vertex to a single polyline (line2?); and I don’t see a line2.begin() nor line2.close() while ofBeginShape/ofEndShape are global functions to directly render vertex to the screen. Also ofPolyline is intended to store only one shape, not multiple ones.

As outlines is a vector of polylines, why not map directly the points values of the contour and send that as different polylines to ofxIlda?

Yup, this is the problem, there is no distinctions between shapes because this is a single polyline (as on the image, shapes are connected and it distords the original image).

This is what I tried on my first post, how could you have done it ?

Thank !
Cyril