slabasebed.cpp 2.5 KB

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