diff --git a/CMake/FindLibusb1.cmake b/CMake/FindLibusb1.cmake index a08709e1ce2c477b5ed4bb685ba00923b6f1f33d..e848898fa6dc67621dea2c44d6cd5ae30cb411c1 100644 --- a/CMake/FindLibusb1.cmake +++ b/CMake/FindLibusb1.cmake @@ -75,10 +75,18 @@ find_path(LIBUSB_INCLUDE_DIR libusb-1.0 ) -# In windows find_* cant find the paths when a digit is included in the name +<<<<<<< HEAD set(LIBUSB1_LIBRARY ${LIBUSB_LIBRARY}) set(LIBUSB1_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR}) +======= +<<<<<<< HEAD +set(LIBUSB1_LIBRARY E:/SimMedTK/libusb-1.0.20/MS64/static/libusb-1.0.lib) +>>>>>>> Camera scope tip bending implementation. +======= + set(LIBUSB1_LIBRARY E:/SimMedTK/libusb-1.0.20/MS64/static/libusb-1.0.lib) + +>>>>>>> Camera scope tip bending works! include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libusb1 REQUIRED_VARS diff --git a/Core/Module.cpp b/Core/Module.cpp index 563fb5a7ec71d6dc137dfd5a5d7c716d0fde66c2..4f85a5d269f1cc26d973860df29aae062b08d04f 100644 --- a/Core/Module.cpp +++ b/Core/Module.cpp @@ -59,7 +59,7 @@ void Module::waitTermination() { while ( 1 ) { - std::cout << this->name << std::endl; + //std::cout << this->name << std::endl; if ( this->terminationCompleted == true ) { break; diff --git a/Examples/LaparoscopicCamera/main.cpp b/Examples/LaparoscopicCamera/main.cpp index 3e50f24658e4f7a100cd9befa03a71f0e02e9478..9933ca9c9f166f4094cf9401d8e0c3b40692d8be 100644 --- a/Examples/LaparoscopicCamera/main.cpp +++ b/Examples/LaparoscopicCamera/main.cpp @@ -80,7 +80,8 @@ bool createCameraNavigationScene(std::shared_ptr<SDK> sdk, char* fileName) targetModel->getMesh()->translate(Eigen::Translation3d(0, 0, -radius)); - Eigen::Quaterniond q(cos(i*22.0 / 42), 0, sin(i*22.0 / 42), 0); + Eigen::Quaterniond q(cos(i*22.0/42), 0, sin(i*22.0/42), 0); + q.normalize(); targetModel->getMesh()->rotate(q); } return true; @@ -112,7 +113,7 @@ int main(int ac, char** av) auto planeRendDetail = std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES); - Color grey(0.32, 0.32, 0.32, 1.); + Color grey(0.32, 0.32, 0.32, 1.0); planeRendDetail->setAmbientColor(grey); planeRendDetail->setDiffuseColor(grey); @@ -186,7 +187,8 @@ int main(int ac, char** av) camClient->setDeviceURL(input); } auto camController = std::make_shared<LaparoscopicCameraCoupler>(camClient); - camController->setScalingFactor(50.0); + camController->setScalingFactor(40.0); + viewer->init(); // viewer should be initialized to be able to retrieve the camera diff --git a/VTKRendering/VTKViewer.cpp b/VTKRendering/VTKViewer.cpp index 5eb10280b356065c93bb24cd82240646e6f0e4ff..95ef42bb07bc62559355fadf53e0ee42d26f9e44 100644 --- a/VTKRendering/VTKViewer.cpp +++ b/VTKRendering/VTKViewer.cpp @@ -225,7 +225,6 @@ public: if (delegate) { renderer->AddActor(delegate->getActor()); - } } } diff --git a/VirtualTools/LaparoscopicCameraCoupler.cpp b/VirtualTools/LaparoscopicCameraCoupler.cpp index 13662c1194b0da80e9f282f97d073c2b6e8c00d3..9ab71c91e168d2145c853afc778b4691444b9b5a 100644 --- a/VirtualTools/LaparoscopicCameraCoupler.cpp +++ b/VirtualTools/LaparoscopicCameraCoupler.cpp @@ -32,13 +32,17 @@ LaparoscopicCameraCoupler::LaparoscopicCameraCoupler( std::shared_ptr< DeviceInterface > inputDevice, - std::shared_ptr< vtkCamera > camera) + vtkCamera* camera) { this->inputDevice = inputDevice; this->poolDelay = std::chrono::milliseconds(100); this->initialTransform.setIdentity(); this->name = "LaparoscopicCameraCoupler"; + initializeCameraScopeConfiguration(); + + this->camera = camera; + cameraPosOrientData = std::make_shared<cameraConfigurationData>(); } @@ -50,6 +54,8 @@ LaparoscopicCameraCoupler::LaparoscopicCameraCoupler( this->initialTransform.Identity(); this->name = "LaparoscopicCameraCoupler"; + initializeCameraScopeConfiguration(); + cameraPosOrientData = std::make_shared<cameraConfigurationData>(); } @@ -57,6 +63,15 @@ LaparoscopicCameraCoupler::~LaparoscopicCameraCoupler() { } +void LaparoscopicCameraCoupler::initializeCameraScopeConfiguration() +{ + this->bendingRadius = 1.0; // default bending radius + angleY = 0.0; + maxAngleY = 11.0 / 7; //+ 90 deg + minAngleY = -11.0 / 7; //- 90 deg + deltaAngleY = (4.0 / 360)*(22.0 / 7);// 2 deg +} + void LaparoscopicCameraCoupler::setInputDevice(std::shared_ptr<DeviceInterface> newDevice) { this->inputDevice = newDevice; @@ -108,14 +123,13 @@ void LaparoscopicCameraCoupler::setOrientation( this->orientation = newOrientation; } -bool LaparoscopicCameraCoupler::init() +void LaparoscopicCameraCoupler::init() { this->orientation.setIdentity(); this->position.setZero(); // Open communication for the device this->inputDevice->openDevice(); - return true; } void LaparoscopicCameraCoupler::beginFrame() @@ -135,14 +149,15 @@ void LaparoscopicCameraCoupler::exec() while(!this->terminateExecution) { - if(!this->updateCamera()) + if (!this->updateCamera()) { this->terminate(); } std::this_thread::sleep_for(poolDelay); } - this->terminationCompleted = true; this->inputDevice->closeDevice(); + + this->terminate(); } bool LaparoscopicCameraCoupler::updateCamera() @@ -153,13 +168,32 @@ bool LaparoscopicCameraCoupler::updateCamera() return false; } - core::Quaterniond newRot = inputDevice->getOrientation(); - core::Vec3d newPos = inputDevice->getPosition() * this->scalingFactor; + if (this->inputDevice->getButton(0) && angleY<maxAngleY) + { + angleY += deltaAngleY; + //std::cout << "button 0 pressed. angle:" << angleY << std::endl; + } + else if (this->inputDevice->getButton(1) && angleY>minAngleY) + { + angleY -= deltaAngleY; + //std::cout << "button 1 pressed. angle:" << angleY << std::endl; + } + + core::Quaterniond newDeviceRot = inputDevice->getOrientation(); + core::Vec3d newDevicePos = inputDevice->getPosition()*this->scalingFactor; + + core::Vec3d bendingOffset = core::Vec3d(0, 0, this->bendingRadius); + + core::Quaterniond bendingRot(cos(angleY/2), 0, sin(angleY/2), 0); + bendingRot.normalize(); // update the camera position, focus and up vector data - cameraPosOrientData->position = inputDevice->getPosition() * this->scalingFactor; - cameraPosOrientData->focus = newRot._transformVector(core::Vec3d(0, 0, -200)); - cameraPosOrientData->upVector = newRot._transformVector(core::Vec3d(0, 1, 0)); + cameraPosOrientData->focus = newDeviceRot*bendingRot*core::Vec3d(0, 0, -200.0); + cameraPosOrientData->upVector = newDeviceRot*bendingRot*core::Vec3d(0, 1.0, 0); + + cameraPosOrientData->position = + newDeviceRot*(bendingOffset - bendingRot*bendingOffset) + + newDevicePos; return true; } @@ -188,4 +222,15 @@ const core::Vec3d & LaparoscopicCameraCoupler::getOffsetPosition() const std::shared_ptr<cameraConfigurationData> LaparoscopicCameraCoupler::getCameraData() { return cameraPosOrientData; -}; \ No newline at end of file +}; + + +double LaparoscopicCameraCoupler::getBendingRadius() const +{ + return bendingRadius; +} + +void LaparoscopicCameraCoupler::setBendingRadius(const double val) +{ + bendingRadius = val; +} \ No newline at end of file diff --git a/VirtualTools/LaparoscopicCameraCoupler.h b/VirtualTools/LaparoscopicCameraCoupler.h index 1c4e25a499cc016edc4ce354f306553d07aedee9..1f2bf275e0671f72f107d3e11a661053e48880f4 100644 --- a/VirtualTools/LaparoscopicCameraCoupler.h +++ b/VirtualTools/LaparoscopicCameraCoupler.h @@ -59,8 +59,9 @@ public: /// LaparoscopicCameraCoupler() = default; - LaparoscopicCameraCoupler(std::shared_ptr<DeviceInterface> inputDevice, - std::shared_ptr<vtkCamera> camera); + LaparoscopicCameraCoupler( + std::shared_ptr<DeviceInterface> inputDevice, + vtkCamera* camera); LaparoscopicCameraCoupler(std::shared_ptr<DeviceInterface> inputDevice); @@ -69,6 +70,11 @@ public: /// ~LaparoscopicCameraCoupler(); + /// + /// \brief Initialize the camera scope configuration + /// + void initializeCameraScopeConfiguration(); + /// /// \brief Set the input device for this tool /// \param newDevice A pointer to an allocated device @@ -168,11 +174,17 @@ public: /// bool updateCamera(); - /// + /// /// \brief Returns the pointer to the camera data that is updated by this controller /// std::shared_ptr<cameraConfigurationData> getCameraData(); + /// + /// \brief Getter and setter for the bending radius of the tip of the scope + /// + double getBendingRadius() const; + void setBendingRadius(const double val); + /// /// \brief Module overrides /// @@ -202,6 +214,12 @@ private: vtkCamera* camera; //!< Pointer to rendering camera std::shared_ptr<DeviceInterface> inputDevice; //!< Pointer to input device + double bendingRadius;//!< bending radius of the tip of the scope + double angleY; + double maxAngleY; + double minAngleY; + double deltaAngleY; + std::shared_ptr<cameraConfigurationData> cameraPosOrientData;//!< camera config data };