void vtkIGTIGSTKStream::Test() { igstk::RealTimeClock::Initialize(); // typedef itk::Logger LoggerType; // typedef itk::StdStreamLogOutput LogOutputType; igstk::PolarisTrackerTool::Pointer tool = igstk::PolarisTrackerTool::New(); std::cout << tool->GetNameOfClass() << std::endl; std::cout << tool << std::endl; igstk::SerialCommunicationForPosix::Pointer serialComm = igstk::SerialCommunicationForPosix::New(); PolarisTrackerTestCommand::Pointer my_command = PolarisTrackerTestCommand::New(); // logger object created std::string testName = "HaiyingIGSTK"; // std::string outputDirectory = IGSTK_TEST_OUTPUT_DIR; std::string outputDirectory = "/spl/tmp/Haiying"; std::string filename = outputDirectory +"/"; filename = filename + testName; filename = filename + "LoggerOutput.txt"; 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 ); // serialComm->SetPortNumber( IGSTK_TEST_POLARIS_PORT_NUMBER ); serialComm->SetPortNumber( igstk::SerialCommunication::PortNumber0 ); 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( "RecordedStreamByPolarisTrackerTest.txt" ); serialComm->SetCapture( true ); 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(); std::cout << "RequestInitialize()" << std::endl; tracker->RequestInitialize(); std::cout << tracker << std::endl; std::cout << "GetNumberOfTools()" << std::endl; unsigned int ntools = tracker->GetNumberOfTools(); std::cout << "NumberOfTools : " << ntools << std::endl; std::cout << "RequestStartTracking()" << std::endl; tracker->RequestStartTracking(); typedef igstk::Transform TransformType; typedef ::itk::Vector VectorType; typedef ::itk::Versor VersorType; for(unsigned int i=0; i<10; i++) { tracker->RequestUpdateStatus(); for (unsigned int port = 0; port < 4; port++) { TransformType transform; VectorType position; tracker->GetToolTransform( port, 0, transform ); position = transform.GetTranslation(); std::cout << "Port " << port << " Position = (" << position[0] << "," << position[1] << "," << position[2] << ")" << std::endl; } } std::cout << "RequestReset()" << std::endl; tracker->RequestReset(); std::cout << "RequestInitialize()" << std::endl; tracker->RequestInitialize(); std::cout << "RequestStartTracking()" << std::endl; tracker->RequestStartTracking(); std::cout << "RequestStopTracking()" << std::endl; tracker->RequestStopTracking(); std::cout << "RequestClose()" << std::endl; tracker->RequestClose(); std::cout << "CloseCommunication()" << std::endl; serialComm->CloseCommunication(); std::cout << "[PASSED]" << std::endl; }