Commit 97db2d8d authored by Ricardo Ortiz's avatar Ricardo Ortiz
Browse files

ENH: Add utility functions to the SDK

in order to facilitate the creation of device servers and clients.
parent 8177fc48
......@@ -116,10 +116,10 @@ bool VRPNDeviceServer::addDeviceClient(
// TODO: Add an extra parameter to set the name of the phantom omni.
// This is necessary because vrpn_Phantom only take non-const names.
char * deviceName = const_cast<char*>(newDeviceName.c_str());
vrpnTrackerDevice =
std::make_shared<vrpn_Phantom>(deviceName,
this->connection,
60.0f, "Default PHANToM");
vrpnTrackerDevice = std::make_shared<vrpn_Phantom>(deviceName,
this->connection,
60.0f,
"Default PHANToM");
#else
// TODO: add to logger
std::cerr<< "addDeviceClient error: needs VRPN_USE_PHANTOM_SERVER defined "
......
......@@ -81,20 +81,9 @@ int main(int ac, char** av)
return EXIT_FAILURE;
}
// setup device client
// Set up a controller to control a mesh with an external device
std::string deviceURL = "Phantom@localhost";
// auto client = std::make_shared<imstk::VRPNForceDevice>(deviceURL);
// sdk->addModule(client);
// setup controller
// auto controller = std::make_shared<imstk::ToolCoupler>(client);
// controller->setScalingFactor(20.0);
// sdk->addModule(controller);
// setup server
auto server = std::make_shared<imstk::VRPNDeviceServer>();
// server->addDeviceClient(client);
sdk->addModule(server);
auto controller = sdk->createForceDeviceController(deviceURL);
//-------------------------------------------------------
// Create scene actor 1: fem scene object + fem simulator
......@@ -168,7 +157,7 @@ int main(int ac, char** av)
loliMesh->transform(transform);
loliMesh->updateInitialVertices();
// controller->setMesh(loliCollisionModel->getMesh());
controller->setMesh(loliCollisionModel->getMesh());
//-------------------------------------------------------
// Enable collision between scene actors 1 and 2
......
......@@ -251,4 +251,28 @@ void SDK::addInteraction(std::shared_ptr< CollisionManager > collisionPair,
contactHandling);
}
//---------------------------------------------------------------------------
std::shared_ptr< VRPNDeviceServer > SDK::createDeviceServer()
{
auto server = std::make_shared<imstk::VRPNDeviceServer>();
this->addModule(server);
return server;
}
//---------------------------------------------------------------------------
std::shared_ptr< ToolCoupler > SDK::createForceDeviceController(std::string &deviceURL)
{
auto server = this->createDeviceServer();
auto client = std::make_shared<VRPNForceDevice>(deviceURL);
this->addModule(client);
server->addDeviceClient(client);
auto controller = std::make_shared<ToolCoupler>(client);
this->addModule(controller);
return controller;
}
}
......@@ -41,6 +41,9 @@
#include "Core/ContactHandling.h"
#include "Core/CollisionManager.h"
#include "Core/CollisionDetection.h"
#include "Devices/VRPNDeviceServer.h"
#include "Devices/VRPNForceDevice.h"
#include "VirtualTools/ToolCoupler.h"
namespace imstk {
......@@ -186,6 +189,18 @@ public:
std::shared_ptr<CollisionDetection> collisionDetection,
std::shared_ptr<ContactHandling> contactHandling);
///
/// \brief Utility function to create a device server
///
std::shared_ptr<VRPNDeviceServer> createDeviceServer();
///
/// \brief Utility function to create a device client, server and controller
///
/// \param deviceURL Client name to make the connection
///
std::shared_ptr<ToolCoupler> createForceDeviceController(std::string &deviceURL);
private:
SDK() = default;
......
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