Commit d8e1e96e authored by Alexis Girault's avatar Alexis Girault

ENH: Sandbox example to test imstkModule

Uses a dummy implementation of imstkScene to test
a module execution in multithreading.
parent bcc84950
......@@ -22,4 +22,19 @@
namespace imstk {
void Scene::initModule()
{
std::cout<<std::endl<<m_name<<" : init"<<std::endl;
}
void Scene::cleanUpModule()
{
std::cout<<std::endl<<m_name<<" : cleanUp"<<std::endl;
}
void Scene::runModule()
{
std::cout<<"."<<std::flush;
}
}
......@@ -21,6 +21,8 @@
#ifndef imstkScene_h
#define imstkScene_h
#include <iostream>
#include "imstkModule.h"
namespace imstk {
......@@ -28,10 +30,14 @@ namespace imstk {
class Scene : public Module
{
public:
Scene(std::string name) : Module(name){}
~Scene() = default;
private:
Scene() = default;
protected:
void initModule() override;
void runModule() override;
void cleanUpModule() override;
};
......
......@@ -69,15 +69,15 @@ include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
#--------------------------------------------------------------------------
# Add Source code subdirectory
# Add Source code subdirectories
#--------------------------------------------------------------------------
add_subdirectory(Base/Core)
add_subdirectory(Base/Scene)
......@@ -97,3 +97,8 @@ install(EXPORT iMSTK_TARGETS
COMPONENT Development
DESTINATION ${${PROJECT_NAME}_INSTALL_SHARE_DIR}
)
#--------------------------------------------------------------------------
# Add Examples subdirectories
#--------------------------------------------------------------------------
add_subdirectory(Examples/Sandbox)
###########################################################################
#
# Copyright (c) Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
project(Sandbox)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
add_executable(${PROJECT_NAME} main.cpp)
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME}
Scene
)
#include <cstring>
#include <iostream>
#include <memory>
#include <thread>
#include "imstkScene.h"
int main()
{
std::cout << "****************" << std::endl
<< "Starting Sandbox" << std::endl
<< "****************" << std::endl;
std::shared_ptr<imstk::Scene> scene1 =
std::make_shared<imstk::Scene>("Scene1");
std::thread t1([scene1]{scene1->exec();});
std::this_thread::sleep_for(std::chrono::milliseconds(500));
scene1->pause();
std::this_thread::sleep_for(std::chrono::seconds(2));
scene1->run();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
scene1->pause();
std::this_thread::sleep_for(std::chrono::seconds(2));
scene1->terminate();
t1.join();
return 0;
}
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