diff --git a/Examples/BoneShaving/BoneShavingExample.cpp b/Examples/BoneShaving/BoneShavingExample.cpp index 94ad4f0410a72dfb728627b55a142c3471d18821..c17e5050fe3f8857bdbd1e7910f316c8b4e85c43 100644 --- a/Examples/BoneShaving/BoneShavingExample.cpp +++ b/Examples/BoneShaving/BoneShavingExample.cpp @@ -47,9 +47,6 @@ #include "imstkCollisionGraph.h" #include "imstkObjectInteractionFactory.h" -// global variables -const std::string phantomOmni1Name = "Default Device"; - using namespace imstk; /// @@ -67,7 +64,8 @@ main() // Device Server imstkNew<HapticDeviceManager> server; - std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(phantomOmni1Name); + const std::string deviceName = ""; + std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(deviceName); // Create bone scene object // Load the mesh diff --git a/Examples/CameraController/CameraControllerExample.cpp b/Examples/CameraController/CameraControllerExample.cpp index 5cb6ef3b6424a821f5c229d0ebc9bd9ecc889444..d8ca513925e68680dbdb1fb088db621cdbad6c60 100644 --- a/Examples/CameraController/CameraControllerExample.cpp +++ b/Examples/CameraController/CameraControllerExample.cpp @@ -36,8 +36,6 @@ #include "imstkSurfaceMesh.h" #include "imstkVTKViewer.h" -const std::string phantomOmni1Name = "Default Device"; - using namespace imstk; /// @@ -55,7 +53,8 @@ main() // Device Server imstkNew<HapticDeviceManager> server; - std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(phantomOmni1Name); + const std::string deviceName = ""; + std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(deviceName); // Load Mesh auto mesh = MeshIO::read<SurfaceMesh>(iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj"); diff --git a/Examples/ObjectController/ObjectControllerExample.cpp b/Examples/ObjectController/ObjectControllerExample.cpp index 5d17119b8ac7785fe616a4625fdd22139ba7fdd0..188dc66bfb4f34870eba15f533f633c983f73e16 100644 --- a/Examples/ObjectController/ObjectControllerExample.cpp +++ b/Examples/ObjectController/ObjectControllerExample.cpp @@ -34,9 +34,6 @@ #include "imstkSceneObjectController.h" #include "imstkVTKViewer.h" -// global variables -const std::string phantomOmni1Name = "Default Device"; - using namespace imstk; /// @@ -54,7 +51,8 @@ main() // Device Server imstkNew<HapticDeviceManager> server; - std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(phantomOmni1Name); + const std::string deviceName = ""; + std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(deviceName); // Object imstkNew<Cube> geom(Vec3d(0.0, 1.0, 0.0), 2.0); diff --git a/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp b/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp index ed6df35219da121c25c5dd32e838fb06fb7114e3..28b1d41c894d2313508d819c1f53e0dcb87ab812 100644 --- a/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp +++ b/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp @@ -43,9 +43,6 @@ #include "imstkVisualModel.h" #include "imstkVTKViewer.h" -// global variables -const std::string phantomOmni1Name = "Default Device"; - using namespace imstk; std::shared_ptr<imstk::RigidObject> @@ -201,7 +198,8 @@ main() // Device Server imstkNew<HapticDeviceManager> server; - std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(phantomOmni1Name); + const std::string deviceName = ""; + std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(deviceName); // Create a virtual coupling object imstkNew<Sphere> visualGeom(Vec3d(0.0, 0.0, 0.0), 5.0); diff --git a/Examples/VirtualCoupling/VirtualCouplingExample.cpp b/Examples/VirtualCoupling/VirtualCouplingExample.cpp index 7d2253acb84c707cefc6c5211abb8503e9782786..179dc73ca9cb035d05e772249f21ecef5063a0af 100644 --- a/Examples/VirtualCoupling/VirtualCouplingExample.cpp +++ b/Examples/VirtualCoupling/VirtualCouplingExample.cpp @@ -41,9 +41,6 @@ #include "imstkVisualModel.h" #include "imstkVTKViewer.h" -// global variables -const std::string phantomOmni1Name = "Default Device"; - using namespace imstk; /// @@ -72,7 +69,8 @@ main() // Device Server imstkNew<HapticDeviceManager> server; - std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(phantomOmni1Name); + const std::string deviceName = ""; + std::shared_ptr<HapticDeviceClient> client = server->makeDeviceClient(deviceName); // Create a virtual coupling object imstkNew<Sphere> visualGeom(Vec3d(0.0, 0.0, 0.0), 20.0); diff --git a/Source/Devices/imstkHapticDeviceClient.cpp b/Source/Devices/imstkHapticDeviceClient.cpp index beac639ef00c9643ed2429d57fbe4669256eb366..2f1ffa456135c26566883237c15a4c2db762b69d 100644 --- a/Source/Devices/imstkHapticDeviceClient.cpp +++ b/Source/Devices/imstkHapticDeviceClient.cpp @@ -40,18 +40,36 @@ HapticDeviceClient::initialize() while (HD_DEVICE_ERROR(errorFlush = hdGetError())) {} // Initialize the device - m_handle = hdInitDevice(this->getDeviceName().c_str()); + if (m_deviceName == "") + { + m_handle = hdInitDevice(HD_DEFAULT_DEVICE); + } + else + { + m_handle = hdInitDevice(getDeviceName().c_str()); + } // If failed HDErrorInfo error; - LOG_IF(FATAL, HD_DEVICE_ERROR(error = hdGetError())) << "Failed to initialize Phantom Omni " << this->getDeviceName(); + LOG_IF(FATAL, HD_DEVICE_ERROR(error = hdGetError())) << "Failed to initialize Phantom Omni \"" << this->getDeviceName() + "\""; + + // If initialized as default, set the name + if (m_deviceName == "") + { + // Worth noting that in this case the name will not match the actual device name and is + // now only useful for scene level identification, OpenHaptics provides no mechanisms + // for querying device names + hdMakeCurrentDevice(m_handle); + HDstring str = hdGetString(HD_DEVICE_SERIAL_NUMBER); + m_deviceName = "Device_" + std::string(str); + } // Enable forces hdEnable(HD_FORCE_OUTPUT); hdEnable(HD_FORCE_RAMPING); // Success - LOG(INFO) << this->getDeviceName() << " successfully initialized."; + LOG(INFO) << "\"" << this->getDeviceName() << "\" successfully initialized."; } void diff --git a/Source/Devices/imstkHapticDeviceClient.h b/Source/Devices/imstkHapticDeviceClient.h index ed9b11ff57fcc49d9d4e8e6c58eb671e5c702056..35bc72f251ac7c10ee14d403467019f832706329 100644 --- a/Source/Devices/imstkHapticDeviceClient.h +++ b/Source/Devices/imstkHapticDeviceClient.h @@ -52,8 +52,9 @@ public: protected: /// /// \brief Constructor/Destructor, only the DeviceManager can construct + /// \param Device name or use empty string for default device /// - HapticDeviceClient(const std::string& name) : DeviceClient(name, "localhost"), m_handle(HD_INVALID_HANDLE) { } + HapticDeviceClient(std::string name = "") : DeviceClient(name, "localhost"), m_handle(HD_INVALID_HANDLE) { } /// /// \brief Initialize the phantom omni device diff --git a/Source/Devices/imstkHapticDeviceManager.cpp b/Source/Devices/imstkHapticDeviceManager.cpp index 08a45a5ea512b1b0f6c8711976164c3e76513d36..fab91e0b94848c8d4b887816ec34cdcf1257e60c 100644 --- a/Source/Devices/imstkHapticDeviceManager.cpp +++ b/Source/Devices/imstkHapticDeviceManager.cpp @@ -29,7 +29,7 @@ namespace imstk { std::shared_ptr<HapticDeviceClient> -HapticDeviceManager::makeDeviceClient(const std::string& name) +HapticDeviceManager::makeDeviceClient(std::string name) { auto deviceClient = std::shared_ptr<HapticDeviceClient>(new HapticDeviceClient(name)); m_deviceClients.push_back(deviceClient); diff --git a/Source/Devices/imstkHapticDeviceManager.h b/Source/Devices/imstkHapticDeviceManager.h index bc6dda73210389f03eebf80a335ab3059eca4a01..26eeb9c92d5e02a4a6bcb57f8ab31e2489aff20c 100644 --- a/Source/Devices/imstkHapticDeviceManager.h +++ b/Source/Devices/imstkHapticDeviceManager.h @@ -50,8 +50,9 @@ public: /// /// \brief Create a haptic device client and add it to the internal list + /// \param Device name or use empty string for default device /// - std::shared_ptr<HapticDeviceClient> makeDeviceClient(const std::string& name); + std::shared_ptr<HapticDeviceClient> makeDeviceClient(std::string name = ""); /// /// \brief Initialize the client devices and start the scheduler