TrackPointRenderer.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Include own header
  2. #include "TrackPointRenderer.hpp"
  3. // Include modules
  4. #include "MainWindow.hpp"
  5. TrackPointRenderer::TrackPointRenderer(OSGWidget* osgWidget, osg::ref_ptr<osg::Group> renderRoot) {
  6. _osgWidget = osgWidget;
  7. _renderRoot = renderRoot;
  8. }
  9. TrackPointRenderer::~TrackPointRenderer() {
  10. }
  11. void TrackPointRenderer::render(ActiveTrackingSystem activeTrackingSystem) {
  12. clear();
  13. switch(activeTrackingSystem) {
  14. case OptiTrack: {
  15. std::vector<OptiTrackPoint*> points = MainWindow::getInstance()->getStore()->getOptiTrackPoints();
  16. int id = 0;
  17. for (OptiTrackPoint* point: points) {
  18. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  19. newShape->setupOptiTrack(point->getOptiTrackSettings());
  20. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  21. id++;
  22. }
  23. break;
  24. }
  25. case EMFTrack: {
  26. std::vector<EMFTrackPoint*> points = MainWindow::getInstance()->getStore()->getEMFTrackPoints();
  27. int id = 0;
  28. for (EMFTrackPoint* point: points) {
  29. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  30. newShape->setupEMFTrack(point->getEMFTrackSettings());
  31. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  32. id++;
  33. }
  34. break;
  35. }
  36. case SteamVRTrack: {
  37. std::vector<SteamVRTrackPoint*> points = MainWindow::getInstance()->getStore()->getSteamVRTrackPoints();
  38. int id = 0;
  39. for (SteamVRTrackPoint* point: points) {
  40. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  41. newShape->setupSteamVRTrack(point->getSteamVRTrackSettings());
  42. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  43. id++;
  44. }
  45. break;
  46. }
  47. case ActionPoints: {
  48. std::vector<ActionPoint*> points = MainWindow::getInstance()->getStore()->getActionPoints();
  49. int id = 0;
  50. for (ActionPoint* point: points) {
  51. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  52. newShape->setupActionPoints();
  53. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  54. id++;
  55. }
  56. break;
  57. }
  58. }
  59. _osgWidget->update();
  60. }
  61. std::vector<PointShape*> TrackPointRenderer::getShapes() {
  62. return _shapes;
  63. }
  64. void TrackPointRenderer::clear() {
  65. for (PointShape* shape: _shapes) {
  66. delete shape;
  67. }
  68. _shapes.clear();
  69. }
  70. PointShape* TrackPointRenderer::addPointShape(TrackPoint* point, ActiveTrackingSystem activeTrackingSystem) {
  71. PointShape* newShape = new PointShape(_renderRoot, activeTrackingSystem, point->getTranslation(), point->getNormal(), point->getNormalModifier(), point->getNormalRotation());
  72. return newShape;
  73. }
  74. void TrackPointRenderer::commonSetupPointShape(PointShape* shape, TrackPoint* point, int id) {
  75. if (id == MainWindow::getInstance()->getEditWiget()->getSelectedPoint()) {
  76. shape->setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 0.2f));
  77. } else {
  78. shape->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 0.2f));
  79. }
  80. shape->rotateToNormalVector(point->getNormal(), point->getNormalRotation());
  81. _shapes.push_back(shape);
  82. }