Пример #1
0
void
ClipperPolygon_to_Slic3rPolygon(const ClipperLib::Polygon &input, Slic3r::Polygon &output)
{
    output.points.clear();
    for (ClipperLib::Polygon::const_iterator pit = input.begin(); pit != input.end(); ++pit) {
        output.points.push_back(Slic3r::Point( (*pit).X, (*pit).Y ));
    }
}
Пример #2
0
//--------------------------------------------------------------
ofPolyline ofxClipper::polygon_to_ofPolyline(ClipperLib::Polygon& polygon) {
    vector<ClipperLib::IntPoint>::iterator iter;
    ofPolyline polyline;
    for(iter = polygon.begin(); iter != polygon.end(); iter++) {
        ofPoint pnt((*iter).X / double(clipperGlobalScale),  // bring back to our coords
                    (*iter).Y / double(clipperGlobalScale)); // bring back to our coords
        polyline.addVertex(pnt);
    }
    polyline.close(); // close it
    return polyline;
}
Пример #3
0
int main(int argc, char* argv[]) {
	if (argc != 3) {
		cout<<"Usage: offset.exe <input.poly> <output.poly>\n\n  Input and output files should be different.\n  Only one ring poly files are accepted now without inner rings.\n  Default offset is 0.001 degree\n";
		return 0;

	}
	ifstream f(argv[1], ifstream::in);
	ofstream outfile(argv[2], ofstream::out);
	outfile.precision(9);
	string s;
	for (int i=0;i<3;i++) {
		getline(f, s);
		outfile<<s<<"\n";
	}
	ClipperLib::Polygons polygons;
	ClipperLib::Polygon polygon;
	while(!f.eof()) {
		f>>s;
		if (s == "END") {
			break;
		}
		double c1 = ::atof(s.c_str());
		f>>s;
		double c2 = ::atof(s.c_str());
		ClipperLib::IntPoint point(c1 * MUL, c2 * MUL);
		polygon.push_back(point);
	}
	polygons.push_back(polygon);
	double distance = 0.001 * MUL;

	ClipperLib::Polygons res_polygons;
	ClipperLib::OffsetPolygons (polygons, res_polygons, distance, ClipperLib::jtMiter);

	if (res_polygons.size() < 1) { cerr<<"Bad output of OffsetPolygons!\n";return 1;}
	ClipperLib::Polygon result = res_polygons.front();

	for (ClipperLib::Polygon::iterator it = result.begin(); it != result.end(); ++it) {
		ClipperLib::IntPoint point = *it;
		outfile << "   " << (point.X/MUL) << "   " << (point.Y/MUL) << " \n";
	}

	outfile<<s;
	while (!f.eof()) {
		getline(f, s);
		outfile<<s<<"\n";
	}

	return 0;
}