Exemple #1
0
// Convert to Printlines
void Layer::MakePrintlines(Vector3d &lastPos, //GCodeState &state,
			   vector<PLine3> &lines3,
			   double offsetZ,
			   Settings &settings) const
{
  const double linewidth      = settings.GetExtrudedMaterialWidth(thickness);
  const double cornerradius   = linewidth*settings.get_double("Slicing","CornerRadius");

  const bool clipnearest      = settings.get_boolean("Slicing","MoveNearest");

  const uint supportExtruder  = settings.GetSupportExtruder();
  const double minshelltime   = settings.get_double("Slicing","MinShelltime");

  const double maxshellspeed  = settings.get_double("Extruder","MaxShellSpeed");
  const bool ZliftAlways      = settings.get_boolean("Extruder","ZliftAlways");

  Vector2d startPoint(lastPos.x(),lastPos.y());

  const double extr_per_mm = settings.GetExtrusionPerMM(thickness);

  //vector<PLine3> lines3;
  Printlines printlines(this, &settings, offsetZ);

  vector<PLine2> lines;

  vector<Poly> polys; // intermediate collection

  // polys to keep line movements inside
  //const vector<Poly> * clippolys = &polygons;
  const vector<Poly> * clippolys = GetOuterShell();

  // 1. Skins, all but last, because they are the lowest lines, below layer Z
  if (skins > 1) {
    for(uint s = 0; s < skins; s++) {
      // z offset from bottom to top:
      double skin_z = Z - thickness + (s+1)*thickness/skins;
      if ( skin_z < 0 ){
	cerr << "Skin Z<0! " << s << " -- " << Z << " -- "<<skin_z <<" -- " << thickness <<  endl;
	continue;
      }

      // skin infill polys:
      if (skinFullInfills[s])
	polys.insert(polys.end(),
		     skinFullInfills[s]->infillpolys.begin(),
		     skinFullInfills[s]->infillpolys.end());
      // add skin infill to lines
      printlines.addPolys(INFILL, polys, false);

      polys.clear();

      // make polygons at skin_z:
      for(size_t p = 0; p < skinPolygons.size(); p++) {
	polys.push_back(Poly(skinPolygons[p], skin_z));
      }
      // add skin to lines
      printlines.addPolys(SKIN, polys, (s==0), // displace at first skin
			  maxshellspeed * 60,
			  minshelltime);
      if (s < skins-1) { // not on the last layer, this handle with all other lines
	// have to get all these separately because z changes
	printlines.makeLines(startPoint, lines);
	if (!ZliftAlways)
	  printlines.clipMovements(*clippolys, lines, clipnearest, linewidth);
	printlines.optimize(linewidth,
			    minshelltime, cornerradius, lines);
	printlines.getLines(lines, lines3, extr_per_mm);
	printlines.clear();
	lines.clear();
      }
      polys.clear();
    }
  } // last skin layer now still in lines
  lines.clear();

  // 2. Skirt
  printlines.addPolys(SKIRT, skirtPolygons, false,
		      maxshellspeed * 60,
		      minshelltime);

  // 3. Support
  if (supportInfill) {
    uint extruderbefore = settings.selectedExtruder;
    settings.SelectExtruder(supportExtruder);
    printlines.addPolys(SUPPORT, supportInfill->infillpolys, false);
    settings.SelectExtruder(extruderbefore);
  }
  // 4. all other polygons:

  //  Shells
  for(int p=shellPolygons.size()-1; p>=0; p--) { // inner to outer
    printlines.addPolys(SHELL, shellPolygons[p],
			(p==(int)(shellPolygons.size())-1),
			maxshellspeed * 60,
			minshelltime);
  }

  //  Infill
  if (normalInfill)
    printlines.addPolys(INFILL, normalInfill->infillpolys, false);
  if (thinInfill)
    printlines.addPolys(INFILL, thinInfill->infillpolys, false);
  if (fullInfill)
    printlines.addPolys(INFILL, fullInfill->infillpolys, false);
  if (skirtInfill)
    printlines.addPolys(INFILL, skirtInfill->infillpolys, false);
  if (decorInfill)
    printlines.addPolys(INFILL, decorInfill->infillpolys, false);
  for (uint b=0; b < bridgeInfills.size(); b++)
    if (bridgeInfills[b])
      printlines.addPolys(INFILL, bridgeInfills[b]->infillpolys, false);

  double polyspeedfactor = printlines.makeLines(startPoint, lines);

  // FINISH

  Command lchange(LAYERCHANGE, LayerNo);
  lchange.where = Vector3d(0.,0.,Z);
  lchange.comment += info();
  lines3.push_back(PLine3(lchange));

  if (!ZliftAlways)
    printlines.clipMovements(*clippolys, lines, clipnearest, linewidth);
  printlines.optimize(linewidth,
		      settings.get_double("Slicing","MinLayertime"),
		      cornerradius, lines);
  if ((guint)LayerNo < (guint)settings.get_integer("Slicing","FirstLayersNum"))
    printlines.setSpeedFactor(settings.get_double("Slicing","FirstLayersSpeed"), lines);
  double slowdownfactor = printlines.getSlowdownFactor() * polyspeedfactor;

  if (settings.get_boolean("Slicing","FanControl")) {
    int fanspeed = settings.get_integer("Slicing","MinFanSpeed");
    if (slowdownfactor < 1 && slowdownfactor > 0) {
      double fanfactor = 1-slowdownfactor;
      fanspeed +=
	int(fanfactor * (settings.get_integer("Slicing","MaxFanSpeed")-settings.get_integer("Slicing","MinFanSpeed")));
      fanspeed = CLAMP(fanspeed, settings.get_integer("Slicing","MinFanSpeed"),
		       settings.get_integer("Slicing","MaxFanSpeed"));
      //cerr << slowdownfactor << " - " << fanfactor << " - " << fanspeed << " - " << endl;
    }
    Command fancommand(FANON, fanspeed);
    lines3.push_back(PLine3(fancommand));
  }

  printlines.getLines(lines, lines3, extr_per_mm);
  if (lines3.size()>0)
    lastPos = lines3.back().to;
}
Exemple #2
0
void Layer::MakeShells(const Settings &settings)
{
  double extrudedWidth        = settings.GetExtrudedMaterialWidth(thickness);
  double roundline_extrfactor =
    settings.RoundedLinewidthCorrection(extrudedWidth,thickness);
  double distance       = 0.5 * extrudedWidth;
  double cleandist      = min(distance/CLEANFACTOR, thickness/CLEANFACTOR);
  double shelloffset    = settings.get_double("Slicing","ShellOffset");
  uint   shellcount     = settings.get_integer("Slicing","ShellCount");
  double infilloverlap  = settings.get_double("Slicing","InfillOverlap");

  // first shrink with global offset
  vector<Poly> shrinked = Clipping::getOffset(polygons, -2.0/M_PI*extrudedWidth-shelloffset);

  vector<Poly> thickPolygons;
  FindThinpolys(shrinked, extrudedWidth, thickPolygons, thinPolygons);
  shrinked = thickPolygons;

  for (uint i = 0; i<thinPolygons.size(); i++)
    thinPolygons[i].cleanup(cleandist);

  // // expand shrinked to get to the outer shell again
  // shrinked = Clipping::getOffset(shrinked, 2*distance);
  for (uint i = 0; i<shrinked.size(); i++)
    shrinked[i].cleanup(cleandist);

  //vector<Poly> shrinked = Clipping::getShrinkedCapped(polygons,distance);
  // outmost shells
  if (shellcount > 0) {
    if (skins>1) { // either skins
      for (uint i = 0; i<shrinked.size(); i++)  {
	shrinked[i].setExtrusionFactor(1./skins*roundline_extrfactor);
      }
      skinPolygons = shrinked;
    } else {  // or normal shell
      clearpolys(shellPolygons);
      for (uint i = 0; i<shrinked.size(); i++)  {
	shrinked[i].setExtrusionFactor(roundline_extrfactor);
      }
      shellPolygons.push_back(shrinked);
    }
    // inner shells
    for (uint i = 1; i<shellcount; i++) // shrink from shell to shell
      {
	shrinked = Clipping::getOffset(shrinked,-extrudedWidth);
	vector<Poly> thinpolys;
	FindThinpolys(shrinked, extrudedWidth, thickPolygons, thinpolys);
	shrinked = thickPolygons;
	thinPolygons.insert(thinPolygons.end(), thinpolys.begin(),thinpolys.end());
	for (uint j = 0; j<shrinked.size(); j++)
	  shrinked[j].cleanup(cleandist);
	//shrinked = Clipping::getShrinkedCapped(shrinked,extrudedWidth);
	shellPolygons.push_back(shrinked);
      }
  }
  // the filling polygon
  if (settings.get_boolean("Slicing","DoInfill")) {
    fillPolygons = Clipping::getOffset(shrinked,-(1.-infilloverlap)*extrudedWidth);
    for (uint i = 0; i<fillPolygons.size(); i++)
      fillPolygons[i].cleanup(cleandist);
    //fillPolygons = Clipping::getShrinkedCapped(shrinked,extrudedWidth);
    //cerr << LayerNo << " > " << fillPolygons.size()<< endl;
  }

  calcConvexHull();

  //cerr << " .. made " << fillPolygons.size() << " offsetpolys "  << endl;
  // for (uint i =0; i<shellPolygons.size(); i++) {
  //   cout << "shell " << i << endl;
  //   for (uint j =1; j<shellPolygons[i].size(); j++) {
  //     shellPolygons[i][j].printinfo();
  //   }
  // }
}