Commit 18a45c37 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Add feature to optionally launch the render

parent adfaa5db
Pipeline #110511 failed with stage
......@@ -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;
}
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment