From 97db2d8d2205ab3c70b706c0f2d8dae92ced8e26 Mon Sep 17 00:00:00 2001 From: Ricardo Ortiz <ricardo.ortiz@kitware.com> Date: Thu, 28 Jan 2016 15:10:51 -0500 Subject: [PATCH] ENH: Add utility functions to the SDK in order to facilitate the creation of device servers and clients. --- Devices/VRPNDeviceServer.cpp | 8 ++++---- Examples/FEMSimulator/main.cpp | 17 +++-------------- SimulationManager/SDK.cpp | 24 ++++++++++++++++++++++++ SimulationManager/SDK.h | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/Devices/VRPNDeviceServer.cpp b/Devices/VRPNDeviceServer.cpp index a8c0d80c0..e7a0bb7c8 100644 --- a/Devices/VRPNDeviceServer.cpp +++ b/Devices/VRPNDeviceServer.cpp @@ -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 " diff --git a/Examples/FEMSimulator/main.cpp b/Examples/FEMSimulator/main.cpp index 6419e25b1..9b93572c9 100644 --- a/Examples/FEMSimulator/main.cpp +++ b/Examples/FEMSimulator/main.cpp @@ -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 diff --git a/SimulationManager/SDK.cpp b/SimulationManager/SDK.cpp index 3f03dd9fd..b7561a5a3 100644 --- a/SimulationManager/SDK.cpp +++ b/SimulationManager/SDK.cpp @@ -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; +} + } diff --git a/SimulationManager/SDK.h b/SimulationManager/SDK.h index 506e17832..c1ee304a6 100644 --- a/SimulationManager/SDK.h +++ b/SimulationManager/SDK.h @@ -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; -- GitLab