本文整理汇总了C++中ofPolyline::getResampledByCount方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPolyline::getResampledByCount方法的具体用法?C++ ofPolyline::getResampledByCount怎么用?C++ ofPolyline::getResampledByCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPolyline
的用法示例。
在下文中一共展示了ofPolyline::getResampledByCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: oscSendContour
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);
}
示例2: keyPressed
//--------------------------------------------------------------
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;
}
}
示例3: update
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;
}