slabasebed.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <libslic3r/libslic3r.h>
  5. #include <libslic3r/TriangleMesh.hpp>
  6. #include <libslic3r/Tesselate.hpp>
  7. #include <libslic3r/ClipperUtils.hpp>
  8. #include <libslic3r/SLA/SLABasePool.hpp>
  9. #include <libslic3r/SLA/SLABoilerPlate.hpp>
  10. #include <libnest2d/tools/benchmark.h>
  11. const std::string USAGE_STR = {
  12. "Usage: slabasebed stlfilename.stl"
  13. };
  14. namespace Slic3r { namespace sla {
  15. Contour3D create_base_pool(const Polygons &ground_layer,
  16. const ExPolygons &holes = {},
  17. const PoolConfig& cfg = PoolConfig());
  18. Contour3D walls(const Polygon& floor_plate, const Polygon& ceiling,
  19. double floor_z_mm, double ceiling_z_mm,
  20. double offset_difference_mm, ThrowOnCancel thr);
  21. void offset(ExPolygon& sh, coord_t distance);
  22. }
  23. }
  24. int main(const int argc, const char *argv[]) {
  25. using namespace Slic3r;
  26. using std::cout; using std::endl;
  27. if(argc < 2) {
  28. cout << USAGE_STR << endl;
  29. return EXIT_SUCCESS;
  30. }
  31. TriangleMesh model;
  32. Benchmark bench;
  33. model.ReadSTLFile(argv[1]);
  34. model.align_to_origin();
  35. ExPolygons ground_slice;
  36. sla::base_plate(model, ground_slice, 0.1f);
  37. if(ground_slice.empty()) return EXIT_FAILURE;
  38. ground_slice = offset_ex(ground_slice, 0.5);
  39. ExPolygon gndfirst; gndfirst = ground_slice.front();
  40. sla::breakstick_holes(gndfirst, 0.5, 10, 0.3);
  41. sla::Contour3D mesh;
  42. bench.start();
  43. sla::PoolConfig cfg;
  44. cfg.min_wall_height_mm = 0;
  45. cfg.edge_radius_mm = 0;
  46. mesh = sla::create_base_pool(to_polygons(ground_slice), {}, cfg);
  47. bench.stop();
  48. cout << "Base pool creation time: " << std::setprecision(10)
  49. << bench.getElapsedSec() << " seconds." << endl;
  50. for(auto& trind : mesh.indices) {
  51. Vec3d p0 = mesh.points[size_t(trind[0])];
  52. Vec3d p1 = mesh.points[size_t(trind[1])];
  53. Vec3d p2 = mesh.points[size_t(trind[2])];
  54. Vec3d p01 = p1 - p0;
  55. Vec3d p02 = p2 - p0;
  56. auto a = p01.cross(p02).norm() / 2.0;
  57. if(std::abs(a) < 1e-6) std::cout << "degenerate triangle" << std::endl;
  58. }
  59. // basepool.write_ascii("out.stl");
  60. std::fstream outstream("out.obj", std::fstream::out);
  61. mesh.to_obj(outstream);
  62. return EXIT_SUCCESS;
  63. }