TrackPointRenderer.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. newShape->setCompensation(point->getCompensation(), point->getNormalCompensation());
  21. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  22. id++;
  23. }
  24. break;
  25. }
  26. case EMFTrack: {
  27. std::vector<EMFTrackPoint*> points = MainWindow::getInstance()->getStore()->getEMFTrackPoints();
  28. int id = 0;
  29. for (EMFTrackPoint* point: points) {
  30. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  31. newShape->setupEMFTrack(point->getEMFTrackSettings());
  32. newShape->setCompensation(point->getCompensation(), point->getNormalCompensation());
  33. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  34. id++;
  35. }
  36. break;
  37. }
  38. case SteamVRTrack: {
  39. std::vector<SteamVRTrackPoint*> points = MainWindow::getInstance()->getStore()->getSteamVRTrackPoints();
  40. int id = 0;
  41. for (SteamVRTrackPoint* point: points) {
  42. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  43. newShape->setupSteamVRTrack(point->getSteamVRTrackSettings());
  44. newShape->setCompensation(point->getCompensation(), point->getNormalCompensation());
  45. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  46. id++;
  47. }
  48. break;
  49. }
  50. case ActionPoints: {
  51. std::vector<ActionPoint*> points = MainWindow::getInstance()->getStore()->getActionPoints();
  52. int id = 0;
  53. for (ActionPoint* point: points) {
  54. PointShape* newShape = addPointShape(static_cast<TrackPoint*>(point), activeTrackingSystem);
  55. newShape->setupActionPoints();
  56. newShape->setCompensation(point->getCompensation(), 0.0f);
  57. commonSetupPointShape(newShape, static_cast<TrackPoint*>(point), id);
  58. id++;
  59. }
  60. break;
  61. }
  62. }
  63. _osgWidget->update();
  64. }
  65. std::vector<PointShape*> TrackPointRenderer::getShapes() {
  66. return _shapes;
  67. }
  68. void TrackPointRenderer::clear() {
  69. for (PointShape* shape: _shapes) {
  70. delete shape;
  71. }
  72. _shapes.clear();
  73. }
  74. PointShape* TrackPointRenderer::addPointShape(TrackPoint* point, ActiveTrackingSystem activeTrackingSystem) {
  75. PointShape* newShape = new PointShape(_renderRoot, activeTrackingSystem, point->getTranslation(), point->getNormal(), point->getNormalModifier(), point->getNormalRotation());
  76. return newShape;
  77. }
  78. void TrackPointRenderer::commonSetupPointShape(PointShape* shape, TrackPoint* point, int id) {
  79. if (id == MainWindow::getInstance()->getEditWiget()->getSelectedPoint()) {
  80. shape->setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 0.2f));
  81. } else {
  82. shape->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 0.2f));
  83. }
  84. shape->rotateToNormalVector(point->getNormal(), point->getNormalRotation());
  85. _shapes.push_back(shape);
  86. }