1.AuroraTrackerAndSerialComm(API)

AuroraTrackerAndSerialComm.h

整体内容:
在这里插入图片描述

头文件:

#pragma once
#include "igstkAuroraTracker.h"
#include "igstkAuroraTrackerTool.h"
#include "igstkSerialCommunication.h"
#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"
#include "igstkAxesObject.h"
#include "AuroraTrackerCommand.h"
#include "MyAuroraTracker.h"
#include <string>
#include <vector>
#include <iostream>

命名空间:

using namespace std ;
using namespace igstk;

类 AuroraTrackerAndSerialComm

class AuroraTrackerAndSerialComm
{
public:
	typedef AuroraTrackerAndSerialComm Self ;
public:
	AuroraTrackerAndSerialComm(void);
	~AuroraTrackerAndSerialComm(void);
public:
	//AuroraTracker的相关类型定义
	typedef igstk::AuroraTrackerTool  TrackerToolType ;
	typedef igstk::SerialCommunication::PortNumberType  PortNumberType ;//USB的端口号类型
	//TrackerTool的Transform类型
	typedef TrackerToolType::TransformType TransformType ;
	typedef itk::ReceptorMemberCommand < Self > LoadedObserverType;
	//logger的相关类型定义
	typedef igstk::Object::LoggerType  LoggerType ;
	typedef itk::StdStreamLogOutput    LogOutputType ;

	static vector<TrackerToolType::Pointer>TrackerToolContainer ;


	static igstk::MyAuroraTracker::Pointer tracker ;

	static igstk::SerialCommunication::Pointer serialComm ;
	 TrackerToolType::Pointer trackerTool ;
	 TrackerToolType::Pointer trackerTool2 ;
	static bool m_IsTracking ;
	static bool m_StopTracking ;
	static int m_VSelType;
	
	/** Define a initial world coordinate system */
	static igstk::AxesObject::Pointer                            m_WorldReference;
public:
	void nStartTracking() ;
	void nStopTracking() ;
private:
	/*LoadedObserverType::Pointer m_TrackerToolUpdateObserver ;*/
	PortNumberType AuroraPortNumber[8] ;

	string filename ;
	ofstream loggerFile ;

	LoggerType::Pointer logger ;
	LogOutputType::Pointer logOutput ;

    AuroraTrackerCommand::Pointer               my_command ;
	igstk::MyAuroraTracker::Pointer m_tracker[8] ;

};

问题:

以下两个方法,仅定义,未(找到)声明

  • void nStartTracking() ;
  • void nStopTracking() ;

以下两个[8]:

  • PortNumberType AuroraPortNumber[8] ;
  • igstk::MyAuroraTracker::Pointer m_tracker[8] ;

应用:

CGIT.h

0.CGIT.h:在其他模块中寻找其定义

extern AuroraTrackerAndSerialComm *AuroratrackerDevice ;

CGITS.cpp

1.CCGITSApp的析构函数中,设置了停止跟踪:

CCGITSApp::~CCGITSApp()
{	
	if(AuroraTrackerAndSerialComm::m_IsTracking)
		AuroratrackerDevice->nStopTracking() ;
	ExitWindowsEx(EWX_FORCE,0);
	ExitWindowsEx(EWX_SHUTDOWN,0);
}

2.CCGITSApp中设置了唯一的一个 CCGITSApp 对象

AuroraTrackerAndSerialComm *AuroratrackerDevice =
												 new AuroraTrackerAndSerialComm() ;

3.CCGITSApp中FillTrackingTable ,其中DWORD为unsigned long

DWORD WINAPI  FillTrackingTable( LPVOID pParam)
{
	HWND hWnd = (HWND)pParam;

	while ( !AuroraTrackerAndSerialComm::m_StopTracking&&!Kill_FLAG )
	{
		/*
		 * while tracking, post messages to fill the list
		 */
		if ( AuroraTrackerAndSerialComm::m_IsTracking )
			::SendMessage( hWnd, WM_FILL_LIST, 0, 0 );
		else
			AuroraTrackerAndSerialComm::m_StopTracking = FALSE;
	}/* while */

	/* when tracking stopped, kill the thread */
	AuroraTrackerAndSerialComm::m_StopTracking = FALSE;
	//AfxEndThread( 0, TRUE );
	return 0;
} 

CCGITSDlg 对话框

0.CCGITSDlg.cpp援引:

extern AuroraTrackerAndSerialComm *AuroratrackerDevice ;

1.启动:

CCGITSDlg::CCGITSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCGITSDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	nstatic=0;
	flag=1;
	if(!AuroraTrackerAndSerialComm::m_IsTracking)
		AuroratrackerDevice->nStartTracking() ;	
	//Kill_FLAG = FALSE ;
	//HANDLE hThread=CreateThread(NULL,0,FillTrackingTable,(LPVOID)m_hWnd,0,NULL); 
	//CloseHandle(hThread);
}

2.析构;

CCGITSDlg::~CCGITSDlg()
{
	Kill_FLAG  = TRUE ;
	
}

3.关机前关闭跟踪设备:

		else if(GetFocus()==GetDlgItem(IDC_IGSTK_6))
		{
			if(AuroraTrackerAndSerialComm::m_IsTracking)
				AuroratrackerDevice->nStopTracking() ;
			EndDialog(SHUTDOWN);注意:后面是自动关机程序
			/*ExitWindowsEx(EWX_FORCE,0);
			ExitWindowsEx(EWX_SHUTDOWN,0);*/
		}
	afx_msg void CCGITSDlg::OnNext()
	{
		else if(nstatic==3)
		{
			if(AuroraTrackerAndSerialComm::m_IsTracking)
				AuroratrackerDevice->nStopTracking() ;
			EndDialog(SHUTDOWN);注意:后面是自动关机程序
			/*ExitWindowsEx(EWX_FORCE,0);
			ExitWindowsEx(EWX_SHUTDOWN,0);*/
		}
	}

CCLBTDlg 对话框

0.析构函数:

CCLBTDlg::~CCLBTDlg()
{
	for (int i=0 ;i<5;i++)
	{
		AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RemoveAllObservers() ;
	}
	TrackerToolObserverCont.clear() ;
	Kill_FLAG=TRUE ;
}

注意这里的Container为0.1.2.3.4 五个?

1.BOOL CCLBTDlg::OnInitDialog(),对点的操作:

BOOL CCLBTDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化

	/*m_FRESlider.SetRange(-660,-50,1) ;
	m_FRESlider.SetPos(-200) ;*/
	LandMarkRegister = Landmark3DRegistrationType::New() ;
	for (int i=0 ;i<7; i++)
	{
		ObserverType::Pointer observer  = ObserverType::New() ;
		TrackerToolObserverCont.push_back(observer) ;
	}
	for(int i =0 ;i<7 ; i++)
	{
		AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RemoveAllObservers() ;
		TrackerToolObserverCont[i]->
			ObserveTransformEventsFrom(AuroraTrackerAndSerialComm::TrackerToolContainer[i]) ;
	}
	lrtcb = igstk::TransformObserver::New();
	lRmscb = RegistrationErrorObserver::New();
	trecb = TargetRegistrationErrorObserver::New();
	errorEstimator = ErrorEstimatorType::New();


	Kill_FLAG = FALSE ;
	HANDLE hThread=CreateThread(NULL,0,FillTrackingTable,(LPVOID)m_hWnd,0,NULL); 
	CloseHandle(hThread);
	UpdateWindow() ;
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

2.FillTrackingList添加点

LONG CCLBTDlg::FillTrackingList(UINT wParam, LONG lParam)
{
	igstk::PulseGenerator::CheckTimeouts() ;
	/*Sleep(10) ;*/

	AutoPair::TrackerLandMarkCont.clear() ; 
	for(int i =0 ;i<6;i++)
	{
		if(i==1)
		{
			AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RequestGetTransformToParent();
			if(TrackerToolObserverCont[i]->GotTransform())
			{
				TransformType transf = TrackerToolObserverCont[i]->GetTransform() ;
				if ( transf.IsValidNow() ) 
				{
					VectorType trackVec=transf.GetTranslation() ;
					x_Interest = TrackerPoint[0] = trackVec[0] ;
					y_Interest = TrackerPoint[1] = trackVec[1] ;
					TrackerPoint[2] = trackVec[2] ;
					z_Interest = abs(TrackerPoint[2]) ;
					AutoPair::TrackerLandMarkCont.push_back(TrackerPoint) ;
				}
			}
			SendMessage(WM_PAINT) ;	
		}
		else 
		{
			AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RequestGetTransformToParent();
			if(TrackerToolObserverCont[i]->GotTransform())
			{
				TransformType transf = TrackerToolObserverCont[i]->GetTransform() ;
				/*if ( transf.IsValidNow() ) 
				{*/

					VectorType trackVec=transf.GetTranslation() ;
					TrackerPoint[0] = trackVec[0] ;
					TrackerPoint[1] = trackVec[1] ;
					TrackerPoint[2] = trackVec[2] ;
					AutoPair::TrackerLandMarkCont.push_back(TrackerPoint) ;
				//}
			}
		}		
	}	

3.配准选坐标系

void CCLBTDlg::RequestLandMarkRegister()
{
	LandMarkRegister->RequestResetRegistration() ;
	for(int i=0 ;i<AutoPair::TrackerLandMarkCont.size() ;i++)
	{
		LandMarkRegister->RequestAddImageLandmarkPoint(AutoPair::sortedImageLandMarkCont[i]) ;
		LandMarkRegister->RequestAddTrackerLandmarkPoint(AutoPair::TrackerLandMarkCont[i]) ;
	}
	LandMarkRegister->RequestComputeTransform() ;
	lrtcb->ObserveTransformEventsFrom( LandMarkRegister );

	LandMarkRegister->RequestGetTransformFromTrackerToImage() ;
	if( lrtcb->GotTransform() )
	{		
		LandMarkRegister->AddObserver( igstk::DoubleTypeEvent(), lRmscb );
		LandMarkRegister->RequestGetRMSError();
		if( lRmscb->GotRegistrationError())
		{
			char ErrorStr[256] ;
			RError=lRmscb->GetRegistrationError();
			RegTrans = lrtcb->GetTransform();			
			sprintf_s(ErrorStr,256,"%.2f",RError) ;
		}

		AuroraTrackerAndSerialComm::tracker->
			RequestSetTransformAndParent(RegTrans, AuroraTrackerAndSerialComm::m_WorldReference);
	}
}

4.切换工作模式

void CCLBTDlg::OnBnClickedVolumSwitch()
{
	// TODO: 在此添加控件通知处理程序代码

	if(AuroraTrackerAndSerialComm::m_IsTracking)
	{
		AuroraTrackerAndSerialComm::tracker->RequestStopTracking();
		AuroraTrackerAndSerialComm::tracker->RequestClose();
		AuroraTrackerAndSerialComm::serialComm->CloseCommunication() ;
		isSwith=0;

	}
	if(1==AuroraTrackerAndSerialComm::m_VSelType)
		AuroraTrackerAndSerialComm::m_VSelType = 2;
	else
		if(2==AuroraTrackerAndSerialComm::m_VSelType)
			AuroraTrackerAndSerialComm::m_VSelType = 1;
	/*if(!AuroraTrackerAndSerialComm::m_IsTracking)*/
		AuroratrackerDevice->nStartTracking() ;	
		isSwith=1;
		//UpdateWindow();
}

主窗口CMainDlg

0.主窗口析构函数

CMainDlg::~CMainDlg()
{
	for( int i=0; i<5; i++)
	{//初始化igstk中的VIEW对象
		m_Views[i]->RequestStop();
	}
	m_Sliders.clear();
	Grid1CMActor.clear() ;
	Grid2CMActor.clear() ;
	GridActor.clear() ;
	m_ImageRepresentation.clear() ;
    m_Views.clear();
	m_Displays.clear();
    for (int i=0;i<5;i++)
	{
		AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RemoveAllObservers() ;
    }
	
	TrackerToolObserverCont.clear() ;		
	Kill_FLAG = TRUE ;
	canPlot = 0 ;

	this->pvtkActor2DOblique->Delete() ;
	pvtkTextMapperOblique->Delete() ;
	//...后续删除一堆
	//包括VTKMapper、RenderWindow、和IGSTKWinWidget等
}

1.BOOL CMainDlg::OnInitDialog()

//各类初始化...
//TrackerToolUpdateObserver的初始化(更新TrackerTool的位置)
m_TrackerToolUpdateObserver=LoadedObserverType::New() ;
	m_TrackerToolUpdateObserver->SetCallbackFunction( this,&CMainDlg::Tracking);
	for(int i=0 ;i<7;i++)
	{
		ObserverType::Pointer observer = ObserverType::New() ;
		this->TrackerToolObserverCont.push_back(observer) ;
	}

	for(int j=0 ;j<7 ;++j )
		this->TrackerToolObserverCont[j]
	->ObserveTransformEventsFrom( AuroraTrackerAndSerialComm::TrackerToolContainer[j] );

//为系统中存在的传感器添加监测器
AuroraTrackerAndSerialComm::TrackerToolContainer[6]->AddObserver(igstk::TrackerToolTransformUpdateEvent(), m_TrackerToolUpdateObserver);
	Kill_FLAG = FALSE 

2.根据工作模式画窗口

void CMainDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: 在此处添加消息处理程序代码
	CRect rect;
	GetClientRect(&rect);
	if(AuroraTrackerAndSerialComm::m_VSelType==1)
	dc.FillSolidRect(rect,RGB(237,247,247));
	else if(AuroraTrackerAndSerialComm::m_VSelType==2)
	dc.FillSolidRect(rect,RGB(119,140,187));
	// 不为绘图消息调用 CDialog::OnPaint()
	//画配准的二维图像(三个圆加一个十字)
	draw_XOY() ;
	draw_YOZ() ;
	draw_Breath();
}

3.void CMainDlg::ConnectImageRepresentation()

//设置视口相对于世界坐标系的位置
	for( int i=0; i<4; i++)
	{
		m_Views[i]->RequestSetTransformAndParent(identity, AuroraTrackerAndSerialComm::m_WorldReference );
	}

	//设置图像数据相对于世界坐标系的位置
	m_ImageSpatialObject->RequestSetTransformAndParent(identity, AuroraTrackerAndSerialComm::m_WorldReference );
	m_ToolSpatialObject->RequestSetTransformAndParent( identity, AuroraTrackerAndSerialComm::m_WorldReference );
	m_ToolSpatialObject0->RequestSetTransformAndParent( identity, AuroraTrackerAndSerialComm::m_WorldReference );
	m_ToolSpatialObject1->RequestSetTransformAndParent( identity, AuroraTrackerAndSerialComm::m_WorldReference );
	m_ToolSpatialObject2->RequestSetTransformAndParent( identity, AuroraTrackerAndSerialComm::m_WorldReference );

4.设置探针方向(和根据探针位置显示相关的函数写在这里面)

void CMainDlg::RequestSetToolOriention()
{	

	//定义一个4*4的矩阵存储当前手术工具的位置信息

	//定义手术工具本地坐标系下的三个方向坐标轴上得三个点

	//定义一个向量用来存储摄像机的焦点位置

	//定义变量用来存储point1、point2和point3在世界坐标系下的坐标
;
	//定义斜面以及探测面窗口中摄像机的向上向量

	//对向上向量做归一化处理

	//设置斜面窗口Camera的相关参数

	//定义一个单位Transform
	TransformType identity ;
	identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() );
	
	//将identity的值更新为手术工具的当前位置
	identity.SetTranslationAndRotation(this->transform.GetTranslation(),this->transform.GetRotation(),0.02, igstk::TimeStamp::GetLongestPossibleTime() ) ;
    //定于斜面的toolSpatialObject
	m_ToolSpatialObject1->RequestSetTransformAndParent( identity, AuroraTrackerAndSerialComm::m_WorldReference );
	
   //定义探测面的ToolSpatialObject与当前手术工具位置的相对位移	

	//求设定前瞻距离后的针尖位置
	vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New();
	this->transform.ExportTransform(*matrix1);
	double translationtmp[3] = {0,0,-prob} ;	//改成负的了 	
	transTemp.SetTranslation(translationtmp,1.0,igstk::TimeStamp::GetLongestPossibleTime());
	vtkMatrix4x4 *matrix2 = vtkMatrix4x4::New();
	transTemp.ExportTransform(*matrix2);
	vtkMatrix4x4 *matrix3 = vtkMatrix4x4::New();
	vtkMatrix4x4::Multiply4x4(matrix1,matrix2,matrix3);
	TransformType prob_transTemp;	
	for (int i=0;i<3;i++)
	{
		proPoint[i]=matrix3->Element[i][3];
	}
	//double tmp[3]={matrix3->Element[0][3],matrix3->Element[1][3],matrix3->Element[2][3]};
	if(isBurnlisEmpty)
	{
		
		prob_transTemp.SetTranslationAndRotation(proPoint,this->transform.GetRotation(),0.02, igstk::TimeStamp::GetLongestPossibleTime());
		m_ToolSpatialObject2->RequestSetTransformAndParent(  prob_transTemp,AuroraTrackerAndSerialComm::m_WorldReference );
		//设置探测面窗口Camera的相关参数
		m_Views[4]->SetCameraViewUp(-nmal2[0],-nmal2[1],-nmal2[2]) ;
		m_Views[4]->SetCameraFocalPoint(focal[0],focal[1],focal[2]);
		m_Views[4]->SetCameraPosition(pos_World[0],pos_World[1],pos_World[2]);
	}
	//添加十字光标
	AddCrosshair();
	//释放局部变量4*4矩阵
	if (!isBurnlisEmpty)
	{	
		prob_transTemp.SetTranslationAndRotation(m_burnlist[m_burnlist.size()-1],this->transform.GetRotation(),0.02, igstk::TimeStamp::GetLongestPossibleTime());
		m_ToolSpatialObject2->RequestSetTransformAndParent(  prob_transTemp,AuroraTrackerAndSerialComm::m_WorldReference );
		//设置探测面窗口Camera的相关参数
		
	}
}

5.系统初始化

void CMSSDlg::Init()
{
	//临时存储自动算法得到图像空间中的基准点

	//基准点坐标值List控件的初始化
	
	//widget

	//初始化MFC窗口对象

	//view 

	// 初始化界面中的滑块
	

	//传感器的监听器的初始化
	for (int i=0 ;i<6; i++)
	{
		ObserverType::Pointer observer  = ObserverType::New() ;
		TrackerToolObserverCont.push_back(observer) ;
	}
	for(int i =0 ;i<6 ; i++)
	{
		AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RemoveAllObservers() ;
		TrackerToolObserverCont[i]->
			ObserveTransformEventsFrom(AuroraTrackerAndSerialComm::TrackerToolContainer[i]) ;
	}
	m_ViewPickerObserver = LoadedObserverType::New();
	m_ViewPickerObserver->SetCallbackFunction( this, &CMSSDlg::Picking );

	m_Views[0]->AddObserver( igstk::CoordinateSystemTransformToEvent(),m_ViewPickerObserver );	
}

6.获得磁场传感器的位置

void CMSSDlg::GetTrackerData()
{
	for(int i =0 ;i<6;i++)
	{
		igstk::PulseGenerator::CheckTimeouts() ;
		
			AuroraTrackerAndSerialComm::TrackerToolContainer[i]->RequestGetTransformToParent();
			if(TrackerToolObserverCont[i]->GotTransform())
			{
				TransformType transf = TrackerToolObserverCont[i]->GetTransform() ;
				/*if ( transf.IsValidNow() ) 
				{*/

					VectorType trackVec=transf.GetTranslation() ;
					TrackerPoint[0] = trackVec[0] ;
					TrackerPoint[1] = trackVec[1] ;
					TrackerPoint[2] = trackVec[2] ;
					AutoPair::TrackerLandMarkCont.push_back(TrackerPoint) ;
				//}
			}
			
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值