|
@@ -4,13 +4,17 @@
|
|
|
|
|
|
#include "MainWindow.hpp"
|
|
|
#include "StringBasics.hpp"
|
|
|
+#include "TrackPointRenderer.hpp"
|
|
|
|
|
|
|
|
|
#include <typeinfo>
|
|
|
#include <iostream>
|
|
|
|
|
|
+#define META_NAMESPACE "tk-ar-tracking"
|
|
|
+
|
|
|
ProjectStore::ProjectStore() {
|
|
|
- projectLoaded = false;
|
|
|
+ _projectLoaded = false;
|
|
|
+ _projectModified = false;
|
|
|
load3mfLib();
|
|
|
}
|
|
|
|
|
@@ -21,28 +25,12 @@ void ProjectStore::loadMesh(std::string meshFile) {
|
|
|
if (StringBasics::endsWithCaseInsensitive(meshFile, ".STL")) {
|
|
|
printf("Currently unsupported.\n");
|
|
|
} else if (StringBasics::endsWithCaseInsensitive(meshFile, ".3MF")) {
|
|
|
- projectLoaded = true;
|
|
|
+ _projectLoaded = true;
|
|
|
|
|
|
Lib3MF::PReader reader = _project->QueryReader("3mf");
|
|
|
reader->ReadFromFile(meshFile);
|
|
|
-
|
|
|
- Lib3MF::PMeshObjectIterator meshIterator = _project->GetMeshObjects();
|
|
|
-
|
|
|
- if (meshIterator->Count() != 1) {
|
|
|
-
|
|
|
- printf("Not 1 mesh: %llu\n", meshIterator->Count());
|
|
|
- return;
|
|
|
- }
|
|
|
- meshIterator->MoveNext();
|
|
|
- Lib3MF::PMeshObject mesh = meshIterator->GetCurrentMeshObject();
|
|
|
-
|
|
|
- std::vector<Lib3MF::sPosition> verticesBuffer;
|
|
|
- mesh->GetVertices(verticesBuffer);
|
|
|
- std::vector<Lib3MF::sTriangle> triangleBuffer;
|
|
|
- mesh->GetTriangleIndices(triangleBuffer);
|
|
|
- render3MFMesh(verticesBuffer, triangleBuffer);
|
|
|
- MainWindow* mainWindow = MainWindow::getInstance();
|
|
|
- mainWindow->renderView(Edit);
|
|
|
+ render3MFMesh();
|
|
|
+ MainWindow::getInstance()->renderView(Edit);
|
|
|
} else {
|
|
|
|
|
|
printf("Unsupported file type.\n");
|
|
@@ -50,10 +38,12 @@ void ProjectStore::loadMesh(std::string meshFile) {
|
|
|
}
|
|
|
|
|
|
bool ProjectStore::loadProject(std::string projectFile) {
|
|
|
- if (!projectLoaded) {
|
|
|
+ if (!_projectLoaded) {
|
|
|
Lib3MF::PReader reader = _project->QueryReader("3mf");
|
|
|
reader->ReadFromFile(projectFile);
|
|
|
- projectLoaded = true;
|
|
|
+ _projectLoaded = true;
|
|
|
+ _projectModified = false;
|
|
|
+ loadMetaData();
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
@@ -61,16 +51,16 @@ bool ProjectStore::loadProject(std::string projectFile) {
|
|
|
|
|
|
bool ProjectStore::saveProject() {
|
|
|
if (_projectFile != "") {
|
|
|
- Lib3MF::PWriter writer = _project->QueryWriter("3mf");
|
|
|
- writer->WriteToFile(_projectFile);
|
|
|
- return true;
|
|
|
+ return saveProject(_projectFile);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
bool ProjectStore::saveProject(std::string path) {
|
|
|
+ updateMetaData();
|
|
|
Lib3MF::PWriter writer = _project->QueryWriter("3mf");
|
|
|
writer->WriteToFile(path);
|
|
|
+ _projectFile = path;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -112,7 +102,23 @@ void ProjectStore::load3mfLib() {
|
|
|
_project = _wrapper->CreateModel();
|
|
|
}
|
|
|
|
|
|
-void ProjectStore::render3MFMesh(const std::vector<Lib3MF::sPosition> verticesBuffer, const std::vector<Lib3MF::sTriangle> triangleBuffer) {
|
|
|
+void ProjectStore::render3MFMesh() {
|
|
|
+
|
|
|
+ Lib3MF::PMeshObjectIterator meshIterator = _project->GetMeshObjects();
|
|
|
+
|
|
|
+ if (meshIterator->Count() != 1) {
|
|
|
+
|
|
|
+ printf("Not 1 mesh: %llu\n", meshIterator->Count());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ meshIterator->MoveNext();
|
|
|
+ Lib3MF::PMeshObject mesh = meshIterator->GetCurrentMeshObject();
|
|
|
+
|
|
|
+ std::vector<Lib3MF::sPosition> verticesBuffer;
|
|
|
+ mesh->GetVertices(verticesBuffer);
|
|
|
+ std::vector<Lib3MF::sTriangle> triangleBuffer;
|
|
|
+ mesh->GetTriangleIndices(triangleBuffer);
|
|
|
+
|
|
|
|
|
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
|
|
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
|
|
@@ -139,6 +145,68 @@ void ProjectStore::render3MFMesh(const std::vector<Lib3MF::sPosition> verticesBu
|
|
|
mainWindow->getOsgWidget()->renderBaseMesh(vertices, normals);
|
|
|
}
|
|
|
|
|
|
-void ProjectStore::exportMetaData() {
|
|
|
+void ProjectStore::updateMetaData() {
|
|
|
+ Lib3MF::PMetaDataGroup metaData = _project->GetMetaDataGroup();
|
|
|
+ try {
|
|
|
+ Lib3MF::PMetaData versionInformation = metaData->GetMetaDataByKey(META_NAMESPACE, "format");
|
|
|
+ } catch (Lib3MF::ELib3MFException &e) {
|
|
|
+ metaData->AddMetaData(META_NAMESPACE, "format", "1.0.0", "string", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ json optiTrackData = json::array();
|
|
|
+ for (OptiTrackPoint* optiTrackPoint: _optiTrackPoints) {
|
|
|
+ optiTrackData.push_back({
|
|
|
+ {"point", osgVecToStdVec(optiTrackPoint->getTranslation())},
|
|
|
+ {"normal", osgVecToStdVec(optiTrackPoint->getNormal())},
|
|
|
+ {"normalModifier", osgVecToStdVec(optiTrackPoint->getNormalModifier())},
|
|
|
+ {"length", optiTrackPoint->getLength()},
|
|
|
+ {"radius", optiTrackPoint->getRadius()}
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Lib3MF::PMetaData optiTrackPoints = metaData->GetMetaDataByKey(META_NAMESPACE, "optitrack");
|
|
|
+ optiTrackPoints->SetValue(optiTrackData.dump());
|
|
|
+ } catch (Lib3MF::ELib3MFException &e) {
|
|
|
+ metaData->AddMetaData(META_NAMESPACE, "optitrack", optiTrackData.dump(), "string", true);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectStore::loadMetaData() {
|
|
|
+ Lib3MF::PMetaDataGroup metaData = _project->GetMetaDataGroup();
|
|
|
+ try {
|
|
|
+ Lib3MF::PMetaData versionInformation = metaData->GetMetaDataByKey(META_NAMESPACE, "format");
|
|
|
+ } catch (Lib3MF::ELib3MFException &e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Lib3MF::PMetaData optiTrackString;
|
|
|
+ try {
|
|
|
+ optiTrackString = metaData->GetMetaDataByKey(META_NAMESPACE, "optitrack");
|
|
|
+ } catch (Lib3MF::ELib3MFException &e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ auto optiTrackData = json::parse(optiTrackString->GetValue());
|
|
|
+ _optiTrackPoints.clear();
|
|
|
+ for (const auto pointData: optiTrackData) {
|
|
|
+ osg::Vec3f point = osg::Vec3f(pointData["point"][0], pointData["point"][1], pointData["point"][2]);
|
|
|
+ osg::Vec3f normal = osg::Vec3f(pointData["normal"][0], pointData["normal"][1], pointData["normal"][2]);
|
|
|
+ osg::Vec3f normalModifier = osg::Vec3f(pointData["normalModifier"][0], pointData["normalModifier"][1], pointData["normalModifier"][2]);
|
|
|
+ OptiTrackPoint* optiTrackPoint = new OptiTrackPoint(point, normal, normalModifier, static_cast<double>(pointData["length"]), static_cast<double>(pointData["radius"]));
|
|
|
+ _optiTrackPoints.push_back(optiTrackPoint);
|
|
|
+ }
|
|
|
+ render3MFMesh();
|
|
|
+ MainWindow::getInstance()->renderView(Edit);
|
|
|
+ MainWindow::getInstance()->getOsgWidget()->getPointRenderer()->render(MainWindow::getInstance()->getEditWiget()->getSelectedTrackingSystem());
|
|
|
+}
|
|
|
+
|
|
|
+std::vector<float> ProjectStore::osgVecToStdVec(osg::Vec3f input) {
|
|
|
+ std::vector<float> vector;
|
|
|
+ vector.push_back(input.x());
|
|
|
+ vector.push_back(input.y());
|
|
|
+ vector.push_back(input.z());
|
|
|
+ return vector;
|
|
|
+}
|
|
|
|
|
|
+osg::Vec3f ProjectStore::stdVecToOsgVec(std::vector<float> input) {
|
|
|
+ return osg::Vec3f(input[0], input[1], input[2]);
|
|
|
}
|