diff --git a/Modules/IGT/TrackingDevices/mitkClaronInterface.cpp b/Modules/IGT/TrackingDevices/mitkClaronInterface.cpp index 3052377ee4..992fb62f42 100644 --- a/Modules/IGT/TrackingDevices/mitkClaronInterface.cpp +++ b/Modules/IGT/TrackingDevices/mitkClaronInterface.cpp @@ -1,291 +1,291 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include mitk::ClaronInterface::ClaronInterface() { isTracking = false; sprintf(calibrationDir,"No calibration dir set yet"); sprintf(markerDir,"No marker dir set yet"); } mitk::ClaronInterface::~ClaronInterface() { } void mitk::ClaronInterface::Initialize(std::string calibrationDir, std::string toolFilesDir) { sprintf(this->calibrationDir, calibrationDir.c_str()); sprintf(this->markerDir,toolFilesDir.c_str()); this->IdentifiedMarkers = 0; this->PoseXf = 0; this->CurrCamera = 0; this->IdentifyingCamera = 0; } bool mitk::ClaronInterface::StartTracking() { isTracking = false; MTC( Cameras_AttachAvailableCameras(calibrationDir) ); //Connect to camera if (Cameras_Count() < 1) { printf("No camera found!\n"); return false; } try { //Step 1: initialize cameras MTC(Cameras_HistogramEqualizeImagesSet(true)); //set the histogram equalizing MTC( Cameras_ItemGet(0, &CurrCamera) ); //Obtain a handle to the first/only camera in the array MITK_INFO< mitk::ClaronInterface::GetAllActiveTools() { //Set returnvalue std::vector returnValue; //Here, MTC internally maintains the measurement results. //Those results can be accessed until the next call to Markers_ProcessFrame, when they //are updated to reflect the next frame's content. //First, we will obtain the collection of the markers that were identified. - MTC( Markers_IdentifiedMarkersGet(nullptr, IdentifiedMarkers) ); + MTC( Markers_IdentifiedMarkersGet(0, IdentifiedMarkers) ); //Now we iterate on the identified markers and add them to the returnvalue for (int j=1; j<=Collection_Count(IdentifiedMarkers); j++) { // Obtain the marker's handle, and use it to obtain the pose in the current camera's space // using our Xform3D object, PoseXf. mtHandle Marker = Collection_Int(IdentifiedMarkers, j); returnValue.push_back(Marker); } return returnValue; } void mitk::ClaronInterface::GrabFrame() { - MTC( Cameras_GrabFrame(nullptr) ); //Grab a frame - MTC( Markers_ProcessFrame(nullptr) ); //Process the frame(s) + MTC( Cameras_GrabFrame(0) ); //Grab a frame + MTC( Markers_ProcessFrame(0) ); //Process the frame(s) } std::vector mitk::ClaronInterface::GetTipPosition(mitk::claronToolHandle c) { std::vector returnValue; double Position[3]; mtHandle t2m = Xform3D_New(); // tooltip to marker xform handle mtHandle t2c = Xform3D_New(); // tooltip to camera xform handle mtHandle m2c = Xform3D_New(); // marker to camera xform handle //Get m2c MTC( Marker_Marker2CameraXfGet (c, CurrCamera, m2c, &IdentifyingCamera) ); //Get t2m MTC( Marker_Tooltip2MarkerXfGet (c, t2m )); //Transform both to t2c MTC(Xform3D_Concatenate(t2m,m2c,t2c)); //Get position MTC( Xform3D_ShiftGet(t2c, Position) ); // Here we have to negate the X- and Y-coordinates because of a bug of the // MTC-library. returnValue.push_back(-Position[0]); returnValue.push_back(-Position[1]); returnValue.push_back(Position[2]); return returnValue; } std::vector mitk::ClaronInterface::GetPosition(claronToolHandle c) { std::vector returnValue; double Position[3]; MTC( Marker_Marker2CameraXfGet (c, CurrCamera, PoseXf, &IdentifyingCamera) ); MTC( Xform3D_ShiftGet(PoseXf, Position) ); // Here we have to negate the X- and Y-coordinates because of a bug of the // MTC-library. returnValue.push_back(-Position[0]); returnValue.push_back(-Position[1]); returnValue.push_back(Position[2]); return returnValue; } std::vector mitk::ClaronInterface::GetTipQuaternions(claronToolHandle c) { std::vector returnValue; mtHandle t2m = Xform3D_New(); // tooltip to marker xform handle mtHandle t2c = Xform3D_New(); // tooltip to camera xform handle mtHandle m2c = Xform3D_New(); // marker to camera xform handle //Get m2c MTC( Marker_Marker2CameraXfGet (c, CurrCamera, m2c, &IdentifyingCamera) ); //Get t2m MTC( Marker_Tooltip2MarkerXfGet (c, t2m )); //Transform both to t2c MTC(Xform3D_Concatenate(t2m,m2c,t2c)); //get the Claron-Quaternion double Quarternions[4]; MTC( Xform3D_RotQuaternionsGet(t2c, Quarternions) ); mitk::Quaternion claronQuaternion; //note: claron quarternion has different order than the mitk quarternion claronQuaternion[3] = Quarternions[0]; claronQuaternion[0] = Quarternions[1]; claronQuaternion[1] = Quarternions[2]; claronQuaternion[2] = Quarternions[3]; // Here we have to make a -90�-turn around the Y-axis because of a bug of the // MTC-library. mitk::Quaternion minusNinetyDegreeY; minusNinetyDegreeY[3] = sqrt(2.0)/2.0; minusNinetyDegreeY[0] = 0; minusNinetyDegreeY[1] = -1.0/(sqrt(2.0)); minusNinetyDegreeY[2] = 0; //calculate the result... mitk::Quaternion erg = (minusNinetyDegreeY*claronQuaternion); returnValue.push_back(erg[3]); returnValue.push_back(erg[0]); returnValue.push_back(erg[1]); returnValue.push_back(erg[2]); return returnValue; } std::vector mitk::ClaronInterface::GetQuaternions(claronToolHandle c) { std::vector returnValue; double Quarternions[4]; MTC( Marker_Marker2CameraXfGet (c, CurrCamera, PoseXf, &IdentifyingCamera) ); MTC( Xform3D_RotQuaternionsGet(PoseXf, Quarternions) ); //here we have to compensate a bug in the MTC-lib. (difficult to understand) mitk::Quaternion claronQuaternion; //note: claron quarternion has different order than the mitk quarternion claronQuaternion[3] = Quarternions[0]; claronQuaternion[0] = Quarternions[1]; claronQuaternion[1] = Quarternions[2]; claronQuaternion[2] = Quarternions[3]; // Here we have to make a -90�-turn around the Y-axis because of a bug of the // MTC-library. mitk::Quaternion minusNinetyDegreeY; minusNinetyDegreeY[3] = sqrt(2.0)/2.0; minusNinetyDegreeY[0] = 0; minusNinetyDegreeY[1] = -1.0/(sqrt(2.0)); minusNinetyDegreeY[2] = 0; //calculate the result... mitk::Quaternion erg = (minusNinetyDegreeY*claronQuaternion); returnValue.push_back(erg[3]); returnValue.push_back(erg[0]); returnValue.push_back(erg[1]); returnValue.push_back(erg[2]); return returnValue; } const char* mitk::ClaronInterface::GetName(claronToolHandle c) { char MarkerName[MT_MAX_STRING_LENGTH]; MTC( Marker_NameGet(c, MarkerName, MT_MAX_STRING_LENGTH, 0) ); std::string* returnValue = new std::string(MarkerName); return returnValue->c_str(); } bool mitk::ClaronInterface::IsTracking() { return this->isTracking; } bool mitk::ClaronInterface::IsMicronTrackerInstalled() { return true; }