slabasebed.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <libslic3r/libslic3r.h>
  5. #include <libslic3r/TriangleMesh.hpp>
  6. #include <libslic3r/SLA/SLABasePool.hpp>
  7. #include <libslic3r/SLA/SLABoilerPlate.hpp>
  8. #include <libnest2d/tools/benchmark.h>
  9. const std::string USAGE_STR = {
  10. "Usage: slabasebed stlfilename.stl"
  11. };
  12. namespace Slic3r { namespace sla {
  13. Contour3D convert(const Polygons& triangles, coord_t z, bool dir);
  14. Contour3D walls(const Polygon& floor_plate, const Polygon& ceiling,
  15. double floor_z_mm, double ceiling_z_mm,
  16. double offset_difference_mm, ThrowOnCancel thr);
  17. void offset(ExPolygon& sh, coord_t distance);
  18. }
  19. }
  20. int main(const int argc, const char *argv[]) {
  21. using namespace Slic3r;
  22. using std::cout; using std::endl;
  23. if(argc < 2) {
  24. cout << USAGE_STR << endl;
  25. return EXIT_SUCCESS;
  26. }
  27. TriangleMesh model;
  28. Benchmark bench;
  29. model.ReadSTLFile(argv[1]);
  30. model.align_to_origin();
  31. ExPolygons ground_slice;
  32. sla::Contour3D mesh;
  33. // TriangleMesh basepool;
  34. sla::base_plate(model, ground_slice, 0.1f);
  35. if(ground_slice.empty()) return EXIT_FAILURE;
  36. ExPolygon bottom_plate = ground_slice.front();
  37. ExPolygon top_plate = bottom_plate;
  38. sla::offset(top_plate, coord_t(3.0/SCALING_FACTOR));
  39. sla::offset(bottom_plate, coord_t(1.0/SCALING_FACTOR));
  40. bench.start();
  41. Polygons top_plate_triangles, bottom_plate_triangles;
  42. top_plate.triangulate_p2t(&top_plate_triangles);
  43. bottom_plate.triangulate_p2t(&bottom_plate_triangles);
  44. auto top_plate_mesh = sla::convert(top_plate_triangles, coord_t(3.0/SCALING_FACTOR), false);
  45. auto bottom_plate_mesh = sla::convert(bottom_plate_triangles, 0, true);
  46. mesh.merge(bottom_plate_mesh);
  47. mesh.merge(top_plate_mesh);
  48. sla::Contour3D w = sla::walls(bottom_plate.contour, top_plate.contour, 0, 3, 2.0, [](){});
  49. mesh.merge(w);
  50. // sla::create_base_pool(ground_slice, basepool);
  51. bench.stop();
  52. cout << "Base pool creation time: " << std::setprecision(10)
  53. << bench.getElapsedSec() << " seconds." << endl;
  54. // basepool.write_ascii("out.stl");
  55. std::fstream outstream("out.obj", std::fstream::out);
  56. mesh.to_obj(outstream);
  57. return EXIT_SUCCESS;
  58. }