[IGSTK-Users] not able to display the tracker tool

steve.berger at istb.unibe.ch steve.berger at istb.unibe.ch
Wed Mar 19 05:47:31 EDT 2014


Hi,

Thanks for the great help from Ionut Iorgovan and Andreas Lasso, I can now use the Polaris tracker and display correctly the view with IGSTK.

I past here the code (below), which is an example of how to use a Polaris tracker with QT 4 and IGSTK 5.2. I hope this might help someone else.

Best,
Steve


MAIN.CPP
--------------------------------------------------------

#include <QApplication>
#include <QtTest/QTest>
#include <QMainWindow>
#include <iostream>
#include "igstkView3D.h"
#include "igstkAxesObject.h"
#include "igstkAxesObjectRepresentation.h"
#include "igstkCylinderObject.h"
#include "igstkCylinderObjectRepresentation.h"
#include "igstkTransformObserver.h"
#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"
#include "igstkPolarisTracker.h"
#include "igstkPolarisTrackerTool.h"
#include "igstkSerialCommunication.h"
#include "igstkQTWidget.h"


int main( int argc, char * argv[])
{
    igstk::RealTimeClock::Initialize();



    // *******************************
    //      INSTANCES
    //********************************

    // logger
    igstk::Object::LoggerType::Pointer   m_Logger        = igstk::Object::LoggerType::New();
    itk::StdStreamLogOutput::Pointer     m_LogOutput     = itk::StdStreamLogOutput::New();

    // tracker
    igstk::PolarisTracker::Pointer       m_Tracker       = igstk::PolarisTracker::New();
    igstk::PolarisTrackerTool::Pointer   m_TrackerTool   = igstk::PolarisTrackerTool::New();
    igstk::SerialCommunication::Pointer  m_Communication = igstk::SerialCommunication::New();

    //observer
    igstk::TransformObserver::Pointer    coordSystemAObserver = igstk::TransformObserver::New();

    //transformation
    const double longestValidityTime = igstk::TimeStamp::GetLongestPossibleTime();
    igstk::Transform identityTransform;
    identityTransform.SetToIdentity(longestValidityTime);

    //objects
    igstk::AxesObject::Pointer                    worldReference  = igstk::AxesObject::New();
    igstk::AxesObjectRepresentation::Pointer      worldReferenceR = igstk::AxesObjectRepresentation::New();
    igstk::CylinderObject::Pointer                cylinder        = igstk::CylinderObject::New();
    igstk::CylinderObjectRepresentation::Pointer  cylinderR       = igstk::CylinderObjectRepresentation::New();

    //views
    igstk::View3D::Pointer View3D = igstk::View3D::New();

    //QT
    QApplication myApp(argc, argv);
    QMainWindow myMainWindow;
    igstk::QTWidget* qtWidget3D  = new igstk::QTWidget();




    // *******************************
    //     LOGGER
    //********************************
    m_LogOutput->SetStream(std::cout);
    m_Logger->AddLogOutput(m_LogOutput);
    //m_Logger->SetPriorityLevel( itk::Logger::DEBUG);




    // *******************************
    //      OBJECTS
    //********************************

    // world reference
    worldReference  -> SetSize(200.0,200.0,200.0);
    worldReferenceR -> RequestSetAxesObject(worldReference);
    worldReferenceR -> SetOpacity(1.0);

    // cylinder
    //cylinder->SetLogger(m_Logger);
    cylinder  -> SetRadius(20.0);
    cylinder  -> SetHeight(300.0);
    cylinderR -> RequestSetCylinderObject( cylinder );
    cylinderR -> SetColor(1.0,0.0,0.0);
    cylinderR -> SetOpacity(1.0);






    // *******************************
    //     TRACKER
    //********************************

    //serial communication
    //m_Communication->SetLogger( m_Logger );
    m_Communication->SetPortNumber(       igstk::SerialCommunication::PortNumber0 );
    m_Communication->SetParity(           igstk::SerialCommunication::NoParity );
    m_Communication->SetBaudRate(         igstk::SerialCommunication::BaudRate115200 );
    m_Communication->SetDataBits(         igstk::SerialCommunication::DataBits8 );
    m_Communication->SetStopBits(         igstk::SerialCommunication::StopBits1 );
    m_Communication->SetHardwareHandshake(igstk::SerialCommunication::HandshakeOff );
    m_Communication->SetCapture( true );

    igstk::Communication::ResultType openCommOutput = m_Communication->OpenCommunication();
    if( openCommOutput == igstk::Communication::SUCCESS)
        std::cout<<"SerialComm: OpenCommunication OK"<<std::endl;
    else if(openCommOutput == igstk::Communication::TIMEOUT)
        std::cout<<"SerialComm: OpenCommunication TIMEOUT"<<std::endl;
    else if(openCommOutput == igstk::Communication::FAILURE)
        std::cout<<"SerialComm: OpenCommunication FAILED"<<std::endl;


    // tracker
    //m_Tracker->SetLogger(m_Logger);
    m_Tracker->SetCommunication(m_Communication);
    m_Tracker->RequestOpen();


    // tool
    m_TrackerTool->SetLogger(m_Logger);
    m_TrackerTool->RequestSelectWirelessTrackerTool();
    m_TrackerTool->RequestSetSROMFileName("../Resources/TrackerROMfiles/ISTB0050.rom");
    m_TrackerTool->RequestConfigure();
    m_TrackerTool->RequestAttachToTracker(m_Tracker);


    //observer
    coordSystemAObserver->ObserveTransformEventsFrom(m_TrackerTool);


    //start tracking
    m_Tracker->RequestStartTracking();




    // *******************************
    //      TRANSFORM AND PARENTS
    //********************************

    View3D->RequestSetTransformAndParent(identityTransform, worldReference);
    cylinder->RequestSetTransformAndParent(identityTransform, worldReference);






    // *******************************
    //      3DView
    //********************************
    //View3D->SetLogger(m_Logger);
    View3D->RequestAddObject(worldReferenceR->Copy());
    View3D->RequestAddObject(cylinderR->Copy());
    View3D->SetRefreshRate( 30 ); // Hz






    // *******************************
    //      QT
    //********************************
    qtWidget3D->RequestSetView( View3D );
    qtWidget3D->RequestEnableInteractions();
    myMainWindow.setCentralWidget(qtWidget3D);
    myMainWindow.setFixedSize(720,576);
    myMainWindow.show();







    // *******************************
    //     MAIN LOOP
    //********************************
    View3D->RequestStart();
    View3D->RequestResetCamera();

    while(1)
    {
        std::cout<<"\n\n"<<std::endl;
        QTest::qWait(25);
        igstk::PulseGenerator::CheckTimeouts();

        //print tracker position
        igstk::Transform trackerToolTransform;
        ::itk::Vector<double, 3> trackerToolTranslation;
        coordSystemAObserver->Clear();
        m_TrackerTool->RequestGetTransformToParent();
        if (coordSystemAObserver->GotTransform())
        {
            trackerToolTransform = coordSystemAObserver->GetTransform();
            if ( trackerToolTransform.IsValidNow() )
            {
                trackerToolTranslation = trackerToolTransform.GetTranslation();
                std::cout << "Trackertool :"
                          << m_TrackerTool->GetTrackerToolIdentifier()
                          << "\t\t  Position = ("
                          << trackerToolTranslation[0]
                          << ","
                          << trackerToolTranslation[1]
                          << ","
                          << trackerToolTranslation[2]
                          << ")" << std::endl
                          << "\tExp Time = " << trackerToolTransform.GetExpirationTime() <<std::endl;
                cylinder->RequestUpdateTransformToParent(trackerToolTransform);
            }
        }
    }


    return EXIT_SUCCESS;
}







QT PRO FILE
-------------------------------------------------

QT       += core gui network \
            widgets printsupport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

QT += testlib #to be able to use the QtTest library
DESTDIR = $$PWD #to say that we are working from this project directory (to easily set up relative filepath)

HEADERS +=


SOURCES += \
    src/main.cpp \



#include the geometry library
INCLUDEPATH += /usr/local/include/Geometry


#include IGSTK
INCLUDEPATH += /usr/local/include/IGSTK
INCLUDEPATH += /home/berger/SpineBot/kitware/igstk/IGSTK-5.2/bin/Testing/

#include ITK
INCLUDEPATH += /usr/local/include/ITK-4.4
INCLUDEPATH += /usr/local/include/ITK-4.4/vnl


#include VTK
INCLUDEPATH += /usr/local/include/vtk-5.10


#lib igstk
LIBS += -L/usr/local/lib/IGSTK
LIBS += -lIGSTK
LIBS += -lSceneGraphVisualization


#lib ITK
LIBS += -L/usr/local/lib/
LIBS += -lITKBiasCorrection-4.4
LIBS += -lITKBioCell-4.4
LIBS += -lITKCommon-4.4
LIBS += -lITKDICOMParser-4.4
LIBS += -litkdouble-conversion-4.4
LIBS += -lITKEXPAT-4.4
LIBS += -lITKFEM-4.4
LIBS += -litkgdcmCommon-4.4
LIBS += -litkgdcmDICT-4.4
LIBS += -litkgdcmDSED-4.4
LIBS += -litkgdcmIOD-4.4
LIBS += -litkgdcmjpeg12-4.4
LIBS += -litkgdcmjpeg16-4.4
LIBS += -litkgdcmjpeg8-4.4
LIBS += -litkgdcmMSFF-4.4
LIBS += -litkgdcmuuid-4.4
LIBS += -lITKgiftiio-4.4
LIBS += -litkhdf5-4.4
LIBS += -litkhdf5_cpp-4.4
LIBS += -lITKIOBioRad-4.4
LIBS += -lITKIOBMP-4.4
LIBS += -lITKIOCSV-4.4
LIBS += -lITKIOGDCM-4.4
LIBS += -lITKIOGE-4.4
LIBS += -lITKIOGIPL-4.4
LIBS += -lITKIOHDF5-4.4
LIBS += -lITKIOImageBase-4.4
LIBS += -lITKIOIPL-4.4
LIBS += -lITKIOJPEG-4.4
LIBS += -lITKIOLSM-4.4
LIBS += -lITKIOMesh-4.4
LIBS += -lITKIOMeta-4.4
LIBS += -lITKIONIFTI-4.4
LIBS += -lITKIONRRD-4.4
LIBS += -lITKIOPNG-4.4
LIBS += -lITKIOSiemens-4.4
LIBS += -lITKIOSpatialObjects-4.4
LIBS += -lITKIOStimulate-4.4
LIBS += -lITKIOTIFF-4.4
LIBS += -lITKIOTransformBase-4.4
LIBS += -lITKIOTransformHDF5-4.4
LIBS += -lITKIOTransformInsightLegacy-4.4
LIBS += -lITKIOTransformMatlab-4.4
LIBS += -lITKIOVTK-4.4
LIBS += -lITKIOXML-4.4
LIBS += -litkjpeg-4.4
LIBS += -lITKKLMRegionGrowing-4.4
LIBS += -lITKLabelMap-4.4
LIBS += -lITKMesh-4.4
LIBS += -lITKMetaIO-4.4
LIBS += -litkNetlibSlatec-4.4
LIBS += -lITKniftiio-4.4
LIBS += -lITKNrrdIO-4.4
LIBS += -litkopenjpeg-4.4
LIBS += -lITKOptimizers-4.4
LIBS += -lITKOptimizersv4-4.4
LIBS += -lITKPath-4.4
LIBS += -litkpng-4.4
LIBS += -lITKPolynomials-4.4
LIBS += -lITKQuadEdgeMesh-4.4
LIBS += -lITKReview-4.4
LIBS += -lITKSpatialObjects-4.4
LIBS += -lITKStatistics-4.4
LIBS += -litksys-4.4
LIBS += -litktiff-4.4
LIBS += -litkv3p_lsqr-4.4
LIBS += -litkv3p_netlib-4.4
LIBS += -litkvcl-4.4
LIBS += -lITKVideoCore-4.4
LIBS += -lITKVideoIO-4.4
LIBS += -litkvnl-4.4
LIBS += -litkvnl_algo-4.4
LIBS += -lITKVNLInstantiation-4.4
LIBS += -lITKVTK-4.4
LIBS += -lITKWatersheds-4.4
LIBS += -litkzlib-4.4
LIBS += -lITKznz-4.4



#lib VTK
LIBS += -L/usr/local/lib/vtk-5.10
LIBS += -lLSDyna
LIBS += -lMapReduceMPI
LIBS += -lmpistubs
LIBS += -lQVTK
LIBS += -lvtkalglib
LIBS += -lvtkCharts
LIBS += -lvtkCommon
LIBS += -lvtkDICOMParser
LIBS += -lvtkexoIIc
LIBS += -lvtkexpat
LIBS += -lvtkFiltering
LIBS += -lvtkfreetype
LIBS += -lvtkftgl
LIBS += -lvtkGenericFiltering
LIBS += -lvtkGeovis
LIBS += -lvtkGraphics
LIBS += -lvtkhdf5
LIBS += -lvtkhdf5_hl
LIBS += -lvtkHybrid
LIBS += -lvtkImaging
LIBS += -lvtkInfovis
LIBS += -lvtkIO
LIBS += -lvtkjpeg
LIBS += -lvtklibxml2
LIBS += -lvtkmetaio
LIBS += -lvtkNetCDF
LIBS += -lvtkNetCDF_cxx
LIBS += -lvtkpng
LIBS += -lvtkproj4
LIBS += -lvtkQtChart
LIBS += -lvtkRendering
LIBS += -lvtksqlite
LIBS += -lvtksys
LIBS += -lvtktiff
LIBS += -lvtkverdict
LIBS += -lvtkViews
LIBS += -lvtkVolumeRendering
LIBS += -lvtkWidgets
LIBS += -lvtkzlib






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/igstk-users/attachments/20140319/d63ac44b/attachment-0002.html>


More information about the IGSTK-Users mailing list