diff --git a/Base/SimulationManager/imstkVTKInteractorStyle.cpp b/Base/SimulationManager/imstkVTKInteractorStyle.cpp index 2fb78b1c8c368604d3b998de37ddcd91d8e1b7fe..8991648411a8543cfe69f93f6c7d8e76b54188bb 100644 --- a/Base/SimulationManager/imstkVTKInteractorStyle.cpp +++ b/Base/SimulationManager/imstkVTKInteractorStyle.cpp @@ -46,7 +46,6 @@ VTKInteractorStyle::VTKInteractorStyle() m_fpsActor = vtkTextActor::New(); m_fpsActor->GetTextProperty()->SetFontSize(60); m_fpsActor->SetVisibility(m_displayFps); - m_screenCapturer = std::make_shared<VTKScreenCaptureUtility>(this->Interactor->GetRenderWindow()); } VTKInteractorStyle::~VTKInteractorStyle() diff --git a/Base/SimulationManager/imstkVTKInteractorStyle.h b/Base/SimulationManager/imstkVTKInteractorStyle.h index aea766838546a68a0892029992547e1f6607e718..2a591eaa3a329521a5acc90e93ceb0baa21d4e03 100644 --- a/Base/SimulationManager/imstkVTKInteractorStyle.h +++ b/Base/SimulationManager/imstkVTKInteractorStyle.h @@ -27,7 +27,6 @@ #include <unordered_map> #include <functional> -#include "imstkVTKScreenCaptureUtility.h" #include "vtkInteractorStyleTrackballCamera.h" class vtkTextActor; @@ -138,7 +137,6 @@ private: VTKEventHandlerFunction m_onTimerFunction; SimulationManager* m_simManager; ///> SimulationManager owning the current simulation being interacted with - std::shared_ptr<VTKScreenCaptureUtility> m_screenCapturer; ///> Screen shot utility double m_targetMS; ///> expected time between each render frame (in ms) std::chrono::high_resolution_clock::time_point m_pre; ///> time point pre-rendering std::chrono::high_resolution_clock::time_point m_post; ///> time point post-rendering diff --git a/Base/SimulationManager/imstkVTKViewer.cpp b/Base/SimulationManager/imstkVTKViewer.cpp index 83323a6a7d2e145ea64e2d54f9c9437b1e350ddf..bbc01f343de68621b0920d7353de37b4813709ad 100644 --- a/Base/SimulationManager/imstkVTKViewer.cpp +++ b/Base/SimulationManager/imstkVTKViewer.cpp @@ -249,22 +249,10 @@ VTKViewer::setOnTimerFunction(VTKEventHandlerFunction func) m_interactorStyle->m_onTimerFunction = func; } -void -VTKViewer::setScreenCapturePrefix(const std::string newPrefix) -{ - m_interactorStyle->m_screenCapturer->setScreenShotPrefix(newPrefix); -} - -void -VTKViewer::captureScreen() const -{ - m_interactorStyle->m_screenCapturer->saveScreenShot(); -} - -void -VTKViewer::resetScreenShotNumber() const +std::shared_ptr<VTKScreenCaptureUtility> +VTKViewer::getScreenCaptureUtility() const { - m_interactorStyle->m_screenCapturer->resetScreenShotNumber(); + return m_screenCapturer; } } // imstk diff --git a/Base/SimulationManager/imstkVTKViewer.h b/Base/SimulationManager/imstkVTKViewer.h index 6b258aac11fcf7ca43883f1adb2f5698a626078f..1e66c8290d566c30f5fc4a82edaeaa438aa158df 100644 --- a/Base/SimulationManager/imstkVTKViewer.h +++ b/Base/SimulationManager/imstkVTKViewer.h @@ -28,6 +28,7 @@ #include "imstkScene.h" #include "imstkVTKRenderer.h" #include "imstkVTKInteractorStyle.h" +#include "imstkVTKScreenCaptureUtility.h" #include "vtkSmartPointer.h" #include "vtkRenderWindow.h" @@ -58,6 +59,7 @@ public: m_vtkRenderWindow->SetInteractor(m_vtkRenderWindow->MakeRenderWindowInteractor()); m_vtkRenderWindow->GetInteractor()->SetInteractorStyle( m_interactorStyle ); m_vtkRenderWindow->SetSize(1000,800); + m_screenCapturer = std::make_shared<VTKScreenCaptureUtility>(m_vtkRenderWindow); } /// @@ -137,28 +139,19 @@ public: // Set custom behaviour to be run on every frame. // The return of the function will not have any effect. void setOnTimerFunction(VTKEventHandlerFunction func); - - /// - /// \brief set the screen capture prefix - /// - void setScreenCapturePrefix(const std::string newPrefix); /// - /// \brief Call capture screen + /// \brief access screen shot utility /// - void captureScreen() const; + std::shared_ptr<VTKScreenCaptureUtility> getScreenCaptureUtility() const; - /// - ///\brief reset the screen capture count - /// - void resetScreenShotNumber() const; - protected: vtkSmartPointer<vtkRenderWindow> m_vtkRenderWindow = vtkSmartPointer<vtkRenderWindow>::New(); vtkSmartPointer<VTKInteractorStyle> m_interactorStyle = vtkSmartPointer<VTKInteractorStyle>::New(); std::shared_ptr<Scene> m_currentScene; std::unordered_map<std::shared_ptr<Scene>, std::shared_ptr<VTKRenderer>> m_rendererMap; + std::shared_ptr<VTKScreenCaptureUtility> m_screenCapturer; ///> Screen shot utility bool m_running = false; }; diff --git a/Examples/Sandbox/main.cpp b/Examples/Sandbox/main.cpp index a6eaf79b8ff654bf6920a676e3ab50c7fc99158c..a9bbdc442b83fe522fdde9869d67d2916758b4be 100644 --- a/Examples/Sandbox/main.cpp +++ b/Examples/Sandbox/main.cpp @@ -97,6 +97,7 @@ void testPbdCollision(); void testLineMesh(); void testMshAndVegaIO(); void testLapToolController(); +void testScreenShotUtility(); int main() { @@ -111,6 +112,7 @@ int main() //testVTKTexture(); //testMultiObjectWithTextures(); //testViewer(); + testScreenShotUtility(); /*------------------ @@ -2136,3 +2138,70 @@ void testLineMesh() sdk->startSimulation(true); #endif } + +void testScreenShotUtility() +{ + // SDK and Scene + auto sdk = std::make_shared<imstk::SimulationManager>(); + auto sceneTest = sdk->createNewScene("SceneTest"); + + // Plane + auto planeGeom = std::make_shared<imstk::Plane>(); + planeGeom->scale(10); + auto planeObj = std::make_shared<imstk::VisualObject>("VisualPlane"); + planeObj->setVisualGeometry(planeGeom); + + // Cube + auto cubeGeom = std::make_shared<imstk::Cube>(); + cubeGeom->scale(0.5); + cubeGeom->rotate(imstk::UP_VECTOR, imstk::PI_4); + cubeGeom->rotate(imstk::RIGHT_VECTOR, imstk::PI_4); + cubeGeom->translate(1.0, -1.0, 0.5); + auto cubeObj = std::make_shared<imstk::VisualObject>("VisualCube"); + cubeObj->setVisualGeometry(cubeGeom); + + // Sphere + auto sphereGeom = std::make_shared<imstk::Sphere>(); + sphereGeom->scale(0.3); + sphereGeom->translate(0, 2, 0); + auto sphereObj = std::make_shared<imstk::VisualObject>("VisualSphere"); + sphereObj->setVisualGeometry(sphereGeom); + + // Light (white) + auto whiteLight = std::make_shared<imstk::Light>("whiteLight"); + whiteLight->setPosition(imstk::Vec3d(5, 8, 5)); + whiteLight->setPositional(); + + // Light (red) + auto colorLight = std::make_shared<imstk::Light>("colorLight"); + colorLight->setPosition(imstk::Vec3d(4, -3, 1)); + colorLight->setFocalPoint(imstk::Vec3d(0, 0, 0)); + colorLight->setColor(imstk::Color::Red); + colorLight->setPositional(); + colorLight->setSpotAngle(15); + + // Add in scene + sceneTest->addSceneObject(planeObj); + sceneTest->addSceneObject(cubeObj); + sceneTest->addSceneObject(sphereObj); + sceneTest->addLight(whiteLight); + sceneTest->addLight(colorLight); + + // Update Camera + auto cam1 = sceneTest->getCamera(); + cam1->setPosition(imstk::Vec3d(-5.5, 2.5, 32)); + cam1->setFocalPoint(imstk::Vec3d(1, 1, 0)); + + // Set up for screen shot + sdk->getViewer()->getScreenCaptureUtility()->setScreenShotPrefix(DATA_ROOT_PATH"/screenShot_"); + // Create a call back on key press of 'b' to take the screen shot + sdk->getViewer()->setOnCharFunction('b', [&](VTKInteractorStyle* c) -> bool + { + sdk->getViewer()->getScreenCaptureUtility()->saveScreenShot(); + return false; + }); + + // Run + sdk->setCurrentScene(sceneTest); + sdk->startSimulation(true); +} \ No newline at end of file