void
Slic3rPolygons_to_ClipperPolygons(const Slic3r::Polygons &input, ClipperLib::Polygons &output)
{
    output.clear();
    for (Slic3r::Polygons::const_iterator it = input.begin(); it != input.end(); ++it) {
        ClipperLib::Polygon p;
        Slic3rPolygon_to_ClipperPolygon(*it, p);
        output.push_back(p);
    }
}
Exemple #2
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;
}
void NavMeshEditorApp::_processEvent(const sf::Event& event)
{
	_polygonUserController.processUserEvent(event);

	switch(event.type)
	{
		case sf::Event::KeyPressed:
		{
			switch(event.key.code)
			{
				case sf::Keyboard::A:
				{
					_changeEditorState(EditorState::EditingWalkableRegion);

					std::cerr<<"State: EditingWalkableRegion"<<std::endl;
				}
					break;

				case sf::Keyboard::S:
				{
					_changeEditorState(EditorState::EditingObstacleRegion);

					std::cerr<<"State: EditingObstacleRegion"<<std::endl;
				}
					break;

				case sf::Keyboard::Q:
				{
					// walkableRegions
					ClipperLib::Polygons walkableRegions;
					for(unsigned int i=0; i < _walkableCuadrilaterals.size() ; ++i)
					{
						ClipperLib::Polygons p = (ClipperLib::Polygons)*_walkableCuadrilaterals[i];
						for(unsigned int j=0; j < p.size() ; ++j)
							walkableRegions.push_back(p[j]);
					}

					std::cerr<<"Process Walkable Polygons"<<std::endl;

					// obstaclesRegions
					ClipperLib::Polygons obstacleRegions;
					for(unsigned int i=0; i < _obstacleCuadrilaterals.size() ; ++i)
					{
						ClipperLib::Polygons p = (ClipperLib::Polygons)*_obstacleCuadrilaterals[i];
						for(unsigned int j=0; j < p.size() ; ++j)
							obstacleRegions.push_back(p[j]);
					}

					std::cerr<<"Process Obstacles Polygons"<<std::endl;

					_pNavMesh->processNavigationMesh( walkableRegions, obstacleRegions );

					walkableRegions.clear();
					obstacleRegions.clear();

					_changeEditorState(EditorState::ViewingNavMeshResult);
				}
					break;

				case sf::Keyboard::Escape:
					_App.close();
					break;
			}
		}
			break;
				
		case sf::Event::Closed://Si se cierra la ventana
			_App.close();
			break;
	}
}
Exemple #4
0
//--------------------------------------------------------------
void ofxClipper::ofxPolylines_to_Polygons(ofxPolylines& polylines,ClipperLib::Polygons& polygons) {
    vector<ofPolyline>::iterator iter;
    for(iter = polylines.begin(); iter != polylines.end(); iter++) {
        polygons.push_back(ofPolyline_to_Polygon((*iter)));
    }
}