diff --git a/Devices/VRPNDeviceServer.cpp b/Devices/VRPNDeviceServer.cpp index a8c0d80c0b208c2c5dd38394b9227e2b98fc9d84..e7a0bb7c83a6d09c6628929ba268696db0ebb005 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 6419e25b14706788c08f716a64235da90ebe5fe2..9b93572c9aa31a56fcf30a83fedd6633d2bce39a 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 3f03dd9fd0e4cb785a0105047d56f38ad2157aef..b7561a5a31a3615acbea8e13d3123564b4450754 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 506e178329a3fd922fa82c5dc48cb140a1bcdd8e..c1ee304a6af8d2c2db083d09f927185e39cf3bb7 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;