本文整理汇总了C++中ofPolyline::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPolyline::size方法的具体用法?C++ ofPolyline::size怎么用?C++ ofPolyline::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPolyline
的用法示例。
在下文中一共展示了ofPolyline::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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();
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
}
}
示例7: makeStroke
void Plant::makeStroke(int i,
float min,
float max,
ofPolyline ¢erLine,
ofPolyline *line1,
ofPolyline *line2
){
ofVec2f v = centerLine.getTangentAtIndex(i);
float length = ofMap(i, 0, centerLine.size()-1, max, min) ;
float angle = 90;
float hackValue = 0.8;
if(i==0 || i == centerLine.size()-1){
ofVec2f p = centerLine.getVertices()[i] + v.rotate(angle)*length*hackValue;
ofVec2f v2 = centerLine.getTangentAtIndex(i);
ofVec2f p2 = centerLine.getVertices()[i] + v2.rotate(-angle)*length*hackValue;
line1->lineTo(p);
line2->lineTo(p2);
}
if(i>0 && i < centerLine.size()-1){
makeCorner(line1, centerLine, i, angle, length);
makeCorner(line2, centerLine, i, -angle, length);
}
if(i == centerLine.size()-1){
ofVec2f v = centerLine.getTangentAtIndex(i);
float length = ofMap(i, 0, centerLine.size()-1, min, min) ;
ofVec2f _p2 = centerLine.getVertices()[i] + v.rotate(90)*length*hackValue;
ofVec2f _p1 = centerLine.getVertices()[i] + v.rotate(180)*length*hackValue;
ofVec2f _p3 = _p1 + (_p2 - _p1)/2;
ofVec2f _delta = _p2 - _p1;
ofVec2f pCenter = _p3 - _delta.getPerpendicular()*min;
ofVec2f pLeft = pCenter - _delta/2;
ofVec2f pRight = pCenter + _delta/2;
line2->bezierTo(_p1, pLeft, pCenter);
line1->bezierTo(_p2, pRight, pCenter);
// ofSetColor(ofColor::yellow);
// ofDrawCircle(p1, 5);
// ofSetColor(ofColor::red);
// ofDrawCircle(p2, 5);
// ofSetColor(ofColor::blueViolet);
// ofDrawCircle(p3, 5);
// ofSetColor(ofColor::darkMagenta);
// ofDrawCircle(pCenter, 5);
// ofSetColor(ofColor::lightPink);
// ofDrawCircle(pLeft, 5);
// ofSetColor(ofColor::lightSkyBlue);
// ofDrawCircle(pRight, 5);
}
}
示例8:
// 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;
}
示例9: toGlm
glmPolyline toGlm(const ofPolyline &_poly){
glmPolyline poly;
for (int i = 0; i < _poly.size(); i++) {
poly.add(toGlm(_poly[i]));
}
return poly;
}
示例10: phdPointInsidePolygon
//--------------------------------------------------------------
// Code by Theo from URL above
//--------------------------------------------------------------
// http://www.openframeworks.cc/forum/viewtopic.php?f=9&t=1443
//--------------------------------------------------------------
bool phdPointInsidePolygon(ofPolyline & _points, float px, float py) {
int N = _points.size();
if (N == 0) return false;
int counter = 0;
int i;
double xinters;
ofPoint p1, p2;
p1 = _points[0];
for (int i = 1; i <= N; i++) {
p2 = _points[i % N];
if (py > MIN(p1.y,p2.y)) {
if (py <= MAX(p1.y,p2.y)) {
if (px <= MAX(p1.x,p2.x)) {
if (p1.y != p2.y) {
xinters = (py-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x;
if (p1.x == p2.x || px <= xinters) counter++;
}
}
}
}
p1 = p2;
}
if (counter % 2 == 0)
return false;
else
return true;
}
示例11: 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());
}
示例12: ofGetBoundingBox
ofRectangle ofGetBoundingBox(const ofPolyline& polyline) {
ofRectangle box;
int n = polyline.size();
if(n > 0) {
const ofPoint& first = polyline[0];
// inititally, use width and height as max x and max y
box.set(first.x, first.y, first.x, first.y);
for(int i = 0; i < n; i++) {
const ofPoint& cur = polyline[i];
if(cur.x < box.x) {
box.x = cur.x;
}
if(cur.x > box.width) {
box.width = cur.x;
}
if(cur.y < box.y) {
box.y = cur.y;
}
if(cur.y > box.height) {
box.height = cur.y;
}
}
// later, we make width and height relative
box.width -= box.x;
box.height -= box.y;
}
return box;
}
示例13: 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;
}
示例14: send
//
// send ofPolyline to laser cutter
//
bool ofxEpilog::send(ofPolyline vector_vertexes)
{
if(vector_vertexes.size() == 0)
return false;
ofBuffer buffer;
buffer.append(createPayloadHeader(getMachineProfile(), getOutputConfig()));
// end raster part regardless of it's empty
buffer.append(PCL_RASTER_END);
// begin HPGL commands (vector part)
buffer.append(HPGL_START);
buffer.append(HPGL_VECTOR_INIT + HPGL_CMD_DELIMITER);
// create vector part and append to the buffer
buffer.append(createPayloadVectorBody(vector_vertexes, getOutputConfig()));
if(!keep_alive)
buffer.append(createPayloadFooter()); // end the session
if(pjl_file.get() != NULL)
pjl_file->writeFromBuffer(buffer);
return tcp_client.sendRaw(buffer);
}
示例15: 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);
}