OpenScadRenderer.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Include own headers
  2. #include "OpenScadRenderer.hpp"
  3. // Include modules
  4. #include "PlatformSupport.hpp"
  5. // Include dependencies
  6. #include <iostream>
  7. #include <fstream>
  8. #include <filesystem>
  9. #include <cstdio>
  10. #include <memory>
  11. #include <stdexcept>
  12. #include <string>
  13. #include <array>
  14. const char* openScadBase =
  15. "$fn = 100;\n"
  16. "module optiTrackPointBase(translation, rotation, length, radius) {\n"
  17. "translate(translation) rotate(rotation) cylinder(length, radius, radius, false);\n"
  18. "}\n";
  19. bool OpenScadRenderer::openScadAvailable() {
  20. std::string path = openScadPath + " -v";
  21. int result = system(path.c_str());
  22. return result == 0;
  23. }
  24. void OpenScadRenderer::renderOptiTrack(std::vector<OptiTrackPoint*> points) {
  25. std::ofstream scadFile;
  26. scadFile.open(std::filesystem::temp_directory_path().u8string() + fileDelimiter + "trackpointapp_export_optitrack.scad");
  27. scadFile << openScadBase;
  28. scadFile << "import(\"trackpointapp_export.3mf\");\n";
  29. for (OptiTrackPoint* point: points) {
  30. osg::Vec3 translation = point->getTranslation();
  31. osg::Vec3 rotation = point->getRotation();
  32. scadFile << "optiTrackPointBase([" << translation.x() << "," << translation.y() << "," << translation.z() << "], [" << rotation.x() << "," << rotation.y() << "," << rotation.z() << "], " << point->getLength() << ", " << point->getRadius() << ");\n";
  33. }
  34. scadFile.close();
  35. std::string command = openScadPath + " -o " + std::filesystem::temp_directory_path().u8string() + fileDelimiter + "trackpointapp_render_optitrack.3mf " + std::filesystem::temp_directory_path().u8string() + fileDelimiter + "trackpointapp_export_optitrack.scad";
  36. system(command.c_str());
  37. }