فهرست منبع

Store trackpoints in 3mf file

Johannes Kreutz 3 سال پیش
والد
کامیت
ded6f49592
4فایلهای تغییر یافته به همراه59 افزوده شده و 1 حذف شده
  1. 8 0
      trackpoint-app/CMakeLists.txt
  2. 24 1
      trackpoint-app/src/main.cpp
  3. 26 0
      trackpoint-app/thirdparty/json.cmake
  4. 1 0
      trackpoint-app/thirdparty/qt.cmake

+ 8 - 0
trackpoint-app/CMakeLists.txt

@@ -18,17 +18,25 @@ INCLUDE(thirdparty/openscenegraph.cmake)
 # lib3mf
 INCLUDE(thirdparty/lib3mf.cmake)
 
+# Json
+INCLUDE(thirdparty/json.cmake)
+
+# Qt
+INCLUDE(thirdparty/qt.cmake)
+
 # The executable we want to build
 ADD_EXECUTABLE(TrackpointApp src/main.cpp)
 
 INCLUDE_DIRECTORIES(
   ${${OPENSCENEGRAPH_PREFIX}_SOURCE_DIR}/include
   ${${LIB3MF_PREFIX}_BINARY_DIR}/Autogenerated/Bindings/Cpp
+  ${${JSON_PREFIX}_SOURCE_DIR}/include
 )
 
 TARGET_LINK_LIBRARIES(TrackpointApp
   osg osgViewer osgDB osgGA osgText osgUtil
   lib3mf
+  nlohmann_json::nlohmann_json
 )
 
 # Header to have version number available in the code

+ 24 - 1
trackpoint-app/src/main.cpp

@@ -16,6 +16,9 @@
 #include <string>
 #include <math.h>
 #include "lib3mf_implicit.hpp"
+#include <nlohmann/json.hpp>
+
+using json = nlohmann::json;
 
 const char* openScadBase =
   "$fn = 100;\n"
@@ -29,6 +32,7 @@ public:
   osg::ref_ptr<osg::MatrixTransform> getUppermostRoot();
   osg::Vec3 getTranslation();
   osg::Vec3 getRotation();
+  osg::Vec3 getTrackPoint();
 
 protected:
   osg::ref_ptr<osg::MatrixTransform> _translationGroup;
@@ -105,6 +109,10 @@ osg::Vec3 TrackPoint::getRotation() {
   return osg::Vec3(xRotation, yRotation, zRotation);
 }
 
+osg::Vec3 TrackPoint::getTrackPoint() {
+  return _trackOrigin;
+}
+
 class ThreeMFWriter {
 public:
   ThreeMFWriter();
@@ -125,7 +133,22 @@ void ThreeMFWriter::writeTrackPoints(std::vector<TrackPoint*> points, std::strin
   reader->ReadFromFile("/tmp/output.3mf");
 
   Lib3MF::PMetaDataGroup metaData = model->GetMetaDataGroup();
-  printf("Having %d MetaData entries\n", metaData->GetMetaDataCount());
+
+  json trackpointData;
+  std::vector<std::vector<float>> pointsList;
+  for (TrackPoint* point: points) {
+    std::vector<float> pointData;
+    osg::Vec3 trackPoint = point->getTrackPoint();
+    pointData.push_back(trackPoint.x());
+    pointData.push_back(trackPoint.y());
+    pointData.push_back(trackPoint.z());
+    pointsList.push_back(pointData);
+  }
+  trackpointData["trackpoints"] = {
+    {"tracking-system", "optitrack"},
+    {"trackpoints", pointsList}
+  };
+  metaData->AddMetaData("tk-ar-tracking", "trackpoints", trackpointData.dump(), "string", true);
 
   Lib3MF::PWriter writer = model->QueryWriter("3mf");
   writer->WriteToFile(path);

+ 26 - 0
trackpoint-app/thirdparty/json.cmake

@@ -0,0 +1,26 @@
+# Build Json
+
+# The GitHub release (tag) we want to use
+SET(JSON_TAG v3.9.1)
+
+SET(JSON_PREFIX nlohmann_json)
+
+SET(JSON_URL https://github.com/nlohmann/json)
+
+# Configure Json
+SET(JSON_BuildTests OFF CACHE INTERNAL "")
+
+# Add Json
+FETCHCONTENT_DECLARE(
+  ${JSON_PREFIX}
+  PREFIX ${JSON_PREFIX}
+  GIT_REPOSITORY ${JSON_URL}
+  GIT_TAG ${JSON_TAG}
+)
+
+FETCHCONTENT_GETPROPERTIES(${JSON_PREFIX})
+
+IF(NOT ${JSON_PREFIX}_POPULATED)
+  FETCHCONTENT_POPULATE(${JSON_PREFIX})
+  ADD_SUBDIRECTORY(${${JSON_PREFIX}_SOURCE_DIR} ${${JSON_PREFIX}_BINARY_DIR})
+ENDIF()

+ 1 - 0
trackpoint-app/thirdparty/qt.cmake

@@ -0,0 +1 @@
+# Build Qt