本文整理汇总了C++中ofPolyline类的典型用法代码示例。如果您正苦于以下问题:C++ ofPolyline类的具体用法?C++ ofPolyline怎么用?C++ ofPolyline使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ofPolyline类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ofxPolylineLoad
void ofxPolylineLoad(ofPolyline & poly, string xmlPath) {
ofXml xml;
bool bLoaded = xml.load(xmlPath);
if(bLoaded == false) {
return;
}
xml.setTo("poly");
bool bClosed = ofToInt(xml.getAttribute("closed"));
poly.clear();
int numOfPoints = xml.getNumChildren();
for(int i=0; i<numOfPoints; i++) {
xml.setToChild(i);
float x = ofToFloat(xml.getAttribute("x"));
float y = ofToFloat(xml.getAttribute("y"));
poly.addVertex(x, y);
}
if(bClosed == true) {
poly.close();
}
}
开发者ID:julapy,项目名称:ofxPolylineSaveLoad,代码行数:25,代码来源:ofxPolylineSaveLoad.cpp
示例2: drawWithNormals
//--------------------------------------------------------------
void drawWithNormals(const ofPolyline& polyline, int zeroX, int zeroY,
bool drawContours) {
for (int i = 0; i < (int) polyline.size(); i++) {
bool repeatNext = i == (int) polyline.size() - 1;
const ofPoint& cur = polyline[i];
const ofPoint& next = repeatNext ? polyline[0] : polyline[i + 1];
float angle = atan2f(next.y - cur.y, next.x - cur.x) * RAD_TO_DEG;
float distance = cur.distance(next);
if (repeatNext) {
ofSetColor(255, 0, 255);
}
glPushMatrix();
glTranslatef(cur.x + zeroX, cur.y + zeroY, 0);
ofRotate(angle);
// ofLine(0, 0, 0, distance);
ofLine(0, 0, distance, 0);
ofLine(0, distance, distance, distance);
if (drawContours) {
for (int i = distance; i < distance * 3; i += 5) {
ofLine(0, 0, i, 0);
ofLine(0, i, i, i);
}
}
glPopMatrix();
}
}
开发者ID:maiatoday,项目名称:ripple,代码行数:30,代码来源:testApp.cpp
示例3: ofGetSmoothed
ofPolyline ofGetSmoothed(const ofPolyline& polyline, int smoothingSize, float smoothingShape) {
ofPolyline result = polyline;
if(!polyline.getClosed()) {
ofLog( OF_LOG_ERROR, "ofSmooth() currently only supports closed ofPolylines." );
return polyline;
}
// precompute weights and normalization
vector<float> weights;
float weightSum = 0;
weights.push_back(1); // center weight
// side weights
for(int i = 1; i <= smoothingSize; i++) {
float curWeight = ofMap(i, 0, smoothingSize, 1, smoothingShape);
weights.push_back(curWeight);
weightSum += curWeight;
}
float weightNormalization = 1 / (1 + 2 * weightSum);
// use weights to make weighted averages of neighbors
int n = polyline.size();
for(int i = 0; i < n; i++) {
for(int j = 1; j <= smoothingSize; j++) {
int leftPosition = (n + i - j) % n;
int rightPosition = (i + j) % n;
const ofPoint& left = polyline[leftPosition];
const ofPoint& right = polyline[rightPosition];
result[i] += (left + right) * weights[j];
}
result[i] *= weightNormalization;
}
return result;
}
开发者ID:alfredoBorboa,项目名称:openFrameworks,代码行数:35,代码来源:ofShapeUtils.cpp
示例4: renderOutlinesToFBO
void testApp::renderOutlinesToFBO(ofPolyline& leftEye, ofPolyline& rightEye, ofPolyline& faceOutline){
outputFbo.begin();
ofClear(0,0,0,0);
ofPushStyle();
//ofEnableAlphaBlending();
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofSetColor(0,0,255,255);
ofBeginShape();
ofVertices(faceOutline.getVertices());
ofEndShape();
ofSetColor(255,0,0,255);
ofBeginShape();
ofVertices(leftEye.getVertices());
ofEndShape();
ofSetColor(255,0,0,255);
ofBeginShape();
ofVertices(rightEye.getVertices());
ofEndShape();
ofPopStyle();
outputFbo.end();
}
开发者ID:obviousjim,项目名称:CloudsInterludes,代码行数:28,代码来源:testApp.cpp
示例5: contourToConvexHull
void contourToConvexHull(ofPolyline &src, ofPolyline &dst) {
dst.clear();
vector<hPoint> P(src.size());
for(int i = 0; i < src.size(); i++) {
P[i].x = src[i].x;
P[i].y = src[i].y;
}
int n = src.size(), k = 0;
vector<hPoint> H(2*n);
// Sort points lexicographically
sort(P.begin(), P.end());
// Build lower hull
for (int i = 0; i < n; i++) {
while (k >= 2 && cross(H[k-2], H[k-1], P[i]) <= 0) k--;
H[k++] = P[i];
}
// Build upper hull
for (int i = n-2, t = k+1; i >= 0; i--) {
while (k >= t && cross(H[k-2], H[k-1], P[i]) <= 0) k--;
H[k++] = P[i];
}
H.resize(k);
for(int i = 0; i < H.size(); i++) {
dst.addVertex(H[i].x + 500, H[i].y);
}
}
开发者ID:phdcosta,项目名称:phdGui,代码行数:34,代码来源:phdUtils.cpp
示例6: V
void ofxPolyline2Mesh::updateShape(const ofPolyline &polyline)
{
shape.clear();
norm.clear();
for (int i = 0; i < polyline.size(); i++)
{
shape.push_back(polyline[i]);
}
if (polyline.isClosed())
shape.push_back(polyline[0]);
const ofVec3f V(0, 0, -1);
for (int i = 0; i < shape.size() - 1; i++)
{
const ofVec3f& p1 = shape[i];
const ofVec3f& p2 = shape[i + 1];
const ofVec3f& n21 = (p2 - p1).normalized();
norm.push_back(n21.crossed(V));
}
{
const ofVec3f& p1 = shape[shape.size() - 1];
const ofVec3f& p2 = shape[0];
const ofVec3f& n21 = (p2 - p1).normalized();
norm.push_back(n21.crossed(V));
}
current_segments.resize(shape.size());
last_segments.resize(shape.size());
}
开发者ID:arturoc,项目名称:ofxPolyline2Mesh,代码行数:35,代码来源:ofxPolyline2Mesh.cpp
示例7: ofGetResampledSpacing
ofPolyline ofGetResampledSpacing(const ofPolyline& polyline, float spacing) {
ofPolyline result;
// if more properties are added to ofPolyline, we need to copy them here
result.setClosed(polyline.getClosed());
float totalLength = 0;
int curStep = 0;
int lastPosition = polyline.size() - 1;
if(polyline.getClosed()) {
lastPosition++;
}
for(int i = 0; i < lastPosition; i++) {
bool repeatNext = i == (int) (polyline.size() - 1);
const ofPoint& cur = polyline[i];
const ofPoint& next = repeatNext ? polyline[0] : polyline[i + 1];
ofPoint diff = next - cur;
float curSegmentLength = diff.length();
totalLength += curSegmentLength;
while(curStep * spacing <= totalLength) {
float curSample = curStep * spacing;
float curLength = curSample - (totalLength - curSegmentLength);
float relativeSample = curLength / curSegmentLength;
result.addVertex(cur.getInterpolated(next, relativeSample));
curStep++;
}
}
return result;
}
开发者ID:alfredoBorboa,项目名称:openFrameworks,代码行数:32,代码来源:ofShapeUtils.cpp
示例8: 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);
}
开发者ID:kinetecharts,项目名称:multiTracker,代码行数:28,代码来源:testApp.cpp
示例9: toCv
vector<cv::Point2f> toCv(const ofPolyline& polyline) {
vector<cv::Point2f> contour(polyline.size());
for(int i = 0; i < polyline.size(); i++) {
contour[i].x = polyline[i].x;
contour[i].y = polyline[i].y;
}
return contour;
}
开发者ID:NickHardeman,项目名称:ofxCv,代码行数:8,代码来源:Utilities.cpp
示例10: getOTSMatrix
void phdGimbal2d::getKeyPoints(ofPolyline & _keys) {
_keys.clear();
_keys.addVertex( 1.00, 0.0);
_keys.addVertex( 0.75, 0.0);
_keys.addVertex( 0.00, 0.0);
_keys.addVertex( 0.00,-1.0);
getTransformedPolyline(_keys, _keys, getOTSMatrix());
}
开发者ID:eliasmelofilho,项目名称:phdGIL_074,代码行数:8,代码来源:phdGimbal2d.cpp
示例11: addLaserPolyline
void LaserManager::addLaserPolyline(const ofPolyline& line, ColourSystem* coloursystem, float intens){
if((line.getVertices().size()==0)||(line.getPerimeter()<0.1)) return;
shapes.push_back(new LaserPolyline(line, coloursystem, intens));
}
开发者ID:sebleedelisle,项目名称:PixelPyros,代码行数:8,代码来源:LaserManager.cpp
示例12: draw
void ofCairoRenderer::draw(ofPolyline & poly){
cairo_new_path(cr);
for(int i=0;i<(int)poly.size();i++){
cairo_line_to(cr,poly.getVertices()[i].x,poly.getVertices()[i].y);
}
if(poly.isClosed())
cairo_close_path(cr);
cairo_stroke( cr );
}
开发者ID:AppleToolbox,项目名称:openFrameworks,代码行数:9,代码来源:ofCairoRenderer.cpp
示例13: polylineArea
// Backported from oF-dev branch on github
float ShapeUtils::polylineArea(const ofPolyline &poly) {
if (poly.size() < 2) return 0;
float area = 0;
for (int i = 0; i < (int) poly.size() - 1; i++) {
area += poly[i].x * poly[i+1].y - poly[i+1].x * poly[i].y;
}
area += poly[poly.size()-1].x * poly[0].y - poly[0].x * poly[poly.size()-1].y;
return 0.5 * area;
}
开发者ID:GR7FF,项目名称:SketchSynth,代码行数:11,代码来源:ShapeUtils.cpp
示例14: insertHole
void AnimatedShadow::insertHole( ofPolyline &holeContourLine ){
if (shapes.size() > 0){
holeContourLine.setClosed(true);
holeContourLine.simplify(1);
int lastFrame = shapes.size()-1;
shapes[lastFrame].hole = holeContourLine.getSmoothed(1,1);
shapes[lastFrame].haveHole = true;
}
}
开发者ID:patriciogonzalezvivo,项目名称:mesaDelTiempo,代码行数:10,代码来源:AnimatedShadow.cpp
示例15: draw
//----------------------------------------------------------
void ofGLRenderer::draw(ofPolyline & poly){
// use smoothness, if requested:
if (bSmoothHinted) startSmoothing();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &poly.getVertices()[0].x);
glDrawArrays(poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP, 0, poly.size());
// use smoothness, if requested:
if (bSmoothHinted) endSmoothing();
}
开发者ID:AsherBond,项目名称:openFrameworks,代码行数:12,代码来源:ofGLRenderer.cpp
示例16:
bool operator==(const ofPolyline& lhs, const ofPolyline& rhs)
{
vector<ofPoint> vertices1 = lhs.getVertices();
vector<ofPoint> vertices2 = rhs.getVertices();
if(vertices1.size() != vertices2.size()) return false;
else {
for(int i = 0; i < vertices1.size(); i++) {
if(vertices1[i] != vertices2[i]) return false;
}
}
return true;
}
开发者ID:mattvisco,项目名称:SFPC_2016,代码行数:12,代码来源:ofApp.cpp
示例17: draw
void ropeMesh::draw(ofPolyline stroke){
if (stroke.hasChanged()) {
mesh.clear();
mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
vector < ofPoint > pts = stroke.getVertices();
for (int i = 0; i < pts.size(); i++){
int i_m_1 = MAX(i-1,0);
int i_p_1 = MIN(i+1, pts.size()-1);
ofPoint pta = pts[i_m_1];
ofPoint ptb = pts[i];
ofPoint ptc = pts[i_p_1];
ofPoint diff = ptc - pta;
float angle = atan2(diff.y, diff.x);
angle += PI/2;
float width = 3; //diff.length();
ofPoint offsetA;
offsetA.x = ptb.x + width * cos(angle);
offsetA.y = ptb.y + width * sin(angle);
ofPoint offsetB;
offsetB.x = ptb.x - width * cos(angle);
offsetB.y = ptb.y - width * sin(angle);
ofSetColor(123,94,65);
ofLine(offsetA, offsetB);
mesh.addVertex(offsetA);
mesh.addVertex(offsetB);
}
ofSetColor(197,155,108);
ofFill();
mesh.draw();
ofSetRectMode(OF_RECTMODE_CENTER);
if (stroke.size()>0) {
top[num].draw(stroke.getVertices()[stroke.size()-1], width, height);
}
}
}
开发者ID:bestpaul1985,项目名称:Thesis2013,代码行数:53,代码来源:ropeMesh.cpp
示例18: bezierSplinePoints
void bezierSplinePoints(ofPolyline pnts, int count, int segments, ofPolyline & points) {
double mu, mudelta;
int x1, y1, x2, y2, n, h;
ofVec2f pha, phb;
if(count < 4 || count > 16383) return;
// Phantom Points
pha = ofVec2f(2.0*pnts[0].x-pnts[1].x, 2.0*pnts[0].y-pnts[1].y);
phb = ofVec2f(2.0*pnts[count-1].x-pnts[count-2].x, 2.0*pnts[count-1].y-pnts[count-2].y);
mudelta = 1.0 / segments;
for(n = 2; n < count; n++) {
mu = 0;
if(n == 2) {
x1 = Calculate(mu,pha.x,pnts[n-2].x,pnts[n-1].x,pnts[n].x);
y1 = Calculate(mu,pha.y,pnts[n-2].y,pnts[n-1].y,pnts[n].y);
} else if(n == count) {
x1 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,phb.x);
y1 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,phb.y);
} else {
x1 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,pnts[n].x);
y1 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,pnts[n].y);
}
points.addVertex(x1, y1);
mu = mu + mudelta;
for(h = 1; h < segments; h++) {
if(n == 2) {
x2 = Calculate(mu,pha.x,pnts[n-2].x,pnts[n-1].x,pnts[n].x);
y2 = Calculate(mu,pha.y,pnts[n-2].y,pnts[n-1].y,pnts[n].y);
} else if(n == count) {
x2 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,phb.x);
y2 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,phb.y);
} else {
x2 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,pnts[n].x);
y2 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,pnts[n].y);
}
points.addVertex(x2, y2);
mu = mu + mudelta;
}
}
}
开发者ID:phdcosta,项目名称:phdGui,代码行数:51,代码来源:phdUtils.cpp
示例19:
// Backported from oF-dev branch on github
ofPoint ShapeUtils::getCentroid2D(const ofPolyline &poly) {
ofPoint centroid;
for(int i=0;i<(int)poly.size()-1;i++){
centroid.x += (poly[i].x + poly[i+1].x) * (poly[i].x*poly[i+1].y - poly[i+1].x*poly[i].y);
centroid.y += (poly[i].y + poly[i+1].y) * (poly[i].x*poly[i+1].y - poly[i+1].x*poly[i].y);
}
centroid.x += (poly[poly.size()-1].x + poly[0].x) * (poly[poly.size()-1].x*poly[0].y - poly[0].x*poly[poly.size()-1].y);
centroid.y += (poly[poly.size()-1].y + poly[0].y) * (poly[poly.size()-1].x*poly[0].y - poly[0].x*poly[poly.size()-1].y);
float area = ShapeUtils::polylineArea(poly);
centroid.x /= (6*area);
centroid.y /= (6*area);
return centroid;
}
开发者ID:GR7FF,项目名称:SketchSynth,代码行数:15,代码来源:ShapeUtils.cpp
示例20: setFromPolyline
//--------------------------------------------------------------
void ofxFatLine::setFromPolyline(ofPolyline & poly){
// ofxFatLine();
setGlobalColor(ofGetStyle().color);
setGlobalWidth(ofGetStyle().lineWidth);
if (!poly.getVertices().empty()){
addVertices(poly.getVertices());
for (int i = 0; i <getVertices().size(); i++) {
addColor(globalColor);
addWeight(globalWidth);
}
update();
//*/
}
}
开发者ID:adozenlines,项目名称:ofxFatLines,代码行数:15,代码来源:ofxFatLine.cpp
注:本文中的ofPolyline类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论