[IGSTK-Users] issue with Running PolarisTracker example
Arefin Shamsil
marefin at uwo.ca
Tue May 24 16:49:04 EDT 2011
Hi Agata,
Thanks a lot for your quick response. I have tried
executing it from the source code as well just like you mentioned. From
Visual studio, I build the project and then go to Debug and I clicked on
Start without Debugging. A terminal comes up and that's about it. I am
attaching the screen shot. I am suspecting that I would need to specify
the SROM file name and directory in the source code, but by the look of
the given code, it seems that the console should ask me for the file
name, but it is not doing so. I am attaching the source code that I am
trying to run. Please suggest something if I should change something in
this if you don't mind.
I just started using IGSTK so I don't
really know what's wrong and I have spent hours on it to test the
Polaris Tracker using IGSTK. If you could kindly give me a step by step
direction, it would really help me out.
Thanks
Arefin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/igstk-users/attachments/20110524/31c5032a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output screen.JPG
Type: image/jpeg
Size: 22307 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/igstk-users/attachments/20110524/31c5032a/attachment.jpe>
-------------- next part --------------
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: PolarisTracker.cxx,v $
Language: C++
Date: $Date: 2011-01-27 19:25:58 $
Version: $Revision: 1.5 $
Copyright (c) ISC Insight Software Consortium. All rights reserved.
See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
// Warning about: identifier was truncated to '255' characters
// in the debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif
#include <iostream>
#include <fstream>
#include <set>
#include "itkCommand.h"
#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"
#include "itkVector.h"
#include "itkVersor.h"
#include "igstkSerialCommunication.h"
// BeginLatex
//
// This example illustrates IGSTK's interface to Polaris NDI tracker. Polaris
// trackers are optical measurement system that measure the 3D positions of
// either active or passive markers.
//
// EndLatex
// BeginLatex
//
// To communicate with Polaris tracking device, include the Polaris Tracker
// header files ( \doxygen{PolarisTracker} ) and (\doxygen{PolarisTrackerTool}).
//
// EndLatex
// BeginCodeSnippet
#include "igstkPolarisTracker.h"
#include "igstkPolarisTrackerTool.h"
// EndCodeSnippet
#include "igstkTransform.h"
#include "igstkTransformObserver.h"
class PolarisTrackerCommand : public itk::Command
{
public:
typedef PolarisTrackerCommand Self;
typedef itk::Command Superclass;
typedef itk::SmartPointer<Self> Pointer;
itkNewMacro( Self );
protected:
PolarisTrackerCommand() {};
public:
void Execute(itk::Object *caller, const itk::EventObject & event)
{
Execute( (const itk::Object *)caller, event);
}
void Execute(const itk::Object * itkNotUsed(object), const itk::EventObject & event)
{
// don't print "CompletedEvent", only print interesting events
if (!igstk::CompletedEvent().CheckEvent(&event) &&
!itk::DeleteEvent().CheckEvent(&event) )
{
std::cout << event.GetEventName() << std::endl;
}
}
};
int main( int argc, char * argv[] )
{
igstk::RealTimeClock::Initialize();
typedef igstk::Object::LoggerType LoggerType;
typedef itk::StdStreamLogOutput LogOutputType;
typedef igstk::TransformObserver ObserverType;
if( argc < 4 )
{
std::cerr << " Usage: " << argv[0] << "\t"
<< "Logger_Output_filename "
<< "Wireless_SROM_filename "
<< "Port_Number"
<< std::endl;
return EXIT_FAILURE;
}
igstk::PolarisTrackerTool::Pointer tool = igstk::PolarisTrackerTool::New();
igstk::SerialCommunication::Pointer
serialComm = igstk::SerialCommunication::New();
PolarisTrackerCommand::Pointer
my_command = PolarisTrackerCommand::New();
std::string filename = argv[1];
std::cout << "Logger output saved here:\n";
std::cout << filename << "\n";
std::ofstream loggerFile;
loggerFile.open( filename.c_str() );
LoggerType::Pointer logger = LoggerType::New();
LogOutputType::Pointer logOutput = LogOutputType::New();
logOutput->SetStream( loggerFile );
logger->AddLogOutput( logOutput );
logger->SetPriorityLevel( itk::Logger::DEBUG);
serialComm->AddObserver( itk::AnyEvent(), my_command);
serialComm->SetLogger( logger );
//BeginLatex
//Instantiate serial communication object and set the communication parameters.
//
//EndLatex
//
//
//BeginCodeSnippet
typedef igstk::SerialCommunication::PortNumberType PortNumberType;
unsigned int portNumberIntegerValue = atoi(argv[4]); //
PortNumberType polarisPortNumber = PortNumberType(portNumberIntegerValue);
serialComm->SetPortNumber( polarisPortNumber );
serialComm->SetParity( igstk::SerialCommunication::NoParity );
serialComm->SetBaudRate( igstk::SerialCommunication::BaudRate115200 );
serialComm->SetDataBits( igstk::SerialCommunication::DataBits8 );
serialComm->SetStopBits( igstk::SerialCommunication::StopBits1 );
serialComm->SetHardwareHandshake( igstk::SerialCommunication::HandshakeOff );
serialComm->SetCaptureFileName( "RecordedStreamByPolarisTracker.txt" );
serialComm->SetCapture( true );
//EndCodeSnippet
serialComm->OpenCommunication();
igstk::PolarisTracker::Pointer tracker;
tracker = igstk::PolarisTracker::New();
tracker->AddObserver( itk::AnyEvent(), my_command);
tracker->SetLogger( logger );
std::cout << "SetCommunication()" << std::endl;
tracker->SetCommunication( serialComm );
std::cout << "RequestOpen()" << std::endl;
tracker->RequestOpen();
typedef igstk::PolarisTrackerTool TrackerToolType;
typedef TrackerToolType::TransformType TransformType;
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wired tool %%%%%%%%%%%%%%%%%%%%%
//BeginLatex
//Wired and wireless tools can be handled by the Polaris Tracker class.
//EndLatex
// instantiate and attach wired tracker tool
TrackerToolType::Pointer trackerTool = TrackerToolType::New(); // commented out
trackerTool->SetLogger( logger ); // commented out
//Add observer to listen to events throw by the tracker tool
trackerTool->AddObserver( itk::AnyEvent(), my_command); // commented out
//Select wired tracker tool
//BeginLatex
//For wired tracker tool type, invoke RequestSelectWirelessTrackerTool method.
//EndLatex
//BeginCodeSnippet
trackerTool->RequestSelectWiredTrackerTool(); // commented out
//EndCodeSnippet
//Set the port number to zero
trackerTool->RequestSetPortNumber( 0 ); // commented out
//Configure
trackerTool->RequestConfigure(); // commented out
//Attach to the tracker
trackerTool->RequestAttachToTracker( tracker ); // commented out
//Add observer to listen to transform events
ObserverType::Pointer coordSystemAObserver = ObserverType::New(); // commented out
coordSystemAObserver->ObserveTransformEventsFrom( trackerTool ); // commented out
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wired tool %%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wireless tool %%%%%%%%%%%%%%%%%%%%%
// instantiate and attach wireless tracker tool -------------------------------------- I am using this only
std::cout << "Instantiate wireless tracker tool: " << std::endl;
TrackerToolType::Pointer trackerTool2 = TrackerToolType::New();
trackerTool2->SetLogger( logger );
//Add observer to listen to events throw by the tracker tool
trackerTool2->AddObserver( itk::AnyEvent(), my_command);
//Select wireless tracker tool
//BeginLatex
//For wireless tracker tool type, invoke RequestSelectWirelessTrackerTool()
//method and set SROM file.
//EndLatex
//BeginCodeSnippet
trackerTool2->RequestSelectWirelessTrackerTool();
//Set the SROM file
std::string romFile = argv[2];
std::cout << "SROM file: " << romFile << std::endl;
trackerTool2->RequestSetSROMFileName( romFile );
//EndCodeSnippet
//Configure
trackerTool2->RequestConfigure();
//Attach to the tracker
//BeginLatex
//After configuring the tracker tool, make a request to attach the tracker tool to the
// tracker.
//EndLatex
//BeginCodeSnippet
trackerTool2->RequestAttachToTracker( tracker );
//EndCodeSnippet
ObserverType::Pointer coordSystemAObserver2 = ObserverType::New();
coordSystemAObserver2->ObserveTransformEventsFrom( trackerTool2 );
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wireless tool %%%%%%%%%%%%%%%%%%%%%
//start tracking
//BeginLatex
//Start tracking and observer tracker tool pose information.
//EndLatex
//
//BeginCodeSnippet
tracker->RequestStartTracking();
typedef igstk::Transform TransformType;
typedef ::itk::Vector<double, 3> VectorType;
typedef ::itk::Versor<double> VersorType;
for(unsigned int i=0; i<100; i++)
{
igstk::PulseGenerator::CheckTimeouts();
TransformType transform;
VectorType position;
VersorType orientation;
//scalerType ;
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wired tool %%%%%%%%%%%%%%%%%%%%%
coordSystemAObserver->Clear();
trackerTool->RequestGetTransformToParent();
if (coordSystemAObserver->GotTransform())
{
transform = coordSystemAObserver->GetTransform();
if ( transform.IsValidNow() )
{
position = transform.GetTranslation();
std::cout << "Trackertool :"
<< trackerTool->GetTrackerToolIdentifier()
<< "\t\t Position = (" << position[0]
<< "," << position[1] << "," << position[2]
<< ")" << std::endl;
}
}
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wired tool %%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wireless tool %%%%%%%%%%%%%%%%%%%%%
coordSystemAObserver2->Clear();
trackerTool2->RequestGetTransformToParent();
if (coordSystemAObserver2->GotTransform())
{
transform = coordSystemAObserver2->GetTransform();
if ( transform.IsValidNow() )
{
position = transform.GetTranslation();
orientation = transform.GetRotation();
std::cout << "Trackertool2:"
<< trackerTool2->GetTrackerToolIdentifier()
<< "\t\t Position = (" << position[0]
<< "," << position[1] << "," << position[2]
<< "\t\t Orientation = (" << orientation.GetAngle()
//<< "," << orientation[1] << "," << orientation[2]
<< ")" << std::endl;
}
}
}
//%%%%%%%%%%%%%%%%%%%%%% Setting up Wireless tool %%%%%%%%%%%%%%%%%%%%%
//EndCodeSnippet
//BeginLatex
//To end the tracking process, stop and close the tracker and close the
//serial communication channel.
//EndLatex
//BeginCodeSnippet
std::cout << "RequestStopTracking()" << std::endl;
tracker->RequestStopTracking();
std::cout << "RequestClose()" << std::endl;
tracker->RequestClose();
std::cout << "CloseCommunication()" << std::endl;
serialComm->CloseCommunication();
//EndCodeSnippet
return EXIT_SUCCESS;
}
More information about the IGSTK-Users
mailing list