Skip to content
Snippets Groups Projects
Commit fc34029b authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

Merge branch 'addDummyClient' into 'master'

Add dummy client

See merge request iMSTK/iMSTK!253
parents d9e125e4 1ea62407
No related branches found
No related tags found
No related merge requests found
###########################################################################
#
# 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(Example-ObjectControllerDummyClient)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
add_executable(${PROJECT_NAME} ObjectControllerDummyClient.cpp)
#-----------------------------------------------------------------------------
# Add shaders
#-----------------------------------------------------------------------------
include(imstkCopyAndCompileShaders)
CopyAndCompileShaders()
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager)
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
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.
=========================================================================*/
#include "imstkSimulationManager.h"
#include "imstkCube.h"
#include "imstkDummyClient.h"
#include "imstkSceneObjectController.h"
using namespace imstk;
///
/// \brief This example demonstrates controlling the object
/// using external device. NOTE: Requires GeoMagic Touch device
///
int main()
{
// SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("ObjectControllerDummyClient");
// Device Client
auto client = std::make_shared<DummyClient>("DummyClient");
// Object
auto geom = std::make_shared<Cube>();
geom->setPosition(0, 1, 0);
geom->setWidth(2);
auto object = std::make_shared<CollidingObject>("VirtualObject");
object->setVisualGeometry(geom);
object->setCollidingGeometry(geom);
scene->addSceneObject(object);
auto trackCtrl = std::make_shared<DeviceTracker>(client);
trackCtrl->setTranslationScaling(0.1);
auto controller = std::make_shared<SceneObjectController>(object, trackCtrl);
scene->addObjectController(controller);
// Supply translation to dummy client frame
auto translateFunc =
[&client](Module* module)
{
Vec3d p = client->getPosition() + Vec3d(1.0e-4, 0, 0);
if (p.x() > 50.)
{
p = Vec3d(0, 0, 0);
}
client->setPosition(p);
};
sdk->getSceneManager(scene)->setPostUpdateCallback(translateFunc);
// Update Camera position
auto cam = scene->getCamera();
cam->setPosition(Vec3d(0, 0, 10));
cam->setFocalPoint(geom->getPosition());
// Light
auto light = std::make_shared<DirectionalLight>("light");
light->setFocalPoint(Vec3d(5, -8, -5));
light->setIntensity(1);
scene->addLight(light);
// Run
sdk->setActiveScene(scene);
sdk->startSimulation(SimulationStatus::RUNNING);
return 0;
}
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
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.
=========================================================================*/
#include <map>
#include "imstkDummyClient.h"
#include "g3log/g3log.hpp"
namespace imstk
{
void
DummyClient::setButton(const unsigned int buttonId, const bool buttonStatus)
{
auto x = m_buttons.find(buttonId);
if (x != m_buttons.end())
{
x->second = buttonStatus;
}
}
} // imstk
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
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.
=========================================================================*/
#ifndef imstkDummyClient_h
#define imstkDummyClient_h
#include "imstkDeviceClient.h"
namespace imstk
{
///
/// \class Dummy client
/// \brief Allows setting the pose of the device from external caller
///
class DummyClient : public DeviceClient
{
public:
///
/// \brief Constructor/Destructor
///
DummyClient(std::string name) : DeviceClient(name, "localhost"){}
virtual ~DummyClient(){}
protected:
///
/// \brief Initialize the phantom omni device
///
void init(const unsigned int numButtons = 0)
{
for (unsigned int i = 0; i < numButtons; ++i)
{
m_buttons[i] = false;
}
};
void run() = delete;
void cleanUp() = delete;
public:
///
/// \brief Set position
///
void setPosition(const Vec3d& pos) { m_position = pos; };
///
/// \brief Set velocity
///
void setVelocity(const Vec3d& vel) { m_velocity = vel; };
///
/// \brief Set orientation
///
void setOrientation(const Quatd& orient) { m_orientation = orient; };
///
/// \brief Set orientation from 4x4 transform
///
void setOrientation(double* transform)
{
m_orientation = (Eigen::Affine3d(Eigen::Matrix4d(transform))).rotation();
};
///
/// \brief Set the button status if it exists
///
void setButton(const unsigned int buttonId, const bool buttonStatus);
};
}
#endif // ifndef imstkDummyClient_h
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment