Ejemplo n.º 1
0
void testApp::oscSendContour(int label, const ofPolyline &polyline){
    ofxOscMessage m;
    stringstream ss;
    ss<<"/contour";
    m.setAddress(ss.str());
    
    int size = polyline.size();
    m.addIntArg(label);
    m.addIntArg(size);
    cout<<"contour: "<<label<<" size: "<<size<<endl;
    const ofRectangle& rect = polyline.getBoundingBox();
    m.addIntArg(rect.getTopLeft().x);
    m.addIntArg(rect.getTopLeft().y);
    m.addIntArg(rect.getBottomRight().x);
    m.addIntArg(rect.getBottomRight().y);
    ofPolyline newLine = polyline.getResampledByCount(100);
    cout<<"resized to "<<newLine.size()<<endl;
//    newLine.draw();
    
    if(bSendContours){
        const vector<ofPoint> points = newLine.getVertices();
        for(int i=0; i< newLine.size(); i++){
            m.addFloatArg(points[i].x);
            m.addFloatArg(points[i].y);
        }
    }
    sender.sendMessage(m);
}
Ejemplo n.º 2
0
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    switch(key) {
        case 'R': bRotate ^= true; if(!bRotate) rotAngle = 0; break;
        case 'r': poly.clear(); break;
        case 'c': poly.curveTo(mouseX, mouseY); break;
        case 'a': poly.arc(mouseX, mouseY, 50, 50, 0, 180); break;
        case 'o': poly.setClosed(!poly.isClosed()); break;
            
        case 'F': poly.simplify(10); break;
        case 'M': poly = poly.getSmoothed(5); break;
        case 'S': poly = poly.getResampledBySpacing(30); break;
        case 'C': poly = poly.getResampledByCount(50); break;
            
        case 'l': poly.setClosed(!poly.isClosed());
            
        case 'i': poly.insertVertex(ofPoint(mouseX, mouseY, 0), nearestIndex); break;
    }
}
Ejemplo n.º 3
0
void trackedContour::update(ofPolyline line){
    
    
    float contourLength = line.getPerimeter();
    //cout << contourLength << endl;
    
    ofPolyline resampled = line.getResampledByCount( sampleCount);
    
    while(resampled.size() < sampleCount){
        resampled.getVertices().push_back(resampled[resampled.size()-1]);
    }
    
    //resampled.draw();
    
    
    
    if (prevFrame.size() > 0){
        
        
        int smallestStart = -1;
        float smallestAvgLen = 10000000;
        
        for (int i = 0; i < sampleCount; i++){
            
            float avgLen = 0;
            for (int j = 0; j < sampleCount; j++){
                avgLen += (resampled[ (j + i ) % sampleCount] - prevFrame[j]).length() / sampleCount*1.0;
            }
            if (avgLen < smallestAvgLen){
                smallestAvgLen = avgLen;
                smallestStart = i;
            }
            
        }
        
        ofPolyline temp;
        for (int i = 0; i < sampleCount; i++){
            temp.addVertex( resampled[ (i + smallestStart) % sampleCount]);
        }
        resampled = temp;

    
    }
    
    
    
    ofPolyline tempT = resampled.getResampledByCount(resampleCount);
    
    while(tempT.size() < resampleCount){
        tempT.getVertices().push_back(tempT[tempT.size()-1]);
    }
    // cout << tempT.size() << " " << resampleSmoothed.size() << endl;
    
    if (resampleSmoothed.size() == 0){
        resampleSmoothed = tempT;
        for (int i = 0; i < resampleSmoothed.size(); i++){
            
            velPts.push_back(ofPoint(0,0,0));
            
        }
    } else {
        for (int i = 0; i < resampleCount; i++){
            ofPoint prev = resampleSmoothed[i] ;
            resampleSmoothed[i] = 0.75f * resampleSmoothed[i] + 0.25f * tempT[i];
            velPts[i] = (resampleSmoothed[i]  - prev) * ofMap(contourLength, resampleCount, 1000, 1, 0.1, true);
        }
    }
    
    for (int i = 0; i < resampleCount; i++){
        velAvg += velPts[i];
    }
    velAvg /= resampleCount;
    velAvgSmooth = 0.9* velAvgSmooth + 0.1 * velAvg;
    
    for (auto p : resampleSmoothed.getVertices()){
        
        unsigned int nearestIndex = 0;
        resampled.getClosestPoint(p, &nearestIndex);
   
    }
    

    
    prevFrame = resampled;
    
}