示例#1
0
void
scaleClipperPolygons(ClipperLib::Polygons &polygons, const double scale)
{
    for (ClipperLib::Polygons::iterator it = polygons.begin(); it != polygons.end(); ++it) {
        for (ClipperLib::Polygon::iterator pit = (*it).begin(); pit != (*it).end(); ++pit) {
            (*pit).X *= scale;
            (*pit).Y *= scale;
        }
    }
}
示例#2
0
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);
    }
}
示例#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;
}
示例#4
0
std::list<TPPLPoly> fromClipperFormat2PolyPartitionFormat(const ClipperLib::Polygons& clipperPoly)
{
    std::list<TPPLPoly> polypartitionPoly;
    for(unsigned int i=0; i < clipperPoly.size() ; ++i)
        polypartitionPoly.push_back( TPPLPoly_To_Polygon(clipperPoly[i]) );

    return polypartitionPoly;
}
示例#5
0
// clip infill pattern polys against polys
void Infill::addInfill(double z, const vector<Poly> polys, 
		       const ClipperLib::Polygons patterncpolys,
		       double offsetDistance)
{
  ClipperLib::Polygons cpolys;
  //   ClipperLib::OffsetPolygons(Clipping::getClipperPolygons(polys), cpolys, 100,
  // 			       ClipperLib::jtMiter,1);
  // else 
    cpolys = Clipping::getClipperPolygons(polys);
  ClipperLib::Clipper clpr;
  clpr.AddPolygons(patterncpolys,ClipperLib::ptSubject);
  clpr.AddPolygons(cpolys,ClipperLib::ptClip);
  ClipperLib::Polygons result;
  clpr.Execute(ClipperLib::ctIntersection, result, 
	       ClipperLib::pftEvenOdd, ClipperLib::pftNonZero);
  if (type==PolyInfill) { // reversal from evenodd clipping
    for (uint i = 0; i<result.size(); i+=2)
      std::reverse(result[i].begin(),result[i].end());
  }
  addInfillPolys(Clipping::getPolys(result, z, extrusionfactor));
}
示例#6
0
GeneralPolygon::GeneralPolygon(const ClipperLib::Polygons& Polygons): 
	_position(0.0f, 0.0f), _rotation(0.0f), _size(1.0f, 1.0f), _gluTesselator(NULL), _renderMode(RenderMethod::GLU_Tessalation)
{
	_contours.resize(Polygons.size());
	for(unsigned int c=0; c < _contours.size() ; ++c)
	{
		const ClipperLib::Polygon &polygon = Polygons[c];
		Contour &contour = _contours[c];

		contour.resize(polygon.size());

		for(unsigned int v=0; v < polygon.size() ; ++v)
			contour[v] = sf::Vector2f(polygon[v].X / clipperScaleCoeficient, polygon[v].Y / clipperScaleCoeficient);

		PolygonWindingOrder winding = _getWinding(contour);

		if( winding == PolygonWindingOrder::Winding_CW )
			std::reverse(contour.begin(), contour.end());
		
	}

	_updateOptimalConvexTesselation();
}
示例#7
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;
	}
}
示例#8
0
//--------------------------------------------------------------
void ofxClipper::polygons_to_ofxPolylines(ClipperLib::Polygons& polygons,ofxPolylines& polylines) {
    vector<ClipperLib::Polygon>::iterator iter;
    for(iter = polygons.begin(); iter != polygons.end(); iter++) {
        polylines.push_back(polygon_to_ofPolyline((*iter)));
    }
}
示例#9
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)));
    }
}