diff --git a/Examples/PBDCloth/pbdClothExample.cpp b/Examples/PBDCloth/pbdClothExample.cpp index ca6f0818b9ae7ea857371f30f9b8843e6f3d9a0b..9ff4fe9ae84eafdd1b806db29d1b2de0f14b9f5a 100644 --- a/Examples/PBDCloth/pbdClothExample.cpp +++ b/Examples/PBDCloth/pbdClothExample.cpp @@ -26,13 +26,15 @@ using namespace imstk; +const bool runSimWithoutRendering = false; + /// /// \brief This example demonstrates the cloth simulation /// using Position based dynamics /// int main() { - auto sdk = std::make_shared<SimulationManager>(); + auto sdk = std::make_shared<SimulationManager>(runSimWithoutRendering); auto scene = sdk->createNewScene("PBDCloth"); // a. Construct a sample triangular mesh @@ -127,7 +129,15 @@ int main() // Start sdk->setActiveScene(scene); - sdk->startSimulation(SimulationStatus::PAUSED); + sdk->startSimulation(SimulationStatus::RUNNING); + + // Perform an infinite loop if there is no rendering enabled + if (runSimWithoutRendering) + { + LOG(INFO) << "simulation is starting. PRESS any key to exit"; + while (sdk->getStatus() == SimulationStatus::RUNNING && !getchar()) {} + sdk->endSimulation(); + } return 0; } diff --git a/Source/SimulationManager/imstkSimulationManager.cpp b/Source/SimulationManager/imstkSimulationManager.cpp index 95bc0b29fde026ab14480ada6fc877830b51029b..46a0df0e5a4475ede6aed82c3b4dd4fdf44f5059 100644 --- a/Source/SimulationManager/imstkSimulationManager.cpp +++ b/Source/SimulationManager/imstkSimulationManager.cpp @@ -27,28 +27,33 @@ namespace imstk { -SimulationManager::SimulationManager(bool enableVR) +SimulationManager::SimulationManager(const bool disableRendering, const bool enableVR) { // Init g3logger m_logUtil->createLogger("simulation", "./"); + if (!disableRendering) + { #ifdef iMSTK_USE_Vulkan - m_viewer = std::make_shared<VulkanViewer>(this); + m_viewer = std::make_shared<VulkanViewer>(this); #else + #ifdef iMSTK_ENABLE_VR - m_viewer = std::make_shared<VTKViewer>(this, enableVR); + m_viewer = std::make_shared<VTKViewer>(this, enableVR); #else - if (enableVR) - { - LOG(FATAL) << "Can not run VR simulation without iMSTK_ENABLE_VR"; - } - m_viewer = std::make_shared<VTKViewer>(this, false); + + if (enableVR) + { + LOG(FATAL) << "Can not run VR simulation without iMSTK_ENABLE_VR"; + } + m_viewer = std::make_shared<VTKViewer>(this, false); #endif #endif + } } -const -SimulationStatus& SimulationManager::getStatus() const +const SimulationStatus& +SimulationManager::getStatus() const { return m_status; } @@ -250,28 +255,36 @@ SimulationManager::setActiveScene(const std::string& newSceneName, return; } - // Update viewer scene - m_viewer->setActiveScene(newScene); - - // If not yet rendering: update current scene and return - if(!m_viewer->isRendering()) + if (m_viewer) { - m_activeSceneName = newSceneName; - return; - } + // Update viewer scene + m_viewer->setActiveScene(newScene); + // If not yet rendering: update current scene and return + if (!m_viewer->isRendering()) + { + m_activeSceneName = newSceneName; + return; + } + } // If rendering and simulation not active: // render scene in debug, update current scene, and return if (m_status == SimulationStatus::INACTIVE) { - m_viewer->setRenderingMode(Renderer::Mode::DEBUG); + if (m_viewer) + { + m_viewer->setRenderingMode(Renderer::Mode::DEBUG); + } m_activeSceneName = newSceneName; return; } - // If rendering and simulation active: - // render scene in simulation mode, and update simulation - m_viewer->setRenderingMode(Renderer::Mode::SIMULATION); + if (m_viewer) + { + // If rendering and simulation active: + // render scene in simulation mode, and update simulation + m_viewer->setRenderingMode(Renderer::Mode::SIMULATION); + } // Stop/Pause running scene auto oldSceneManager = m_sceneManagerMap.at(m_activeSceneName); @@ -376,8 +389,11 @@ SimulationManager::startSimulation(const SimulationStatus simStatus /*= Simulati this->launchSimulation(); } - // start the viewer - this->startViewer(renderMode); + if (m_viewer) + { + // start the viewer + this->startViewer(renderMode); + } } void @@ -495,8 +511,11 @@ SimulationManager::endSimulation() LOG(INFO) << "Ending simulation"; } - // Update Renderer - m_viewer->setRenderingMode(Renderer::Mode::DEBUG); + if (m_viewer) + { + // Update Renderer + m_viewer->setRenderingMode(Renderer::Mode::DEBUG); + } // End modules for(const auto& pair : m_modulesMap) diff --git a/Source/SimulationManager/imstkSimulationManager.h b/Source/SimulationManager/imstkSimulationManager.h index 1a7eee3ec220be7b633f292a3f3c7dfeeb164a71..226a5334c5574f1d4d36adb4c34a8a352e0c7777 100644 --- a/Source/SimulationManager/imstkSimulationManager.h +++ b/Source/SimulationManager/imstkSimulationManager.h @@ -54,7 +54,7 @@ public: /// /// \brief Constructor /// - SimulationManager(bool enableVR = false); + SimulationManager(const bool disableRendering = false, const bool enableVR = false); /// /// \brief Default destructor @@ -201,7 +201,7 @@ private: std::unordered_map<std::string, std::thread> m_threadMap; - std::shared_ptr<Viewer> m_viewer; + std::shared_ptr<Viewer> m_viewer = nullptr; std::shared_ptr<LogUtility> m_logUtil = std::make_shared<LogUtility>(); }; } // imstk