Commit fbc48bae authored by Alexis Girault's avatar Alexis Girault

ENH: simplify TrackingController constructor

- Get rid of scaling in constructor (too many parameters,
why choose scaling and not others? Use setTranslationScaling
instead)

- No more default nullptr value for deviceClient in controller
constructor
parent 97fc549f
......@@ -106,15 +106,18 @@ Camera::getController() const
return m_cameraController;
}
void
Camera::setupController(std::shared_ptr<DeviceClient> deviceClient, double scaling)
std::shared_ptr<CameraController>
Camera::setupController(std::shared_ptr<DeviceClient> deviceClient)
{
if(m_cameraController == nullptr)
{
m_cameraController = std::make_shared<CameraController>("Camera controller", *this);
m_cameraController = std::make_shared<CameraController>(*this, deviceClient);
}
m_cameraController->setDeviceClient(deviceClient);
m_cameraController->setTranslationScaling(scaling);
else
{
m_cameraController->setDeviceClient(deviceClient);
}
return m_cameraController;
}
} // imstk
\ No newline at end of file
} // imstk
......@@ -111,7 +111,7 @@ public:
///
/// \brief
///
void setupController(std::shared_ptr<DeviceClient> deviceClient, double scaling = 1.0);
std::shared_ptr<CameraController> setupController(std::shared_ptr<DeviceClient> deviceClient);
protected:
std::shared_ptr<CameraController> m_cameraController; ///>
......@@ -124,4 +124,4 @@ protected:
} // imstk
#endif // ifndef imstkCamera_h
\ No newline at end of file
#endif // ifndef imstkCamera_h
......@@ -42,9 +42,9 @@ public:
///
/// \brief
///
CameraController(std::string name, Camera& camera,
std::shared_ptr<DeviceClient> deviceClient = nullptr) :
Module(name),
CameraController(Camera& camera,
std::shared_ptr<DeviceClient> deviceClient) :
Module("Camera controller"),
m_camera(camera),
TrackingController(deviceClient)
{}
......
......@@ -94,9 +94,8 @@ protected:
///
/// \brief Constructor
///
TrackingController(std::shared_ptr<DeviceClient> deviceClient = nullptr, double scaling = 1.0) :
m_deviceClient(deviceClient),
m_scaling(scaling)
TrackingController(std::shared_ptr<DeviceClient> deviceClient) :
m_deviceClient(deviceClient)
{}
std::shared_ptr<DeviceClient> m_deviceClient; ///< Reports device tracking information
......
......@@ -43,10 +43,9 @@ public:
/// \brief Constructor
///
VirtualCouplingObject(std::string name,
std::shared_ptr<DeviceClient> deviceClient = nullptr,
double scaling = 1.0) :
std::shared_ptr<DeviceClient> deviceClient) :
CollidingObject(name),
TrackingController(deviceClient, scaling)
TrackingController(deviceClient)
{
m_type = Type::VirtualCoupling;
}
......
......@@ -42,11 +42,11 @@ public:
/// \brief Constructor
///
VirtualCouplingPBDObject(std::string name,
std::shared_ptr<DeviceClient> deviceClient = nullptr,
double scaling = 1.0) :
TrackingController(deviceClient, scaling), PbdRigidObject(name)
{
m_type = Type::VirtualCoupling;
std::shared_ptr<DeviceClient> deviceClient) :
TrackingController(deviceClient),
PbdRigidObject(name)
{
m_type = Type::VirtualCoupling;
}
///
......
......@@ -353,7 +353,8 @@ void testPenaltyRigidCollision()
auto sphere0Geom = std::make_shared<Sphere>();
sphere0Geom->scale(0.5);
sphere0Geom->translate(Vec3d(1, 0.5, 0));
auto sphere0Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere0", client0, 40);
auto sphere0Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere0", client0);
sphere0Obj->setTranslationScaling(40);
sphere0Obj->setVisualGeometry(sphere0Geom);
sphere0Obj->setCollidingGeometry(sphere0Geom);
scene->addSceneObject(sphere0Obj);
......@@ -362,7 +363,8 @@ void testPenaltyRigidCollision()
auto sphere1Geom = std::make_shared<Sphere>();
sphere1Geom->scale(0.5);
sphere1Geom->translate(Vec3d(-1, 0.5, 0));
auto sphere1Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere1", client1, 40);
auto sphere1Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere1", client1);
sphere1Obj->setTranslationScaling(40);
sphere1Obj->setVisualGeometry(sphere1Geom);
sphere1Obj->setCollidingGeometry(sphere1Geom);
scene->addSceneObject(sphere1Obj);
......@@ -422,7 +424,8 @@ void testTwoFalcons()
auto sphere0Geom = std::make_shared<imstk::Sphere>();
sphere0Geom->setPosition(imstk::Vec3d(16, 4.5, 0));
sphere0Geom->scale(1);
auto sphere0Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere0", falcon0, 30);
auto sphere0Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere0", falcon0);
sphere0Obj->setTranslationScaling(30);
sphere0Obj->setVisualGeometry(sphere0Geom);
sphere0Obj->setCollidingGeometry(sphere0Geom);
scene->addSceneObject(sphere0Obj);
......@@ -431,7 +434,8 @@ void testTwoFalcons()
auto sphere1Geom = std::make_shared<imstk::Sphere>();
sphere1Geom->setPosition(imstk::Vec3d(-16, 4.5, 0));
sphere1Geom->scale(1);
auto sphere1Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere1", falcon1, 30);
auto sphere1Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere1", falcon1);
sphere1Obj->setTranslationScaling(30);
sphere1Obj->setVisualGeometry(sphere1Geom);
sphere1Obj->setCollidingGeometry(sphere1Geom);
scene->addSceneObject(sphere1Obj);
......@@ -440,9 +444,9 @@ void testTwoFalcons()
auto cam = scene->getCamera();
cam->setPosition(imstk::Vec3d(0, 18, 20));
cam->setFocalPoint(imstk::UP_VECTOR * 18);
cam->setupController(hdk);
cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY |
imstk::CameraController::InvertFlag::rotZ);
auto camController = cam->setupController(hdk);
camController->setInversionFlags(imstk::CameraController::InvertFlag::rotY |
imstk::CameraController::InvertFlag::rotZ);
// Run
sdk->setCurrentScene("FalconsTestScene");
......@@ -477,7 +481,8 @@ void testTwoOmnis(){
auto sphere0Geom = std::make_shared<imstk::Sphere>();
sphere0Geom->setPosition(imstk::Vec3d(2, 2.5, 0));
sphere0Geom->scale(1);
auto sphere0Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere0", client0, 0.05);
auto sphere0Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere0", client0);
sphere0Obj->setTranslationScaling(0.05);
sphere0Obj->setVisualGeometry(sphere0Geom);
sphere0Obj->setCollidingGeometry(sphere0Geom);
scene->addSceneObject(sphere0Obj);
......@@ -486,7 +491,8 @@ void testTwoOmnis(){
auto sphere1Geom = std::make_shared<imstk::Sphere>();
sphere1Geom->setPosition(imstk::Vec3d(-2, 2.5, 0));
sphere1Geom->scale(1);
auto sphere1Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere1", client1, 0.05);
auto sphere1Obj = std::make_shared<imstk::VirtualCouplingObject>("Sphere1", client1);
sphere1Obj->setTranslationScaling(0.05);
sphere1Obj->setVisualGeometry(sphere1Geom);
sphere1Obj->setCollidingGeometry(sphere1Geom);
scene->addSceneObject(sphere1Obj);
......@@ -521,7 +527,8 @@ void testObjectController()
auto geom = std::make_shared<imstk::Cube>();
geom->setPosition(imstk::UP_VECTOR);
geom->scale(2);
auto object = std::make_shared<imstk::VirtualCouplingObject>("VirtualObject", client, 0.1);
auto object = std::make_shared<imstk::VirtualCouplingObject>("VirtualObject", client);
object->setTranslationScaling(0.1);
object->setVisualGeometry(geom);
object->setCollidingGeometry(geom);
scene->addSceneObject(object);
......@@ -564,10 +571,11 @@ void testCameraController()
cam->setPosition(imstk::Vec3d(0, 0, 10));
// Set camera controller
cam->setupController(client, 100);
//LOG(INFO) << cam->getController()->getTranslationOffset(); // should be the same than initial cam position
cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY |
imstk::CameraController::InvertFlag::rotZ);
auto camController = cam->setupController(client);
camController->setTranslationScaling(100);
//LOG(INFO) << camController->getTranslationOffset(); // should be the same than initial cam position
camController->setInversionFlags(imstk::CameraController::InvertFlag::rotY |
imstk::CameraController::InvertFlag::rotZ);
// Run
sdk->setCurrentScene("SceneTestDevice");
......
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